javaprotegeowl-api

OWLAPI set DataProperty strict value on subclass assertion


I can use this code to Create the restricted data range :

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

now I need to know how to programmatically define a class as subclass of a dataproperty assertion with strict value :

Alex:owlClass
HasAge:DataProperty

Alex HasAge value 35

enter image description here

P.S: both answers are correct.but @ssz answer is more closer answer to the question and it works with both hermit and pellet reasoner.

it seems there is some issue with pellet reasoning on axioms like hasAge xsd:integer [>=20 , <=20 ] . see here


Solution

  • The screenshot appears to show 8.4.3 Literal Value Restriction, see also OWL2 Quick Guide, Data Property Restrictions. Programmatically this looks like following:

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