Hi, I'm creating a function to test the minimum number of elements in an rdf:List. I am using the SHACL-API to run this function.
I can't use sh:minCount or sh:maxCount because they disregard the existence
of duplicate elements in the rdf:List, and in my case study, I can have
more than one element with the same value in the rdf:List.
The function code is:
function myMinOccur ($this) {
// Defines an array for the return
var results = [];
// Defines the the IRI of the target node
var propertyName =
TermFactory.namedNode("http://www.example.org#coordinates");
var rest =
TermFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#rest");
var nil =
TermFactory.namedNode("http://www.w3.org/1999/02/22-rdf-syntax-ns#nil");
// Finds the object defined by the target node
var propertyObject = $data.find($this, propertyName, null) ;
// Navigate the target node graph
for (var t = propertyObject.next(); t; t = propertyObject.next()) {
// Each instance is a Javascript object
var node = t.object;
var head = node;
var lenght = 0;
// This loop runs thorugh the list and
// counts how many elements are in the list.
for ( ; node !== nil; ) {
lenght++;
var next = $data.find(node,rest,null).next();
if (!next || next == node) { node = nil; }
else {node = next;}
}
// If the list lenght < 2 ($minSize), then it is an outlier.
if (length < 2 ) {
results.push({
value : head
});
}
}
return results;
}
I have two problems/doubts in this code:
a) the inner loop is apparently looping, that is, it cannot find the end of
the list.
b) How do I pass the value of ex:minSize to the function?
The problem in (a) was discussed, but with no solution, here:
https://github.com/linkeddata/rdflib.js/issues/169
I tested the function with the rdflib.js and rdflib-graph.js libraries
found at (https://github.com/TopQuadrant/shacl-js) and it worked perfectly.
However, in this test, the loop mentioned in (a) is replaced by length =
node.elements.length, which is not supported by the SHACL-API.
Attached are the shape graph and data graph files used in the tests.
The function is found at
http://54.201.29.21/shapes/Case_1-Functions_iterator.js.
Best regards,
Angelo
--
You received this message because you are subscribed to the Google Groups
"TopBraid Suite Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/topbraid-users/6af577ee-0a59-43c9-8e65-7136d0a7ae51%40googlegroups.com.
Case_1-DataGraph.ttl
Description: Binary data
Case_1-ShapeGraph.ttl
Description: Binary data
