@shexjs/shape-path-query
TypeScript icon, indicating that this package has built-in type declarations

1.0.0-alpha.29 • Public • Published

@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)
  1. schema: a ShExJ ShEx schema; should match @types/shexj
  2. nodeSet: result of evalPathExpr
  3. db: ShEx DB, e.g. the @shexjs/neighborhood-rdfjs
  4. node: graph to start validation
  5. 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/*:

Package Sidebar

Install

npm i @shexjs/shape-path-query

Weekly Downloads

1

Version

1.0.0-alpha.29

License

MIT

Unpacked Size

13.4 kB

Total Files

7

Last publish

Collaborators

  • ericprud
  • justinwb