Hello Brad,
On 14/05/13 01:42, Brad/Bahadorreza OFOGHI wrote:
Hi there,
I have two ontologies in OWL. One is a big picture place holder
(main
ontology) and the other is something like a sub-ontology that needs to
be appended under one of the classes in the main ontology (all that
exists in that sub-ontology needs to go under a class in the main
ontology, as a subClassOf).
OK
I have access to both ontologies programmatically. My question is:
how can I add the sub-ontology under a class of the main ontology?
I have tried this (in c#.Net):
I don't know C#, but I can read your code as Java. You'll have to
translate if my answer doesn't work in C# ..
//ontModel_main comes as a referennce arg. in the function
OntModelSpec oms = new OntModelSpec(OntModelSpec.OWL_MEM);
oms.setDocumentManager(OntDocumentManager.getInstance());
OntModel ontModel_sub = ModelFactory.createOntologyModel(oms);
ontModel_sub = (OntModel)ontModel_sub.read("file:" +
"sub_ont_file.owl");
OntClass ont_sub_class = ontModel_sub.getOntClass(ns + "#" +
"classname");//this is the parent class of all other classes in the sub ontology
ontModel_main.getOntClass(ns + "#" + "classname under which sub
ontology is supposed to be added").addSubClass(ont_sub_class);
If I understand the issue, the problem is that you haven't established
the relationship between ontModel_sub and ontModel_main. Your code can
be simplified quite a bit. What I would do is:
OntModel ontModelMain = ... your main ontModel ... ;
OntModel ontModelSub = ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM );
FileManager.get().readModel( ontModelSub, "sub_ont_file.owl" );
// this is the step you are missing
ontModelMain.addSubModel( ontModelSub );
// getting a reference to the class from the main model will ensure
// that you see all of the axioms
OntClass c = ontModelMain.getOntClass( ns + "#classname" );
One thing to beware of is that, in this setup, any updates will be
written to the base model, i.e. ontModelMain. If you specifically want
to update the sub model, you need to make sure that you're updating the
correct model:
OntClass c = ontModelMain.getOntClass( ns + "c" );
c.addComment( "foo" ); // will update the main model
OntClass c = ontModelSub.getOntClass( ns + "c" );
c.addComment( "foo" ); // will update the sub model
This does not seem to work. Any ideas?
As a general comment, please don't just say "it doesn't work". Be
specific, then we are more likely to be able to help. In what way
doesn't it work? If you were expecting something to happen and it
didn't, then what were you expecting and what actually happened? Can you
express that as a test case we could actually run?
Ian