Search Mailing List Archives


Limit search to: Subject & Body Subject Author
Sort by: Reverse Sort
Limit to: All This Week Last Week This Month Last Month
Select Date Range     through    

[protege-owl] Importing one ontology to another in a java API

Timothy Redmond tredmond at stanford.edu
Thu Feb 23 10:43:08 PST 2012


On 02/23/2012 09:33 AM, samane abdi wrote:
> Hi Timothy,
>
> Thanks for your hel and good stuff. I have the same code as yours. I 
> guess the problem for my code was referring to the ontology URI on 
> disk( file:/// home/...). I have sorted out the problem by changing 
> the URI format. My code works fine now. For the second part of my 
> previous question, I should say I wanna move(instead of add!) "class 
> b" from ontology B as a subclass of "class a" in ontology A. Is there 
> any straightforward piece of coding on that?


This is one of those things that is much easier in the Manchester OWL 
api than it is in the Protege 3 OWL api.  Depending on what you want to 
do, I don't think that it is very trivial to do in the Protege 3 OWL 
api.  I am not sure I know how to do it but I can raise some of the 
issues.  In the Manchester OWL api, it is trivial once you have clearly 
defined exactly what moving the class means.

First we need to define what you mean by moving a class from one 
ontology to the other.  The insight is that you really want to move is 
some set of axioms (things that are asserted to be true) about the class 
b from ontology B to ontology A.  In the Manchester OWL api, all of 
these move operations are trivial.  Depending on what you mean the 
identification of the axioms to be moved is also trivial.  In the 
Protege 3 OWL api, I would have to do some experimentation to figure out 
how to do it and the resulting code will be fairly messy.

So for example, the ontology B might include the following axiom:

    Class: B
         SubClassOf:
             X


Perhaps you would then want to to remove this axiom from ontology B and 
add this axiom from ontology A.  If X is a named class I could imagine 
moving this axiom from ontology B to ontology A by

 1. removing the X superclass from B in ontology B
 2. adding the X superclass from B in ontology A.


If you do this after the import operation, you could simply make the 
remove superclass call followed by the add superclass call.

But things get more complicated if your axiom contains class 
expressions.  So for instance ontology B might contain the following 
definition of the class B:

    Class: B

         EquivalentTo:
             Y and (p some Z)


To do this in Protege 3,  I think that you must

 1. copy the class expression "Y and (p some Z)" from the ontology B to
    the ontology A.  I don't remember how to do this but there is some
    sort of clone method that will take care of this for you.
 2. delete the equivalent class axiom from ontology B.
 3. add the equivalent class axiom to ontology A.

You have to be a little careful here.  If you reverse steps 1 and 2 then 
the class expression "Y and p some Z" is garbage collected and the copy 
operation will fail.  If you don't do step 1 and you reverse steps 2 and 
3, then - I think - that the class expression is, in some weird sense, 
held in ontology B even though it is referenced in ontology A.  I 
wouldn't be surprised if this will then break on a save and reload.

Finally there is a case where I am not sure what you would want to do.  
The class B might occur in axioms in ontology B that you, perhaps, had 
not considered.  For example, perhaps ontology B has the axiom:

    Class: T
         EquivalentTo:
             Y and (p some B)


This axiom involves the class B and would this mean that you would want 
to move this axiom from ontology B to ontology A?

In the Manchester OWL api, you would simply identify the axioms that you 
wanted to move, remove them from ontology B and then add them to ontology A.

-Timothy



>
> Thanks for you help,
> Samane
>
> On Wed, Feb 22, 2012 at 9:49 PM, Timothy Redmond 
> <tredmond at stanford.edu <mailto:tredmond at stanford.edu>> wrote:
>
>     On 2/22/12 3:39 AM, samane abdi wrote:
>>     Hi Timothy,
>>     Thanks for your reply. I have added the line that you mentioned.
>>     It just shows that the ontology B was imported in the namespace
>>     window with prefix "myPrefix" . However, when I open the metadata
>>     tab or class tab or property tab, etc... there is no entity from
>>     ontology B(is not imported) in Ontology A. How can I see the
>>     imported entities in ontology A?
>
>     I am not sure what is happening here so I modified your code so
>     that it utilizes ontologies on the internet so that we can compare
>     results.  I ran the attached AddImport code and as a result I
>     obtained the attached ontology called pizza-with-import.owl. You
>     can also see from the attached figure that Animal (from the koala
>     ontology) is a subclass of DomainConcept from the pizza ontology.
>
>     Do you get a different result with this code?  Do you get a
>     different result when you point your own data?  Are their any
>     exceptions?
>
>
>>      In addition, I do not know how to add "class b" from ontology B
>>     as a subclass of "class a" from ontology A. Is there any solution
>>     on this?
>
>     I didn't address this in my previous posts.  This is done with a
>     small bit of code:
>
>          public static void addSuperClass(OWLModel owlModel) {
>              // from pizza
>              OWLNamedClass domainConcept = owlModel.getOWLNamedClass("http://www.co-ode.org/ontologies/pizza/pizza.owl#DomainConcept"  <http://www.co-ode.org/ontologies/pizza/pizza.owl#DomainConcept>);
>              // from koala
>              OWLNamedClass animal = owlModel.getOWLNamedClass("http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#Animal"  <http://protege.stanford.edu/plugins/owl/owl-library/koala.owl#Animal>);
>              animal.addSuperclass(domainConcept);
>          }
>
>
>     -Timothy
>
>
>
>>     Thanks,
>>     Samane
>>
>>     On Tue, Feb 21, 2012 at 7:08 PM, Timothy Redmond
>>     <tredmond at stanford.edu <mailto:tredmond at stanford.edu>> wrote:
>>
>>
>>         Actually your code seemed to work perfectly on the first
>>         try.  The one thing that might be an issue is that perhaps
>>         you expected to find the modified ontology on disk whereas
>>         your code simply loads it into memory.  I added a
>>
>>             owlModel.save(URI.create("file:///Volumes/Shared/ontologies/simple/pizza-with-import.owl"));
>>
>>
>>         line (your file path will differ) and was able to examine the
>>         modified version of the ontology on the disk.
>>
>>         -Timothy
>>
>>
>>
>>         On 2/21/12 7:15 AM, samane abdi wrote:
>>>         Dear Experts,
>>>
>>>         I built two ontologies A and B. I want to import ontology B
>>>         to ontology A and add "class b" and all its relations and
>>>         individuals from Ontology B as a subclass of "class a" from
>>>         Ontology A. How can I encode this in a java API(such as
>>>         Eclipse).
>>>
>>>         Here is a fragment of my code which does not give me the
>>>         desired result.
>>>
>>>         "public static void main(String[] args) throws
>>>         OntologyLoadException, URISyntaxException {
>>>         JenaOWLModel owlModel;
>>>         //JenaOWLModel owlModel = ProtegeOWL.createJenaOWLModel();
>>>            String DAL2Ontology = "file:///home/A.owl";
>>>         owlModel = ProtegeOWL.createJenaOWLModelFromURI(DAL2Ontology);
>>>         //String medicalOntology =
>>>         "file:///home/sabdi/Applications/Protege3.4.8/MedicalOntology/Medical.owl";
>>>         //if you want to use a custom prefix for the namespace of
>>>         the imported ontology, uncomment the following line
>>>         owlModel.getNamespaceManager().setPrefix(new
>>>         URI("file:///home/B.owl#"), "myPrefix");
>>>
>>>         //create the ImportHelper
>>>         ImportHelper importHelper = new
>>>         ImportHelper((JenaOWLModel)owlModel);
>>>
>>>         //this is the URI from where your ontology is created
>>>         //URI importUri =
>>>         URIUtilities.createURI("file:///home/sabdi/Applications/Protege3.4.8/test/DAL2.owl");
>>>         URI importUri2 = URIUtilities.createURI("file:///home/B.owl");
>>>         //add the import (multiple imports can be added here)
>>>         //importHelper.addImport(importUri);
>>>         importHelper.addImport(importUri2);
>>>         try {
>>>            //do the actual import
>>>         importHelper.importOntologies();
>>>            //importHelper.importOntologies(true);
>>>         } catch (Exception e) {
>>>            e.printStackTrace();
>>>         }
>>>           }"
>>>
>>>
>>>         Can you suggest me a solution or a tutorial for this?
>>>
>>>         Thanks,
>>>         Samane
>>>
>>>         -- 
>>>         Samane
>>>
>>>
>>>         _______________________________________________
>>>         protege-owl mailing list
>>>         protege-owl at lists.stanford.edu  <mailto:protege-owl at lists.stanford.edu>
>>>         https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>>
>>>         Instructions for unsubscribing:http://protege.stanford.edu/doc/faq.html#01a.03
>>
>>
>>         _______________________________________________
>>         protege-owl mailing list
>>         protege-owl at lists.stanford.edu
>>         <mailto:protege-owl at lists.stanford.edu>
>>         https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>
>>         Instructions for unsubscribing:
>>         http://protege.stanford.edu/doc/faq.html#01a.03
>>
>>
>>
>>
>>     -- 
>>     Samane
>>
>>
>>     _______________________________________________
>>     protege-owl mailing list
>>     protege-owl at lists.stanford.edu  <mailto:protege-owl at lists.stanford.edu>
>>     https://mailman.stanford.edu/mailman/listinfo/protege-owl
>>
>>     Instructions for unsubscribing:http://protege.stanford.edu/doc/faq.html#01a.03
>
>
>     _______________________________________________
>     protege-owl mailing list
>     protege-owl at lists.stanford.edu <mailto:protege-owl at lists.stanford.edu>
>     https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
>     Instructions for unsubscribing:
>     http://protege.stanford.edu/doc/faq.html#01a.03
>
>
>
>
> -- 
> Samane
>
>
> _______________________________________________
> protege-owl mailing list
> protege-owl at lists.stanford.edu
> https://mailman.stanford.edu/mailman/listinfo/protege-owl
>
> Instructions for unsubscribing: http://protege.stanford.edu/doc/faq.html#01a.03

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.stanford.edu/pipermail/protege-owl/attachments/20120223/9119e2df/attachment-0001.html>


More information about the protege-owl mailing list