问题描述
我有以下小本体,有两个类(DataSubject"和Minor"),一个属性具有从 DataSubject(s) 到 xsd:positiveInteger 的年龄,以及一个个体(John",他是一个 DataSubject 并且 has-age 等于 20).
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 ;
.
以下 SHACL 规则应该将所有年龄低于 16 岁的数据主体标记为未成年人.
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 ;
.
但是,以下 Java 代码将 John 推断为 Minor……但 John 不是,他已经 20 岁了!当然这条规则是不正确的,特别是指令sh:lessThan16"^^xsd:positiveInteger;".
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?
提前致谢!
利维奥
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:小于结婚日期.您需要的是 sh:maxExclusive.
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.
有关详细信息,请参阅 SHACL 规范,例如https://www.w3.org/TR/shacl/#LessThanConstraintComponent
See the SHACL spec for details, e.g. https://www.w3.org/TR/shacl/#LessThanConstraintComponent
这篇关于我不能将 sh:lessThan 与 xsd:positiveInteger 一起使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!