我不能对xsd:positiveInteger使用sh:lessThan

问题描述

我有以下小型本体,有两个类(“ DataSubject”和“ 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的所有DataSubject标记为次要。

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;”。

如何比较具有给定常量的数据类型属性

谢谢!

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,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:maxExclusive。

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...