This example shows how to map an attribute to an ontology and compute an ontology-based similarity function in the KNN.
jCOLIBRI uses the OntoBridge library to do the mapping an manage the ontologies.
The mapping consists on reading the values of an attribute from the persistence layer and link them with instances of an ontology.
In this example we are going to map the values of the Season column in the travelext database with the instances of the concept "SEASON" of the ontology vacation.owl.
This ontology contains information about travels and vacations. The SEASON concept organizes the information as shown in this figure:

To map this concept with the attributes in the database we have to change the type of the season attribute in the description to
Instance.
This type automatically connects with the ontology and links its value to the proper instance. To configure the mapping we have to modify the
travelDescription.hbm.xml file pointing out that we are using a Instance:
...
<property name="Season" column="Season">
<type name="es.ucm.fdi.gaia.jcolibri.connector.databaseutils.GenericUserType">
<param name="className">jcolibri.datatypes.Instance</param>
</type>
</property>
...
And finally, in the configure() method of our application we have to setup OntoBridge with the ontology:
...
OntoBridge ob = jcolibri.util.OntoBridgeSingleton.getOntoBridge();
ob.initWithPelletReasoner();
OntologyDocument mainOnto = new OntologyDocument("http://gaia.fdi.ucm.es/ontologies/vacation.owl",
FileIO.findFile("es/ucm/fdi/gaia/jcolibri/test/test5/vacation.owl").toURI().toString());
ArrayList subOntologies = new ArrayList();
ob.loadOntology(mainOnto, subOntologies, false);
...
With these changes the ontology is loaded and the values of Season are mapped to its instances.
Now, we can compute similarity functions that use information from the ontology. Here we are using the OntCosine() method:
simConfig.addMapping(new Attribute("Season", TravelDescription.class), new OntCosine());
For more information about OntoBridge read its documentation or visit the web page:
http://gaia.fdi.ucm.es/projects/ontobridge/.