0

我有以下小本体,有两个类(“DataSubject”和“Minor”),一个属性从 DataSubject(s) 到 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 岁的 DataSubject 标记为 Minor。

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:lessThan "16"^^xsd:positiveInteger ;"。

如何将数据类型属性与给定的常量进行比较?

提前致谢!

利维奥

    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));
    }
4

1 回答 1

1

sh:lessThan 用于建立两个属性之间的关系,例如出生日期 sh:lessThan 结婚日期。您需要的是 sh:maxExclusive。

有关详细信息,请参阅 SHACL 规范,例如https://www.w3.org/TR/shacl/#LessThanConstraintComponent

于 2020-09-26T23:20:56.367 回答