I am trying to utilize SHACL-JS to access external JavaScript functions and perform constraint validation on an RDF graph. The reason for using external functions is I need to perform some complex mathematical operations, which cannot be performed directly within SHACL-SPARQL. The shape graph I used is as follows:
This is a sample shape, which I am using just for testing purpose. The objective of this shape is just to validate that no two bounding boxes in the RDF data are different (as I said, this is just for testing purpose, just to get the approach right. I'll be developing shape and JS functions for more complex operations). The JS function checkEquality is as follows:
function checkEQuality ($surfaceValue1, $surfaceValue2) {
if ($surfaceValue1 != $surfaceValue2) {
return "true";
}
}
The problem is that I am not sure if the shape is actually accessing the external function or not. This is because, for the FILTER statement in the SPARQL constraint, whatever value of the string I use in FILTER (?result = "true") in place of "true", the validation result is always true, which should not be the case. All the bounding boxes in the data graph are different, so this constraint should ideally be violated. I think there is something wrong with the way I am accessing the JS function and passing the arguments.
Could anyone please suggest if what I am trying is the right way of accessing the JavaScript functions from SHACL_JS and passing the arguments? What changes should be made to the shape so that I can pass the arguments to the external JS function and use the computation results for constraint checking? I searched a lot online, but not much of the information is available, other than the official W3C SHACL-JS documentation.
P.S. - I tried using pySHACL as well. Getting the same issue there as well.
I am trying to utilize SHACL-JS to access external JavaScript functions and perform constraint validation on an RDF graph. The reason for using external functions is I need to perform some complex mathematical operations, which cannot be performed directly within SHACL-SPARQL. The shape graph I used is as follows:
This is a sample shape, which I am using just for testing purpose. The objective of this shape is just to validate that no two bounding boxes in the RDF data are different (as I said, this is just for testing purpose, just to get the approach right. I'll be developing shape and JS functions for more complex operations). The JS function checkEquality is as follows:
The relevant sample data graph and the complete datagraph can be accessed using link (sample graph is just a smaller snippet of the complete RDF graph, containing relevant triples for testing) - https://drive.google.com/drive/folders/1onqLiqjmn2OLHDZj5Lqz8RVCxER7NED6?usp=sharing
For validation, I used TopQuadrant SHACL API 1.3.2, using the following command from command line:
However, the validation result always comes to be true, as shown below:
The problem is that I am not sure if the shape is actually accessing the external function or not. This is because, for the FILTER statement in the SPARQL constraint, whatever value of the string I use in FILTER (?result = "true") in place of "true", the validation result is always true, which should not be the case. All the bounding boxes in the data graph are different, so this constraint should ideally be violated. I think there is something wrong with the way I am accessing the JS function and passing the arguments.
Could anyone please suggest if what I am trying is the right way of accessing the JavaScript functions from SHACL_JS and passing the arguments? What changes should be made to the shape so that I can pass the arguments to the external JS function and use the computation results for constraint checking? I searched a lot online, but not much of the information is available, other than the official W3C SHACL-JS documentation.
P.S. - I tried using pySHACL as well. Getting the same issue there as well.
Thanks a lot!
Best Regards, Ajay