OWLAPI 在子类断言上设置 DataProperty 严格值

问题描述

我可以使用此代码创建受限数据范围:

 public void testDatatypeRestriction() throws OWLException {
        OWLOntologyManager m = create();
        OWLOntology o = m.createOntology(EXAMPLE_IRI);
        // Adults have an age greater than 18.
        OWLDataProperty hasAge = df.getoWLDataProperty(IRI.create(EXAMPLE_IRI + "hasAge"));
        // Create the restricted data range by applying the facet restriction
        // with a value of 18 to int
        OWLDatarange greaterThan18 = df.getoWLDatatypeRestriction(df.getIntegerOWLDatatype(),OWLFacet.MIN_INCLUSIVE,df
            .getoWLLiteral(18));
        // Now we can use this in our datatype restriction on hasAge
        OWLClassExpression adultDeFinition = df.getoWLDataSomeValuesFrom(hasAge,greaterThan18);
        OWLClass adult = df.getoWLClass(IRI.create(EXAMPLE_IRI + "#Adult"));
        OWLSubClassOfAxiom ax = df.getoWLSubClassOfAxiom(adult,adultDeFinition);
        m.applyChange(new AddAxiom(o,ax));
    }

现在我需要知道如何以编程方式将类定义为具有严格值的数据属性断言的子类:

Alex:owlClass
HasAge:DataProperty

Alex HasAge value 35

enter image description here

P.S:两个答案都是正确的。但@ssz 的答案更接近问题的答案,它适用于隐士和颗粒推理机。

似乎在 hasAge xsd:integer [>=20,<=20 ] 等公理上的颗粒推理存在一些问题。见here

解决方法

屏幕截图似乎显示 8.4.3 Literal Value Restriction,另见 OWL2 Quick Guide,Data Property Restrictions。 以编程方式,这看起来如下所示:

String EXAMPLE_IRI = "https://stackoverflow.com/questions/65793751#";

OWLDataFactory df = m.getOWLDataFactory();
OWLDataProperty hasAge = df.getOWLDataProperty(IRI.create(EXAMPLE_IRI + "hasAge"));
OWLClass adult = df.getOWLClass(IRI.create(EXAMPLE_IRI + "Adult"));

// SubClassOf(:Adult DataHasValue(:hasAge "35"^^xsd:integer))
OWLAxiom ax = df.getOWLSubClassOfAxiom(adult,df.getOWLDataHasValue(hasAge,df.getOWLLiteral(35)));
System.out.println(ax);
System.out.println("---------------");

OWLOntology ont = m.createOntology();
ont.add(ax);    
ont.saveOntology(new ManchesterSyntaxDocumentFormat(),System.out);