@shexjs/shape-path-query
v1.0.0-alpha.29
Published
ShapePath query interface for ShEx.js
Downloads
6
Readme
@shexjs/shape-path-query
NPM module to use shape-path-core to query data.
API
const N3 = require("n3");
const Sp = require('shape-path-core')
const { ctor: RdfJsDb } = require('@shexjs/neighborhood-rdfjs')
const yy = { // resolution for PNames in ShapePath
base: new URL('http://project.example/schema'),
prefixes: {
'issue': 'http://project.example/ns#'
}
}
const pathStr = '@issue:DiscItem ~ issue:href'
const pathExpr = new Sp.ShapePathParser(yy).parse(pathStr)
console.log(`${pathStr} compiles to ${JSON.stringify(pathExpr)}`)
const filePath = Issue.json
const schema = readJson('Issue.json')
const schemaNodes = pathExpr.evalPathExpr([schema], new EvalContext(schema))
const graph = new N3.Store();
const turtleStr = Fs.readFileSync('Issue2.ttl', 'utf8');
const parser = new N3.Parser({ baseIRI: 'http://a.example/' });
graph.addQuads(parser.parse(turtleStr));
const db = RdfJsDb(graph)
shapePathQuery (schema, nodeSet, db, node, shape)
- schema: a ShExJ ShEx schema; should match
@types/shexj
- nodeSet: result of
evalPathExpr
- db: ShEx DB, e.g. the
@shexjs/neighborhood-rdfjs
- node: graph to start validation
- shape: label of shape expression against which to validate returns: hmm, not sure. at the simplest, an array of terms matched from the validated graph.
quickstart
./bin/spquery.js \
'@<http://project.example/schema#DiscItem>~<http://project.example/ns#href>,@<http://project.example/schema#Issue>~<http://project.example/ns#spec>/valueExpr/shapeExprs~<http://project.example/ns#href>' \
../../node_modules/shape-path-core/examples/issue/Issue.json \
-d ./examples/issue/Issue2.ttl \
-m '<http://instance.example/project1/Issue2>@<http://project.example/schema#Issue>'
or npm run toy
from this directory
Lerna Monorepo
This repo uses lerna to manage multiple NPM packages. These packages are located in packages/*
:
shape-map
-- a ShapeMap parser@shexjs/parser
-- parse ShExC into ShExJ@shexjs/writer
-- serialize ShExK as ShExC@shexjs/term
-- RDF terms uses in ShEx@shexjs/util
-- some utilities for transforming schemas or validation output@shexjs/visitor
-- a visitor for schemas@shexjs/validator
-- validate nodes in an RDF graph against shapes in a schema@shexjs/eval-validator-api
-- API called by@shexjs/validator
for validating Shapes, with tripleExpressions and EXTENDS etc.@shexjs/eval-simple-1err
-- Implementation of@shexjs/eval-validator-api
which reports only one error.@shexjs/eval-threaded-nerr
-- Implementation of@shexjs/eval-validator-api
which exhaustively enumerate combinations of ways the data fails to satisfy a shape's expression.@shexjs/loader
-- an API for loading and using ShEx schemas@shexjs/node
-- additional API functionality for a node environment@shexjs/cli
-- a set of command line tools for transformaing and validating with schemas@shexjs/webapp
-- the shex-simple WEBApp@shexjs/shape-path-query
-- traverse ShEx schemas with a path language@shexjs/extension-test
-- a small language for testing semantic actions in ShEx implementations (more)@shexjs/extension-map
-- an extension for transforming data from one schema to another (more)@shexjs/extension-eval
-- simple extension which evaluates Javascript semantic action code (more)