NodeJs project for validating Sturctured Data with ShEx and SHACL. Is mainly used in a form of a bundle as a core part of the Schema.org Content Checker demo.
Main tasks:
- parsing JSON-LD, Microdata, RDFa data using n3, microdata-node, rdf-streaming-parser, jsonld;
- validating structured data against ShEx shapes using a minified version of shex.js; against SHACL shapes using rdf-validate-shacl.
ShEx validation
const ShexValidator = require('./schemarama/shexValidator').Validator;
const annotations = {
description: 'http://www.w3.org/2000/01/rdf-schema#comment',
severity: 'http://www.w3.org/2000/01/rdf-schema#label'
}
// shapes - JSON object with shapes in ShEx format
const validator = new ShexValidator(shapes, {annotations: annotations});
const startShape = 'http://schema.org/validation#ValidSchemaThing'
// data - string or n3.js Store, that should be validated
validator.validate(data, startShape, {baseUrl: 'http://example.org/test'})
.then(report => report.failures.forEach(failure => console.log(failure)));
SHACL validation
const ShaclValidator = require('./schemarama/shaclValidator').Validator;
const annotations = {
description: 'http://www.w3.org/2000/01/rdf-schema#comment',
severity: 'http://www.w3.org/2000/01/rdf-schema#label'
}
// shapes - JSON object with shapes in ShEx format
const validator = new ShaclValidator(shapes, {annotations: annotations});
// data - string or n3.js Store, that should be validated
validator.validate(data, {baseUrl: 'http://example.org/test'})
.then(report => report.failures.forEach(failure => console.log(failure)));
To use this project as a cli, first you need to do an npm install
node cli --parse
Required arguments:
--input <file path>
- path to the input file.
Optional arguments:
--output <file path>
- path to the output file. If not specified, output will be printed to the console.
--format <format>
- one of the output formats. Available formats: nquads|ntriples|turtle|trig
. 'nquads' is used by default.
node cli --validate
Required arguments:
--shex <file path>
- path to ShEx shapes. Could be either local or URL
--input <file path>
- path to the input file.
--target <shapeURI>
- target shape, e.g. http://example.org/shex#Thing.
Optional arguments:
--output <file path>
- path to the output file. If not specified, output will be printed to the console.
--base <URI>
- base data URI (@id). If not specified, random URI will be used.
--annotations <file path>
- path to the annotation correspondence file, in JSON format, where keys are keys
in the failure report object and values are annotation predicates. If not specified, annotations will be ignored.
node cli --validate
Required arguments:
--shex <file path>
- path to SHACL shapes. Could be either local or URL
--input <file path>
- path to the input file.
Optional arguments:
--output <file path>
- path to the output file. If not specified, output will be printed to the console.
--base <URI>
- base data URI (@id). If not specified, random URI will be used.
--annotations <file path>
- path to the annotation correspondence file, in JSON format, where keys are keys
in the failure report object and values are annotation predicates. If not specified, annotations will be ignored.
--subclasses <file path>
- additional triples that should be added to data for every validation.
Originally used for adding schema.org subclasses structure to the data.