Skip to content

6. Example: Removing Axioms from an Ontology

Luca Buoncompagni edited this page Apr 8, 2024 · 2 revisions

This example (i.e., example3) can be found in the path owloop/src/test/java/it/emaroLab/owloopArticleExamples/example3/.

It uses the following descriptor (which can be found in the path owloop/src/test/java/it/emaroLab/owloopArticleExamples/exampleDescriptors/):

  • ObjectLinkIndividualDesc: A Individual Descriptor that implements IndividualExpression interface ObjectLink.

The explanation of example3 is divided into two parts. Therefore firstly, we instantiate an ontology reference ontoRef, with a reference name and the path where the ontology file already exists (notice the method newOWLReferenceFromFileWithPellet()).

// Disables printing of amor logs
OntologyReference.activateAMORlogging( false);

// Ontology reference, newOWLReferencesCreatedWithPellet() allows to create a new ontology which does not exist
ontoRef = OntologyReference.newOWLReferenceFromFileWithPellet(
        "robotAtHomeOnto", // ontology reference name
        "src/test/resources/robotAtHomeOntology.owl", // the ontology file path
        "http://www.semanticweb.org/emaroLab/robotAtHomeOntology", // the ontology IRI path
        true // if (true) you must synchronize the reasoner manually. Else, it synchronizes itself.
);

And secondly, a new Descriptor robot_Desc1 is instantiated with the ground as "Robot1". By synchronization, axioms are read from the ontology into the robot_Desc1 Descriptor's internal state. With the help of removeObject() the association between the individual "Robot1" and the Object Property "isIn" is removed, within the internal state of the Descriptor robot_Desc1. Then, by synchronization, axioms are written into the ontology from the robot_Desc1 Descriptor's internal state. The ontology reasoner (Pellet) is synchronized, this is necessary because, this way the axioms within the ontology are updated with inferences based on the latest assertions (i.e., the removal of the object property "isIn"). Lastly, for the sake of testing whether the removal process has worked well, a new Descriptor robot_Desc2 is instantiated with the ground as "Robot1". By synchronization, axioms are read from the ontology into the robot_Desc2 Descriptor's internal state.

// robot individual
ObjectLinkIndividualDesc robot_Desc1 = new ObjectLinkIndividualDesc( "Robot1", ontoRef);

// synchronize axioms from the Ontology to the internal state of the Descriptor robot_Desc1.readExpressionAxioms();

// print the Descriptor
System.out.println(robot_Desc1);

// remove Object Property associated to the Individual Descriptor (i.e., from Descriptor's internal state)
robot_Desc1.removeObject("isIn");

// synchronize axioms from the internal state of the Descriptor and Ontology
robot_Desc1.writeExpressionAxioms();

// synchronize reasoner of the ontology, so that its axioms are updated with inferences based on latest assertions
ontoRef.synchronizeReasoner();

// save the current state of the ontology
robot_Desc1.saveOntology(ontoRef.getFilePath());

// A new Descriptor associated to the same individual as before
ObjectLinkIndividualDesc robot_Desc2 = new ObjectLinkIndividualDesc( "Robot1", ontoRef);

// synchronize axioms from the Ontology to the internal state of the Descriptor
robot_Desc2.readExpressionAxioms();

// print the Descriptor
System.out.println(robot_Desc2);

Screenshots

View of the IntelliJ-IDEA console, after executing owloop/../test/../example3/.

alt text