0

I am new in the semantic web field, and i'm trying to create a java model using JENA to extract classes, subclass and/or comments from an OWL file..

any help/guidance on how to do such thing would be appreciated.

Thank you

Emma
  • 9
  • 2
  • Welcome to stackoverflow! Please include what you have tried so far. – kosmičák Feb 18 '20 at 13:29
  • Not sure what you're asking, but the whole documentation is online: https://jena.apache.org/documentation/ – UninformedUser Feb 18 '20 at 13:29
  • Thank you for your reply, I'm actually lost in how/where to start the task from? Because you know its not a normal JAVA coding! So What i am really looking for is how to include JENA in my Project and start using it for reading and retrieving from OWL file. again,, thank you – Emma Feb 19 '20 at 15:27

1 Answers1

0

You can do so with the Jena Ontology API. This API allows you to create an ontology model from owl file and then provides you access to all the information stored in the ontology as Java Classes. Here is a quick introduction to Jena ontology. This introduction contains useful information on getting started with Jena Ontology.

The code generally looks like this:

String owlFile = "path_to_owl_file"; // the file can be on RDF or TTL format

/* We create the OntModel and specify what kind of reasoner we want to use
Depending on the reasoner you can acces different kind of information, so please read the introduction. */
OntModel model = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);

/* Now we read the ontology file
The second parameter is the ontology base uri.
The third parameter can be TTL or N3 it represents the file format*/
model.read(owlFile, null, "RDF/XML"); 

/* Then you can acces the information using the OntModel methods
Let's access the ontology properties */
System.out.println("Listing the properties");
model.listOntProperties().forEachRemaining(System.out::println);
// let's access the classes local names and their subclasses
try {
            base.listClasses().toSet().forEach(c -> {
                System.out.println(c.getLocalName());
                System.out.println("Listing subclasses of " + c.getLocalName());
                c.listSubClasses().forEachRemaining(System.out::println);
            });
        } catch (Exception e) {
            e.printStackTrace();
   }
// Note that depending on the classes types, accessing some information might throw an exception.

Here is the Jena Ontology API JavaDoc.

I hope it was useful!

soscler
  • 227
  • 4
  • 4