0

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 ?

max
  • 1
  • 1

1 Answers1

0

There are a couple of errors in your code:

  1. You need 2 IRIs: One for loading your ontology which is prepended with file:, the other the IRI used in your ontology for uniquely identifying constructs in your ontology.
  2. You have to load your ontology, not create it.
  3. You have to use a different reasoner. So instead of using StructuralReasonerFactory use say Hermit. See Hermit. JFact also does not work.

Here are the working code using Hermit:

        OWLOntologyManager manager = OWLManager.createOWLOntologyManager();

        //IRI
        Path path = Paths.get(".").toAbsolutePath().normalize();
        IRI loadDocumentIRI = IRI.create("file:/D:/Studies/tpOwl.owl");

        IRI ontologyIRI = IRI.create("http://www.semanticweb.org/akkou/ontologies/2017/10/tp-ontology");


        //ontology
        OWLOntology ont = manager.loadOntologyFromOntologyDocument(loadDocumentIRI);

        //factory
        OWLDataFactory factory = manager.getOWLDataFactory();


        OWLReasonerFactory reasonerFactory = new ReasonerFactory();
        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);
        }
Henriette Harmse
  • 4,167
  • 1
  • 13
  • 22
  • so you think that the problem is the StructuralReasonerFactory ? but how can i use JFact ? – max Dec 05 '17 at 20:41
  • It is definitely part of the problem. Just add it to your classpath. Download it from [maven central](https://mvnrepository.com/artifact/net.sourceforge.owlapi/jfact/5.0.1). – Henriette Harmse Dec 05 '17 at 21:12
  • JFact, Pellet, HermiT. As usual, add the library to your classpath - which indeed depends on how you're managing your project. With Maven, for example, it's just adding the appropriate dependency. – UninformedUser Dec 06 '17 at 07:09
  • And I hope you understand why it doesn't work with the StructuralReasoner, which in fact simply works on the asserted information and doesn't do any reasoning except simple class hierarchy computation. In Protege, for sure, you're also using a different reasoner, probably HermIT, which is an OWL reasoner using the common (hyper)tableau algorithm and being sound and complete regarding OWL 2 DL semantics. – UninformedUser Dec 06 '17 at 07:10