-
Notifications
You must be signed in to change notification settings - Fork 10
5. Example: Inferring Axioms from an Ontology
This example (i.e., example2
) can be found in the path owloop/src/test/java/it/emaroLab/owloopArticleExamples/example2/
.
It uses the following descriptors (which can be found in the path owloop/src/test/java/it/emaroLab/owloopArticleExamples/exampleDescriptors/
):
-
ObjectLinkIndividualDesc: A Individual Descriptor that implements IndividualExpression interface ObjectLink.
-
TypeIndividualDesc: A Individual Descriptor that implements IndividualExpression interface Type.
-
DefSubClassDesc: A Class Descriptor that implements 2 ClassExpression interfaces Definition and Sub.
The explanation of example2
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, we read axioms (both, asserted and inferred) from the ontology file, with the help of the Descriptors mentioned previously. Apart from simply reading axioms from the Ontology, notice that the Descriptors are also used to build other Descriptors which are grounded in knowledge obtained from the former Descriptor. For example in, Set<DefSubClassDesc> setOfClassTypes = d2.buildTypeIndividual();
and Set<DefSubClassDesc> setOfSubClasses = d3.buildSubClass();
.
// Considering that the Robot's position is saved in the ontology after running Example1
ObjectLinkIndividualDesc d1 = new ObjectLinkIndividualDesc( "Robot1", ontoRef);
d1.addObject( "isIn",true); // to be able to read knowledge (only) specific to the property "isIn"
d1.readExpressionAxioms(); // read all axioms (related to this descriptor) from the ontology
System.out.println( d1); // printing to check the axioms represented by this descriptor
OWLNamedIndividual robotPosition = d1.getObject( "isIn"); // get knowledge from the internal state of the Descriptor
TypeIndividualDesc d2 = new TypeIndividualDesc( robotPosition, ontoRef); // here, robotPosition = "Corridor1"
d2.readExpressionAxioms();
System.out.println( d2); // printing
Set<DefSubClassDesc> setOfClassTypes = d2.buildTypeIndividual(); // (Descriptor.buildTypeIndividual()) here, gets the Type(s) (i.e., Class(es)) of the Individual "Corridor1", as grounded Descriptors
for( DefSubClassDesc d3 : setOfClassTypes ){
Set<DefSubClassDesc> setOfSubClasses = d3.buildSubClass(); // (Descriptor.buildSubClass()) here, gets the subClasses of a Class, as grounded Descriptors
if( setOfSubClasses.size() == 1 ) { // to find the root Class, because it has max. 1 subClass, i.e., owl:Nothing
System.out.println( "'" + d3.getInstanceName() + "' is the root Class among: "); // printing
for( DefSubClassDesc classType : setOfClassTypes ){
System.out.println( "\t\t\t'" + classType.getInstanceName() + "'"); // printing
}
System.out.print( "\n'" + d2.getInstanceName() + "'" + " is of Type " + "'" + d3.getInstanceName() + "' \n"); // printing
DescriptorEntitySet.Restrictions restrictions = d3.getDefinitionClasses();
for( SemanticRestriction rest : restrictions ){
if( rest instanceof SemanticRestriction.ClassRestrictedOnExactObject ){
System.out.println( "\n" + "'" + d3.getInstanceName() + "'" + " is defined with Exact Cardinality Restriction " + "'" + rest + "'"); // printing
}
else if( rest instanceof SemanticRestriction.ClassRestrictedOnMinObject ){
System.out.println( "\n" + "'" + d3.getInstanceName() + "'" + " is defined with Min Cardinality Restriction " + "'" + rest + "'"); // printing
}
}
}
}
View of the IntelliJ-IDEA console, after executing owloop/../test/../example2/
.