-
Notifications
You must be signed in to change notification settings - Fork 2
4. Example: Adding Axioms to an Ontology
This example (i.e., example1
) can be found in the path owloop/src/test/java/it/emaroLab/owloopArticleExamples/example1/
.
It uses the following descriptors (which can be found in the path owloop/src/test/java/it/emaroLab/owloopArticleExamples/exampleDescriptors/
):
-
DefClassDesc: A Class Descriptor that implements ClassExpression interface Definition.
-
LocationClassDesc: It extends DefClassDesc.
-
RoomClassDesc: It extends LocationClassDesc.
-
CorridorClassDesc: It extends LocationClassDesc.
-
ObjectLinkIndividualDesc: A simple Individual Descriptor that implements IndividualExpression interface ObjectLink.
-
DomainRangeObjectPropertyDesc: A a compound ObjectProperty Descriptor that implements 2 ObjectPropertyExpression interfaces, i.e., Domain, Range. This Descriptor can be found in the path
owloop/src/main/java/it/emarolab/owloop/descriptor/utility/objectPropertyDescriptor/
.
Assuming that you already know, how to construct a descriptor. In this example, it is particularly interesting to see how LocationClassDesc, RoomClassDesc and CorridorClassDesc were created, and what axioms they add to the ontology.
- DefClassDesc: is a Class Descriptor that implements the ClassExpression interface Definition.
-
LocationClassDesc: extends DefClassDesc and implements a method
getRestriction()
such that it adds to the ontology, the axiomLOCATION hasDoor some DOOR
. The axiom showcases the use of some-restriction. -
RoomClassDesc: extends LocationClassDesc and overrides the method
getRestriction()
such that it adds to the ontology, the axiom(LOCATION hasDoor some DOOR) and (ROOM hasDoor max 1 DOOR)
. The axiom showcases the use of max-cardinality-restriction. This Descriptor inherits the axiom(LOCATION hasDoor some DOOR)
from LocationClassDesc. -
CorridorClassDesc: extends LocationClassDesc and overrides the method
getRestriction()
such that it adds to the ontology, the axiom(LOCATION hasDoor some DOOR) and (CORRIDOR hasDoor min 2 DOOR)
. The axiom showcases the use of min-cardinality-restriction. This Descriptor inherits the axiom(LOCATION hasDoor some DOOR)
from LocationClassDesc.
The explanation of example1
is divided into three parts. Therefore firstly, we instantiate an ontology reference ontoRef
, with a reference name and the path where the ontology file needs to be created (notice the method newOWLReferencesCreatedWithPellet()
).
// Disables printing of amor logs
OntologyReference.activateAMORlogging( false);
// To create a new ontologyReference. The ontology file need not be pre-existing.
ontoRef = OntologyReference.newOWLReferencesCreatedWithPellet(
"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.
);
Secondly, we construct an ontology by adding axioms with the help of the Descriptors mentioned previously. Notice that the Descriptors are initialized with a ground and an ontology reference, for example, corridorIndividual_Desc
is instantiated as an ObjectLinkIndividualDesc with the ground as "Corridor1"
and ontology reference as ontoRef
.
// Add Class Expression Axioms to the ontology
LocationClassDesc locationClass_Desc = new LocationClassDesc( ontoRef);
CorridorClassDesc corridorClass_Desc = new CorridorClassDesc( ontoRef);
RoomClassDesc roomClass_Desc = new RoomClassDesc( ontoRef);
// Add Individual Expression Axioms (i.e., Assertions) to the ontology
ObjectLinkIndividualDesc corridorIndividual_Desc = new ObjectLinkIndividualDesc( "Corridor1", ontoRef); // Instantiate ObjectLinkIndividualDesc with ground as "Corridor1" and ontology reference as ontoRef
ObjectLinkIndividualDesc robotIndividual_Desc = new ObjectLinkIndividualDesc( "Robot1", ontoRef);
corridorIndividual_Desc.addObject( "isLinkedTo", "Room1");
corridorIndividual_Desc.addObject( "isLinkedTo", "Room2");
corridorIndividual_Desc.writeExpressionAxioms(); // write all axioms (represented in this descriptor) to the ontology
robotIndividual_Desc.addObject( "isIn", getRobotPosition()); // consider that we get robot's position after some computation
robotIndividual_Desc.writeExpressionAxioms();
// Adding ObjectProperty Expression Axioms to the Ontology
DomainRangeObjectPropertyDesc hasDoor_Desc = new DomainRangeObjectPropertyDesc( "hasDoor", ontoRef);
hasDoor_Desc.addDomainClassRestriction( "LOCATION");
hasDoor_Desc.addRangeClassRestriction( "DOOR");
hasDoor_Desc.writeExpressionAxioms();
DomainRangeObjectPropertyDesc isLinkedTo_Desc = new DomainRangeObjectPropertyDesc( "isLinkedTo", ontoRef);
isLinkedTo_Desc.addDomainClassRestriction( "CORRIDOR");
isLinkedTo_Desc.addRangeClassRestriction( "ROOM");
isLinkedTo_Desc.writeExpressionAxioms();
DomainRangeObjectPropertyDesc isIn_Desc = new DomainRangeObjectPropertyDesc( "isIn", ontoRef);
isIn_Desc.addDomainClassRestriction( "ROBOT");
isIn_Desc.addRangeClassRestriction( "LOCATION");
isIn_Desc.writeExpressionAxioms();
// this function is outside the main()
private String getRobotPosition() {
// ... consider that this method does some computation and finally returns the robot's position
// ...
return "Corridor1";
}
Finally, we save the ontology.
// saveOntology() works for ontologyReference instantiated with the method newOWLReferencesCreatedWithPellet()
ontoRef.saveOntology();
Ontology viewed using the Protege editor, after executing owloop/../test/../example1/
.
If we run the Ontology reasoner (in our case, the Pellet reasoner), we can see the following inferences in the Class Hierarchy.
Following are the Object Properties:
Following are the Data Properties: