I need to print [Class] - [Class sub-property] - [Class range] also [Class super property] in one line using owl API.
I have tried but I am only getting [class] and it's [sub-property]
below is my code :
package com.ifour.example.owl;
import java.io.File;
import org.semanticweb.owlapi.apibinding.OWLManager;
import org.semanticweb.owlapi.model.AxiomType;
import org.semanticweb.owlapi.model.IRI;
import org.semanticweb.owlapi.model.OWLClass;
import org.semanticweb.owlapi.model.OWLDataProperty;
import org.semanticweb.owlapi.model.OWLDataPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLNamedIndividual;
import org.semanticweb.owlapi.model.OWLObjectProperty;
import org.semanticweb.owlapi.model.OWLObjectPropertyDomainAxiom;
import org.semanticweb.owlapi.model.OWLOntology;
import org.semanticweb.owlapi.model.OWLOntologyManager;
public class IterateOWLDetails2 {
public static void main(String args[]) {
try {
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
IRI iri = IRI.create(new File("src/main/webapp/resources/inputfile/owlfile/pizza.owl"));
OWLOntology moduleOWL = manager.loadOntologyFromOntologyDocument(iri);
java.util.Set<OWLClass> classes;
java.util.Set<OWLObjectProperty> prop;
java.util.Set<OWLDataProperty> dataProp;
java.util.Set<OWLNamedIndividual> individuals;
classes = moduleOWL.getClassesInSignature();
prop = moduleOWL.getObjectPropertiesInSignature();
dataProp = moduleOWL.getDataPropertiesInSignature();
individuals = moduleOWL.getIndividualsInSignature();
System.out.println("Classes");
System.out.println("--------------------------------");
for (OWLClass cls : classes) {
System.out.println("+: " + cls.getIRI().getShortForm());
System.out.println(" \tObject Property Domain");
for (OWLObjectPropertyDomainAxiom op : moduleOWL.getAxioms(AxiomType.OBJECT_PROPERTY_DOMAIN)) {
if (op.getDomain().equals(cls)) {
for (OWLObjectProperty oop : op.getObjectPropertiesInSignature()) {
if (cls.getIRI().getShortForm().equals(oop.getIRI().getShortForm()))
continue;
System.out.println("\t\t +: " + oop.getIRI().getShortForm() + "==Object Property");
}
}
}
System.out.println(" \tData Property Domain");
for (OWLDataPropertyDomainAxiom dp : moduleOWL.getAxioms(AxiomType.DATA_PROPERTY_DOMAIN)) {
if (dp.getDomain().equals(cls)) {
for (OWLDataProperty odp : dp.getDataPropertiesInSignature()) {
System.out.println("\t\t +: " + odp.getIRI().getShortForm() + "==Data Property");
}
}
}
}
} // end try
catch (Exception e) {
System.out.println("Failed to load ontology/ies");
e.getLocalizedMessage();
e.printStackTrace();
} // end catch`
}
}
I have data like below
<owl:ObjectProperty rdf:about="http://www.co-ode.org/ontologies/pizza/pizza.owl#hasBase">
<rdfs:subPropertyOf rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#hasIngredient"/>
<owl:inverseOf rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#isBaseOf"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#FunctionalProperty"/>
<rdf:type rdf:resource="http://www.w3.org/2002/07/owl#InverseFunctionalProperty"/>
<rdfs:domain rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#Pizza"/>
<rdfs:range rdf:resource="http://www.co-ode.org/ontologies/pizza/pizza.owl#PizzaBase"/>
</owl:ObjectProperty>
I need to get domain, range, sub property from the file. I don't have subclass property in my file so please don't give solutions as using the list subclass method of ontology. I have iterated all the classes now I have to get the various property of that class like domain, range,sub-property, etc. of the iterated class.
I have printed my output using below code it's now solved my question like this way using property getObjectPropertyRangeAxioms(oop)
for(OWLObjectPropertyRangeAxiom range:moduleOWL.getObjectPropertyRangeAxioms(oop)) {
for(OWLEntity rangeStr : range.getSignature()) {
//System.out.println("\t\t ==========: " + rangeStr );
if(!rangeStr.containsEntityInSignature(oop)) {
System.out.println("\t\t -: " + rangeStr.toString().replaceAll("<|>", "") );
str = rangeStr.toString().replaceAll("<|>", "");
}
}
}