我有以下小本体,有两个类("DataSubject"one_answers"Minor"(,一个属性的年龄从DataSubject到xsd:positiveInteger,还有一个个体("John",他是DataSubject,年龄等于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 ;
.
以下SHACL规则应将年龄低于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 ;
.
然而,下面的Java代码推断John是Minor。。。但约翰不是,他20岁了!当然,这个规则是不正确的,特别是指令";sh:小于";16〃^^xsd:ppositiveInteger&";。
如何将数据类型属性与给定常量进行比较?
提前感谢!
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用于在两个属性之间建立关系,例如出生日期sh:lessThan结婚日期。您需要的是sh:maxExclusive。
有关详细信息,请参阅SHACL规范,例如。https://www.w3.org/TR/shacl/#LessThanConstraintComponent