This module extends @shexjs/loader with file: access. This modules is probably not appropriate for use in a browser.
npm install @shexjs/node
const ShExIo = require('@shexjs/node');
@shexjs/writer - convert ShExJ as ShExC
shape-map - pairs of node/shape implementing ShapeMap
load shex and json files into a single ShEx schema and turtle into a graph.
@shexjs/node extends the @shexjs/loader load method to allow the source to be a file path.
SOURCE may be
parameters:
returns: {Promise<{schema: any, dataMeta: [], data: ( | null), schemaMeta: *[]}>} |
example (same as @shexjs/loader example, but using file paths):
// Initialize @shexjs/loader with implementations of APIs.
const ShExLoader = require("@shexjs/node")({
rdfjs: require('n3'), // use N3 as an RdfJs implementation
fetch: require('node-fetch'), // fetch implementation
jsonld: require('jsonld') // JSON-LD (if you need it)
});
// Schemas from URL and filepath:
const schemaFromUrl =
"https://shex.io/webapps/packages/shex-cli/test/cli/1dotOr2dot.shex";
const schemaFromFile =
"../shex-cli/test/cli/1dotOr2dot.shex";
// Data graphs from URL, text and graph API:
const graphFromUrl =
"https://shex.io/webapps/packages/shex-cli/test/cli/p1.ttl";
const graphFromFile =
"../shex-cli/test/cli/p2p3.ttl";
// ShExLoader.load returns a promise to load and merge schema and data.
const schemaAndDataP = ShExLoader.load(
{ shexc: [ schemaFromUrl, schemaFromFile ] },
{ turtle: [ graphFromUrl, graphFromFile ] }
);
// Print out results to show off returned structure.
schemaAndDataP.then(({schema, schemaMeta, data, dataMeta}) => {
console.log('schemaMeta:\n' + JSON.stringify(schemaMeta, null, 2));
console.log('shapes:\n' + schema.shapes.map(s => ' ' + s.id).join('\n'));
console.log('dataMeta:\n' + JSON.stringify(dataMeta, null, 2));
console.log('triples:\n' + data.getQuads().map(
q => ' ' +
(['subject', 'predicate', 'object'])
.map(t => q[t].value).join(' ')).join('\n'));
});
output:
schemaMeta:
[ { "mediaType": "text/shex", "url": "file:…cli/1dotOr2dot.shex",
"base": "file:…cli/1dotOr2dot.shex", "prefixes": {} },
{ "mediaType": "text/shex", "url": "https:…cli/1dotOr2dot.shex",
"base": "https:…cli/1dotOr2dot.shex", "prefixes": {} }
]
shapes:
http://a.example/S1
dataMeta:
[ { "mediaType": "text/turtle", "url": "file:…cli/p2p3.ttl",
"base": "file:…cli/p2p3.ttl", "prefixes": {
"": "http://a.example/",
"xsd": "http://www.w3.org/2001/XMLSchema#" } },
{ "mediaType": "text/turtle", "url": "https:…cli/p1.ttl",
"base": "https:…cli/p1.ttl", "prefixes": {
"": "http://a.example/"
} }
]
triples:
file:…cli/x http://a.example/p2 p2-0
file:…cli/x http://a.example/p3 p3-0
https:…cli/x http://a.example/p1 p1-0
See @shexjs/loader load method for more description.
prototype of loadExtensions. does nothing
return promise of {contents, url}
Use @shexjs/node
directly:
const ShExIo = require("@shexjs/node")({
rdfjs: N3,
fetch: require('node-fetch')
});
Extend @shexjs/node
with jsonld and a non-standard jsonld document loader:
const ShExIo = require("@shexjs/node")({
rdfjs: N3,
fetch: require('node-fetch'),
jsonld: require('jsonld'),
jsonLdOptions: { documentLoader }
});
async function documentLoader (url, options) {
# see https://github.com/digitalbazaar/jsonld.js#custom-document-loader
}
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)