zazuko / rdf-validate-shacl

Validate RDF data purely in JavaScript. An implementation of the W3C SHACL specification on top of the RDFJS stack.
MIT License
98 stars 13 forks source link

Custom Factory implementation not fully supported #52

Closed spetrac closed 3 years ago

spetrac commented 3 years ago

I am using a custom factory implementation and I thought, if I can supply the factory as an argument, it would be used throughout the module. The factory uses the standard rdf/js specified interface, but it only supports elements created by itself! That is the reason that my implementation throws an error, because clownface tries to use its own created nodes to access my datasets:

TypeError: Dataset#match - invalid predicate
    at Dataset.match (\Dataset.js)
    at Context.match (\node_modules\clownface\lib\Context.js:142:45)
    at Context.matchProperty (\node_modules\clownface\lib\Context.js:154:17)
    at Context.in (\node_modules\clownface\lib\Context.js:25:17)
    at \node_modules\clownface\lib\Clownface.js:270:81
    at Array.reduce (<anonymous>)
    at Clownface.in (\node_modules\clownface\lib\Clownface.js:270:35)
    at RDFLibGraph.getSubClassesOf (\node_modules\rdf-validate-shacl\src\rdflib-graph.js:38:10)
    at RDFLibGraph.getInstancesOf (\node_modules\rdf-validate-shacl\src\rdflib-graph.js:20:26)
    at new ShapesGraph (\node_modules\rdf-validate-shacl\src\shapes-graph.js:30:44)
    at SHACLValidator.loadShapes (\node_modules\rdf-validate-shacl\index.js:49:24)
    at new SHACLValidator (\node_modules\rdf-validate-shacl\index.js:21:10)
    at Dataset.shaclValidate (\Dataset.js)
    at Context.<anonymous> (\Dataset.test.js)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)

The error is thrown, because the method only accepts its own NamedNodes and no arbitrary objects. That is exactly the behaviour I want and I am sad, that I cannot use this magnificient shacl module, because it does not create NamedNodes with the supplied factory :(

I consider this a bug and if it will not get fixed, my only option is to write a shacl validator myself!

(using version 0.2.6 of rdf-validate-shacl)

martinmaillard commented 3 years ago

The provided factory is used to create any terms that come out of the library. But internally, it's possible that some terms created with another factory are used. I think if you follow the RDF/JS spec, these terms should be compatible.