SLIDE 2 OWLOntology ontology = man.loadOntology(ontologyIRI); System.out.println(ontology.getLogicalAxiomCount()); } catch (OWLOntologyCreationException e) { e.printStackTrace(); }
- 7. When you execute the program, you should be able to see the axiom count: 712.
- Congratulations. You have just conquered mount Olympus.
- 8. For every task in the following, we recommend you to create a new class with some sensible
name (OWLAPITutorialTask1) , copy the test code mentioned in the Basic Project Setup into it and go from there.
Task 1: Loading ontology from the file system / first glimpse of entities
You know now how to load an ontology from the web and extract a simple piece of information about it (the logical axiom count). Your first assignment will be to play with the OWLOntologyManager and find a way to load your own Sushi Ontology that you have created as part of last weeks coursework into the OWL API and print a list of all the classes you have in your
- ntology onto the console (System.out). When you are done with this exercise, play with the
OWLOntology interface and print other interesting bits of information (Ontology IRI, Object Property Count, print all TBox axioms etc) . Tip: make heavy use of your IDEs autocomplete features. In Eclipse you can trigger it by using CTRL + SPACE.
Task 2: Creating entities and asserting axioms
We have been looking at the properties of an existing ontology. Let’s try to create something for a
- change. We have seen in the demo how to create a simple class declaration. In this task, you are
asked to create a second class, Person, and make Student a subclass of it. To ensure that you have done the right thing, print the axioms in the ontology to the console (you should know how to do this by now). If you are done with this, create two or three students. For that, find out how to create a named individual, and assert it to be a member of the student class. Make sure you add this assertion to the
- ntology again and check whether it worked in the known style.
IRI ontologyIRI = IRI.create("http://owl.cs.man.ac.uk/ontology"); OWLOntologyManager man = OWLManager.createOWLOntologyManager(); OWLDataFactory factory = man.getOWLDataFactory(); PrefixManager pm = new DefaultPrefixManager(ontologyIRI+"#"); try { OWLOntology ontology = man.createOntology(ontologyIRI); System.out.println("Created: "+ontology.getOntologyID().getOntologyIRI()); OWLClass student = factory.getOWLClass(":Student",pm); OWLDeclarationAxiom declaration = factory.getOWLDeclarationAxiom(student); man.addAxiom(ontology, declaration); System.out.println(student); } catch (OWLOntologyCreationException e) { e.printStackTrace(); }