I am making an application which may require about 2-3 OWL files to work with, in order to serve different task for the same application. I am using Jena as my semantic web framework. My question is: How do we organize/setup these owl files? Should I read all the owl files in the same dataset or I should maintain different datasets for different owls. Note: I am not considering the Imported owls as it is handled by jena itself.
If I use same dataset, how can I differentiate to between he results obtained by functions like OntModel.lisRootHierarchyClasses(); and other such types of functions. Is it possible to name the ontologies when I read them into the OntModel.
Hence would like to know the best practice to handle more than one OWL files in a same application
For Example: I read my ontologies in the into an ontModel backed by a TDB dataset:
public static void loadModel(){
dataset.begin(ReadWrite.WRITE);
try{
ontModel = ModelToOntModel(model);
FileManager.get().readModel( ontModel, "SourceOwl1.owk");
FileManager.get().readModel( ontModel, "SourceOwl2.owl");
registerListener();
dataset.commit();
} catch (Exception e){
System.out.println("Error in Loading model from source!!");
e.printStackTrace();
} finally {
dataset.end();
}
}
Once the ontmodel
is ready a user input specifies a particular class (say : SourceOWL2_ClassA) among any of the owl files, which i further need to process its Object properties and datatype properties and provide user some information in the same context.
But in order to do that, properties from SourceOWL1 also get listed and hence cause errors. Further more the structure of the SourceOWL1 and SourceOWL2 are very much different, where SourceOWL1 contains about 3 imports and SourceOWL2 contains none.
After few days of extensive hands on I found the solution.
The answer is to make use of NAMED MODELS in
Dataset
. The mistake committed in the above code snippet is thatmodel
/ontModel
used is generated from the DefaultModel i.e.Model model = dataset.getDefaultModel();
Insted one should make use of :Model namedmodel = dataset.addNamedModel("NameOfModel");
where NameOfModel can be any string convenient for the developer. After which load the OWL files in the respectivenamedModel
.Thus the above function can be re-written as follows:
}
To answer the problems stated in the question: Once dataset creation is complete we can access the different ontologies /
OntModel
specific to our requirement by usingdataset.getNamedModel("NamedModel1")
and hence treat it as a ontModel independent of others. Since theontModel
used in the question was generated viadataset.getDefaultModel()
hence onontModel.lisRootHierarchyClasses()
used to result in root classes from all the source owls. But now one can access the desiered model using the named model concept andontModel.lisRootHierarchyClasses()
will answer the root classes specific to that ontology only.For more information on Named models you can refer here It helped me clear my concepts.. hope it helps you too..