-
Notifications
You must be signed in to change notification settings - Fork 1
ShEx validator updates
##New features
As per the README the usage now looks like this
var ShEx = require('ShEx-validator');
var schemaText = "...";
var dataText = "...";
var startingShapes = {
"SHAPE" : "SHAPE DEFINITION",
...
};
var callbacks = {
schemaParsed: function (schema) {...},
schemaParseError: function (errorMessage) {...},
dataParsed: function (data) {...},
dataParseError: function (errorMessage) {...},
validationResult: function (validationResult) {...},
shapeFindingResult: function(shapes) {...}
};
var options = {
closedShapes: true|false,
};
var validator = new ShEx.Validator(schemaText, dataText, callbacks, options);
validator.findShapes();
validator.validate(startingShapes);
a Validator object has these functions:
v.updateSchema(schemaText);
v.updateData(dataText);
v.findShapes();
v.validate(startingShapes);
updateSchema and updateData do what you would expect and mean that both don't have to be parsed every time anything changes. callbacks and options can be safely modified directly ie. validator.callbacks.validationResult = function(result) {...};
findShapes()
returns an object where the keys are the names of the shapes in the data file ie. '<http://rdf.ebi.ac.uk/chembl/chembl>'
and the values are either null if it didn't find a matching shape or the shape definition name if it did ie. '<SummaryLevelShape>'
.
validate(startingShapes)
is the same function as before except startingShapes is now an object of exactly the form returned by findShapes. Obviously however the user might want to change which shapes get validated against which shape definition. If the shape definition is null ie. { "<http://rdf.ebi.ac.uk/chembl/chembl15>": null}
is passed in then nothing will be validated.
##Callback changes
To avoid the UI side having to interact with RDF.js as much as possible the parsedSchema and parsedData callbacks now receive these params.
schemaParsed = {
shapeDefinitions: ["SHAPE NAME", ...]
}
dataParsed = {
shapes: ["SHAPE"],
triples: [RDF.Triple]
}
The only object which is coming direct from RDF.js is the RDF.Triple and this is because any future changes to are unlikely to change the format of this object much.
##Future The plan is for findShapes to not only return the exact matches (ie. those that already pass the validate function but to also return the shape with least errors so as to guess which shape it is closest to being valid to).
This should allow the UI to have fairly good defaults (w/o hardcoding them) but also flexible in letting the user pick which shapes get validated against which shape definitions