0

Hi I'm following the http://owlapi.sourceforge.net/owled2011_tutorial.pdf to understand and attempt to parse an ontology in OWL2/RDF. I'm wondering how to obtain restrictions provided within a class and the code example in the tutorial as well as that in the github code https://github.com/owlcs/owlapi/blob/version4/contract/src/test/java/uk/ac/manchester/owl/owlapi/tutorialowled2011/TutorialSnippetsTestCase.java don't seem to show a working example. The PDF seems to have older logic and the example in the github seems to have commented out code. Any idea I'd be able to obtain and print the properties for a class - also how would I do this for the complex properties i.e. if i had the following kind of restriction within the class:

<rdfs:subClassOf>
        <owl:Restriction>
            <owl:onProperty rdf:resource="AAA"/>
            <owl:someValuesFrom>
                <owl:Class>
                    <owl:intersectionOf rdf:parseType="Collection">
                        <owl:Restriction>
                            <owl:onProperty rdf:resource="BBB"/>
                            <owl:someValuesFrom rdf:resource="111"/>
                        </owl:Restriction>
                        <owl:Restriction>
                            <owl:onProperty rdf:resource="CCC"/>
                            <owl:hasValue rdf:datatype="xsd;string">SOME VALUE</owl:hasValue>
                        </owl:Restriction>
                    </owl:intersectionOf>
                </owl:Class>
            </owl:someValuesFrom>
        </owl:Restriction>
    </rdfs:subClassOf>

How would I parse this programmatically. I'm trying to see what methods/classes of the API I should be looking at since I'm new to the jargon in OWL and linked data.

user1111871
  • 137
  • 1
  • 12

1 Answers1

0

Starting from the IRI for a class, e.g., "http://example.com/startpoint", you would:

  • Get an OWLClass instance: OWLClass c = owldatafactory.getOWLClass(IRI.create("http://example.com/startpoint"));
  • Retrieve all superclasses of this class from the declaring ontology: Collection<OWLSubClassOfAxiom> axioms = ontology.getSubClassAxiomsForSubClass(c);
  • For each axiom, access the superclass: for(OWLSubClassOfAxiom ax:axioms){ OWLClassExpression levelOne = ax.getSuperClass();

In your example, that's the someValuesFrom restriction on AAA.

In order to explore the restriction to any depth level, what you'd do is write an OWLClassExpressionVisitor (for example, by extending the OWLClassExpressionVisitorAdapter class). In the example you linked, one such class is RestrictionVisitor extends OWLClassExpressionVisitorAdapter.

If I get your description correctly, you're after the 'properties of a class' - the usual meaning for that is the properties where the input class is part of the domain. In this example, the only such property is AAA, so you don't need a deeper visit to find them. What's complex in this definition is the range of AAA, which is made of two more class expressions.

Ignazio
  • 10,504
  • 1
  • 14
  • 25
  • Thanks Ignazio. That helps me understand a bit better. When I mean I'm after the properties of the class, I do mean that I'm interested in both the property name and its value. e.g if I'm to interpret the above example, am i right in saying that instances 'startPoint' are related to instances of AAA where AAA has the property BBB with instance of 111 as the target and a second property CCC with a value of 'SOME VALUE' – user1111871 Nov 30 '15 at 15:15
  • No, AAA is a property here; BBB and CCC are related to the filler for AAA, i.e., the object (Y) for the statement X AAA Y – Ignazio Nov 30 '15 at 15:53
  • Understood. So I understood the code piece in the example now as well, as to what the OWLSubClassOfAxiom is - which is basically the tag for the corresponding class we obtain from. So, we have the set of these and we get the OWLClassExpressions in each case. But how are we getting the property domain/rang or anything from these now. From the documented examples it shows a restrictionVisitor.getRestrictedProperties() call which is commented out and no such method exists in the OWLClassExpressionVisitorAdapter in the 4.x versions. – user1111871 Nov 30 '15 at 16:32
  • for AAA, the property range is the intersection of all owl class expressions you find there. For the next level of properties, i.e., for BBB and CCC, you need to visit the class expressions the same way you visit the startpoint. The method about restricted properties is nothing more than the list of properties found on the restrictions that the visitor has been applied to - it can be replicated by applying the visitor multiple times and adding the value of restriction.getProperty() to a set. – Ignazio Dec 01 '15 at 19:51