I have an ontology witch is created in protege, insid it :
I have 2 classes ( teenager and adult ).
I have the individual John with a dataProperty hasAge.
In protege i get the class of john according to his age. ( so my ontology work well)
Now i have loaded my ontology in java and i try to get all the individuals that are in the class adult ( Like John in protege ). so i did
//manager
OWLOntologyManager manager = OWLManager.createOWLOntologyManager();
//IRI
String x = "file:/D:/Studies/tpOwl.owl";
IRI ontologyIRI = IRI.create(x);
//ontology
OWLOntology ont = manager.createOntology(ontologyIRI);
//factory
OWLDataFactory factory = manager.getOWLDataFactory();
OWLReasonerFactory reasonerFactory = new StructuralReasonerFactory();
OWLReasoner reasoner = reasonerFactory.createReasoner(ont);
OWLClass adult = factory.getOWLClass(IRI.create(ontologyIRI + "#Adult"));
NodeSet<OWLNamedIndividual> instancess = reasoner.getInstances(adult, true);
for (Node<OWLNamedIndividual> i : instancess)
{
System.out.println(""+i);
}
but i got nothing.
So how can i get the individuals of a specific class after loading my ontology in java ?
There are a couple of errors in your code:
file:
, the other the IRI used in your ontology for uniquely identifying constructs in your ontology.StructuralReasonerFactory
use sayHermit
. See Hermit. JFact also does not work.Here are the working code using Hermit: