Skip to content

ShEx-validator parses a ShEx schema and RDF data file and validates the resources in the data against the shapes in the schema

License

Notifications You must be signed in to change notification settings

jathanasiou/ShEx-validator

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ShEx-validator Build Status

Parses a ShEx schema and RDF data file and validates the resources in the data against the shapes in the schema.

A standalone Node module with a command line interface and validate() function as described below

It is built on Eric Prud'hommeaux's ShEx validator and parser

Installation

npm install HW-SWeL/ShEx-validator

Usage

In Code

var ShEx = require('ShEx-validator');

var schemaText = "...";

var dataText = "...";

var startingResources = {
    "RESOURCE" : "SHAPE",
    ...
};

var callbacks = {
    schemaParsed: function (schema) {...},
    schemaParseError: function (errorMessage) {...},
    dataParsed: function (data) {...},
    dataParseError: function (errorMessage) {...},
    validationResult: function (validationResult) {...},
    findShapesResult: function(shapes) {...}
};

var options = {
    closedShapes: true|false,
};

var validator = new ShEx.Validator(schemaText, dataText, callbacks, options);

validator.findShapes();

validator.validate(startingResources);

Callbacks

Not nearly finished or perfected but it is the current implementation.

schemaParsed = {
    shapes: ["SHAPE", ...]
}

dataParsed = {
    resources: ["RESOURCE"],
    triples: [RDF.Triple]
}

validationResult = {
    passed: true|false,
    startingResource: RDF.RDFLiteral|RDF.IRI,
    matches: [{
        rule: RDF.Triple,
        triple: RDF.Triple
    ]},
    errors: [{
        name: string,
        triple: RDF.Triple,
        req_lev: string
    ]}
}

shapeFindingResult = {
    "RESOURCE" : "SHAPE" | null,
    ...
};

On Command Line

While developing: node commandLine.js samples/hcls_2014.shex samples/chembl_2014.ttl http://rdf.ebi.ac.uk/chembl/chembl=SummaryLevelShape

In future when globally installed:

Usage:
    ShEx-validator [options] SCHEMA DATA RESOURCE=SHAPE [RESOURCE=SHAPE ...]
    ShEx-validator [options] SCHEMA DATA -f

Options:
    -c, --closed-shape  All properties must be in shape
    -h, --help          Print usage information
    -f, --find-shapes   Find shapes which match the resources

Development

The main access point is index.js.

Currently only n3.js is used for parsing the data but others can easily be added in dataParser.js.

Validation is still performed by a combination of Erics PEG generated includes/shexParser and includes/RDF.js.

Requirement Levels ShEx Addition

Requirement levels have been added to the ShEx syntax to a allow sematics such as "should" and "should not". The following example shows the syntax.

PREFIX foaf: <http://xmlns.com/foaf/>
PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema>

start = <PersonShape>
<PersonShape> {
    `should` foaf:name rdf:langString,
    `should not` !foaf:age rdfs:Literal
}

Tests

Tests are done using Jasmine, and the test specifications are located in specs/.

To run the tests do:

npm test

Dependencies

  • minimist: parse argument options
  • n3: Lightning fast, asynchronous, streaming Turtle / N3 / RDF library.
  • promise: Bare bones Promises/A+ implementation

Dev Dependencies

  • jasmine-node: DOM-less simple JavaScript BDD testing framework for Node
  • pegjs: Parser generator for JavaScript

License

MIT

About

ShEx-validator parses a ShEx schema and RDF data file and validates the resources in the data against the shapes in the schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%