Jpropeht89
Jpropeht89

Reputation: 21

OWL API object properties Annotation creation

Does any one can help me generate this ObjectPropertyRange using "The OWL API"??

<ObjectPropertyRange>
    <Annotation>
        <AnnotationProperty abbreviatedIRI="owl:backwardCompatibleWith"/>
        <IRI>#ProgramLanguage</IRI>
    </Annotation>
    <ObjectProperty IRI="#specifiedBy"/>
    <ObjectMaxCardinality cardinality="1">
        <ObjectProperty IRI="#specifiedBy"/>
        <Class IRI="#Grammars"/>
    </ObjectMaxCardinality>
</ObjectPropertyRange> 

This is how i got in the last 3 days....

<ObjectPropertyRange>
    <ObjectProperty IRI="#has"/>
    <ObjectMaxCardinality cardinality="1">
        <ObjectProperty IRI="#has"/>
        <Class IRI="#Quantity"/>
    </ObjectMaxCardinality>
</ObjectPropertyRange>

From this code...

OWLClassExpression expression=df.getOWLObjectMaxCardinality(relations.max, objectProperty,range.getNNF());
OWLSubClassOfAxiom subClassOfAxiom=df.getOWLSubClassOfAxiom(df.getOWLClass(IRI.create(relations.class2)), expression);
OWLObjectPropertyRangeAxiom owlObjectPropertyRangeAxiom=df.getOWLObjectPropertyRangeAxiom(objectProperty,subClassOfAxiom.getSuperClass());
manager.addAxiom(new_ontology,owlObjectPropertyRangeAxiom);

Upvotes: 0

Views: 1143

Answers (1)

Ignazio
Ignazio

Reputation: 10659

To give a complete code snippet:

OWLDataFactory df = ...
OWLAnnotationProperty  p=df.getOWLAnnotationProperty(IRI.create("urn:test#backwardCompatibleWith"));
OWLAnnotation ann=df.getOWLAnnotation(p, IRI.create("urn:test#languageDesign"));
OWLObjectProperty op=df.getOWLObjectProperty(IRI.create("urn:test#produces"));
OWLClass c = df.getOWLClass(IRI.create("urn:test#ProgramLanguage"));
OWLObjectPropertyRangeAxiom axiom=df.getOWLObjectPropertyRangeAxiom(op, c, Collections.singleton(ann));

At this point, add the axiom to your ontology and save in the preferred format. From the example, I'm guessing that's OWL/XML.

The question and this answer are available at https://github.com/owlcs/owlapi/issues/235 for further comments, discussions and any other activity that does not fit in StackOverflow format.

Regarding the mention of unsupported operations when adding annotations, note that all objects created by an OWLDataFactory are immutable. Annotations must be added when creating the objects, they cannot be added afterwards to already existing objects.

Upvotes: 1

Related Questions