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

OWLAPI set DataProperty strict value on subclass assertion

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

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

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

Alex:owlClass
HasAge:DataProperty

Alex HasAge value 35

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

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

屏幕截图显示 8.4.3 Literal Value Restriction, see also OWL2 Quick Guide, Data Property Restrictions。 编程方式如下所示:

String EXAMPLE_IRI = "

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