0

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);
Jpropeht89
  • 21
  • 4
  • It's easier to do some of these things if you specify the axiom you're trying to create in a simpler syntax, first. In this case, you're trying to say that the range of specifiedBy is the restriction class (specifiedBy max 1 Grammars). This seems sort of strange to me, as you're saying: "If specifiedBy(x,y), then there is at most one z such that specifiedBy(y,z)". Thinking of it in those terms, though, might make it easier to figure out the code that you need to write. – Joshua Taylor Jun 30 '14 at 16:35
  • Do you know to to make that inside annotation? the rest i just figure it out... – Jpropeht89 Jun 30 '14 at 19:04
  • There's [an example](https://github.com/owlcs/owlapi/blob/master/contract/src/test/java/org/coode/owlapi/examples/Examples.java#L1270) in the documentation that might help. If you solve this, be sure to post your result as an answer and accept it. Others will find your question and benefit from the solution you found. – Joshua Taylor Jun 30 '14 at 19:50
  • I already saw the examples for the annotations but the documentation on the OWL API sucks and didn't help so if you could help with the annotation would be great...i already did the rest but i can't answer because i'm a low ranking member and have to wait.. – Jpropeht89 Jun 30 '14 at 22:53
  • 1
    Well, you can still update your question with the code you have now. You're already using getOWLSubClassOfAxiom, what's the matter with using the version that take a set of annotations (there are two getOWLSubClassOfAxiom methods in OWLDataFactory)? – Joshua Taylor Jun 30 '14 at 23:25
  • If you find bad documentation be sure to raise the issue on the GitHub site or on the mailing list. We cannot fix documentation we don't know it's obscure or wrong. – Ignazio Jul 01 '14 at 09:47
  • @JoshuaTaylor yahp i saw that method but when i try to add a annotation to the set it gives me a error for UnSupported operation... – Jpropeht89 Jul 01 '14 at 10:57
  • @Jpropeht89 One of the reasons for closing questions is "Questions seeking debugging help ("why isn't this code working?") must include the desired behavior, a specific problem or error and the shortest code necessary to reproduce it in the question itself." If there's a method that looks relevant, and you've tried it, then you should show it in the question, along with the specific error message. It's much better to ask "I'm trying to do X, using Y, and got error Z, so what am I doing wrong?" than to ask "how do I do X?" If you've already tried that method and it doesn't work, then you've… – Joshua Taylor Jul 01 '14 at 12:11
  • …wasted some of your time (because you have to sort through comments and answers that suggest it) and **our time** (because we spend time suggesting it). If you've gotten that close already, show that code in your question, along with the actual error message. We're not mind readers; you need to show what you've tried and what didn't work. – Joshua Taylor Jul 01 '14 at 12:12

1 Answers1

1

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.

Ignazio
  • 10,504
  • 1
  • 14
  • 25