I have the following small ontology, with two classes ("DataSubject" and "Minor"), one property has-age from DataSubject(s) to xsd:positiveInteger, and one individual ("John", who is a DataSubject and has-age equal to 20).
ontology:DataSubject
rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ;
owl:disjointWith ontology:Minor ;
owl:disjointWith owl:NamedIndividual ;
.
ontology:John
rdf:type ontology:DataSubject ;
ontology:has-age "20"^^xsd:positiveInteger ;
.
ontology:Minor
rdf:type owl:Class ;
rdfs:subClassOf owl:Thing ;
owl:disjointWith ontology:DataSubject ;
owl:disjointWith owl:NamedIndividual ;
.
ontology:has-age
rdf:type owl:DatatypeProperty ;
rdfs:domain ontology:DataSubject ;
rdfs:range xsd:positiveInteger ;
.
The following SHACL rule SHOULD mark as Minor all DataSubject(s) whose age is lower than 16.
rules:WhenDataSubjectIsMinor
rdf:type sh:NodeShape ;
sh:rule [
rdf:type sh:TripleRule ;
#IF: "the age of the Data Subject is lower than 16"
sh:condition [
sh:property [
sh:path ontology:has-age;
sh:lessThan "16"^^xsd:positiveInteger ;
] ;
] ;
#THEN: "the Data Subject is marked as type Minor"
sh:subject sh:this ;
sh:predicate rdf:type;
sh:object ontology:Minor ;
] ;
sh:targetClass ontology:DataSubject ;
.
However, the following Java code infers John as Minor... but John is not, he is 20 years old! Of course the rule is not correct, specifically the instruction "sh:lessThan "16"^^xsd:positiveInteger ;".
How can I compare datatype properties with given constants?
Thanks in advance!
Livio
public static void main(String[] args) throws Exception
{
//Load the ontology
Model ontology = JenaUtil.createMemoryModel();
FileInputStream fisOntology = new FileInputStream("./ontology.ttl");
ontology.read(fisOntology, "urn:dummy", FileUtils.langTurtle);
//Load the rules
Model rules = JenaUtil.createMemoryModel();
FileInputStream fisRules = new FileInputStream("./rules.ttl");
rules.read(fisRules, "urn:dummy", FileUtils.langTurtle);
//Executing the rule and print
Model inferredTriples = RuleUtil.executeRules(ontology, rules, null, null);
System.out.println(ModelPrinter.get().print(inferredTriples));
}
sh:lessThan is used to establish relationships between two properties, e.g. date of birth sh:lessThan date of marriage. What you need is sh:maxExclusive.
See the SHACL spec for details, e.g. https://www.w3.org/TR/shacl/#LessThanConstraintComponent