Thanks Ian and Olivier,
When I said it did not work, I meant the sub-ontology was not added to the main
ontology under the class I wanted.
What I have now is:
OntModelSpec oms = new OntModelSpec(OntModelSpec.OWL_MEM);
oms.setDocumentManager(OntDocumentManager.getInstance());
OntModel ontModel_sub = ModelFactory.createOntologyModel(oms);
ontModel_sub = (OntModel)ontModel_sub.read("file:" + "myfile.owl");
entireModel.add(ontModel_sub);
//I now understand that the above line was missing as Ian pointed out [line
***]
OntClass _class = entireModel.getOntClass(ns + "#" + "...");
//This gets the main parent class from my (sub-ontology not literally) to
become a subClassOf a class in the main ontology. This is now coming from the
main ontology as it has been added in [line ***]
OntClass main_class = entireModel.getOntClass(ns + "#" + "...");//this is
the class in the main ontology under which the sub-ontology will go
main_class.addSubClass(_class);
This is now working for me!
Thank you again for your help.
BO
________________________________
From: Olivier Rossel <[email protected]>
To: [email protected]
Sent: Tuesday, 14 May 2013 7:21 PM
Subject: Re: adding one ontology to another under a class
I think I would create a third .owl file that:
1: imports both the "upper" ontology and the "subtree" ontology,
2: lists the subClassOf to bind both ontologies together.
This is an easy task if the "subtree" ontology has a small set of
identified top-level classes.
You can do something similar programatically.
But you lose the formal description of the relationship between both
ontologies.
On Tue, May 14, 2013 at 11:14 AM, Ian Dickinson <[email protected]> wrote:
> 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
>
>