user3801191
user3801191

Reputation: 3

Getting individual properties with owl api

I'm trying to read the information stored in an ontology. The XML binding (of the part I'm working in) is:

<!-- hasPrevious and hasNext are defined at the imported ontology -->
<owl:NamedIndividual   rdf:about="http://www.myexampledomain.com/myExample.owl#one_relationship">
    <rdf:type rdf:resource="http://www.myexampledomain.com/myExample.owl#typeA"/>
    <intui_PO:hasPrevious rdf:resource="http://www.myexampledomain.com/myExample.owl#element01"/>
    <intui_PO:hasNext rdf:resource="http://www.myexampledomain.com/myExample.owl#element02"/>
</owl:NamedIndividual>

I use the following Java code:

//Create factories that will produce the objects
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
OWLDataFactory fac = man.getOWLDataFactory();

//Get a reasoner, to query the ontology
OWLReasonerConfiguration config = new SimpleConfiguration();
OWLReasoner reasoner = reasonerFactory.createReasoner(owlOnt, config);

//Get relations. Their properties are the related individuals
OWLClass myclass = fac.getOWLClass(IRI.create("http://www.myexampledomain.com/myExample.owl#RelationClass"));
NodeSet<OWLNamedIndividual> individualsRelationNodeSet = reasoner.getInstances(myclass,false);
Set<OWLNamedIndividual> relations = individualsRelationNodeSet.getFlattened();

With this, I have NamedIndividuals that are the relations found. I want to read their properties with:

Map<OWLObjectPropertyExpression,Set<OWLIndividual>> properties = oneRelation.getObjectPropertyValues(owlOnt);

But I get an empty Map. I cannot find the solution, can anyone help me?

Upvotes: 0

Views: 1808

Answers (1)

Artemis
Artemis

Reputation: 3301

I am not really sure what you are doing, but there is an easier way to read the individuals from the ontology than the one you used. I would suggest you read the OWL API documentation, it has so many good examples.

Set<OWLLogicalAxiom> axiomSet=localOntology.getLogicalAxioms();
    Iterator<OWLLogicalAxiom> iteratorAxiom= axiomSet.iterator();

    while(iteratorAxiom.hasNext()) {
        OWLAxiom tempAx= iteratorAxiom.next();
        if(!tempAx.getIndividualsInSignature().isEmpty()){
            System.out.println(tempAx.getIndividualsInSignature());
            System.out.println(tempAx.getDataPropertiesInSignature());
            System.out.println(tempAx.getObjectPropertiesInSignature());
        }
    }

Basically, you can just check if each axiom has an individual embedded in it, and then extract the property.

Upvotes: 5

Related Questions