2
votes

I have two ontologies called ontology A and ontology B without any individuals in both of them. Simply, I need to get a concept C1 in ontology A with its sub concepts (a sub hierarchy of concepts) and merge it to a concept in ontology B. Is there an easy way to achieve this in OWL API or do I have to code this logic from scratch?

I have looked into some other related questions, but they doesn't contain what I need. Protege only contains the option to merge two ontologies which is not the requirement of mine (Merge Ontology with Protege-OWL API). This question I found about merging ontologies also does the merging of complete ontologies (How to properly merge 2 ontologies with OWL API 4 or 3.5). What I want is to merge a part of an ontology to another.

Very simply, is there an easy way in OWL API to merge a part of an ontology (a sub hierarchy of concepts) to another ontology?

Thanks in advance.

1
just get the subclass axioms recursively starting from the concept and add those to the other ontology - yes, it's simple, approx. 10 lines of Java codeUninformedUser
Thanks @AKSW for the answer. I am new to owl api and I thought there may be easy methods in owl api other than coding the logic which is simple.Agent47
well, at least I'm not aware of any method like getSubClassHierarchy(OWLClass root) - but as I said, it's pretty simple to implement. Feel free to ask here if you have any issues with itUninformedUser
No, nothing is changed automatically. OWL is based on axioms which itself refer to entities identified by URIs. If you copy axioms from ontology 1 to ontology 2, you'll still have the URIs used in ontology 1. If you don't want this, you have to rename the classes, which means you have to re-create the subclass axioms with the new URIs.UninformedUser
@AKSW, I figured it out. And also understood what you said too. I just need to transfer the relevant axioms to the other ontology. Thank you for your time.Agent47

1 Answers

0
votes

The question is deceptively simple, but there are important constraints that need to be explicit before code can be written.

A sub hierarchy in an ontology where there are only named classes and subclass axioms between named classes is straightforward:

A subclassOf B
C subclassOf B

The sub hierarchy of B is completely described by these two axioms, so you can select them and copy across easily:

OWLOntology source = ...
OWLOntology destination = ...
OWLClass a = ...

source.subClassAxiomsForSuperClass(a).forEach(destination::addAxiom);
// repeat on the subclass in each axiom recursively

However, if there anonymous classes, the problem becomes quickly more complex:

A subclassOf exist r D
exist r D subclassOf B
C subclassOf B

It becomes very complex to select the set of axioms to copy to the destination ontology if it is necessary to preserve all inferences as well as the asserted hierarchy (for example, the GCI shown in the example above. There is a lot of literature available about modularisation and atomic decomposition, both are research areas that cover the topic of selecting the axioms that allow all inferences that refer to an initial signature - in this case, your starting class.

You can obtain the set of axioms using SyntacticLocalityModuleExtractor:

destination.addAxioms(new SyntacticLocalityModuleExtractor(
        source.getOWLOntologyManager(), 
        source, 
        ModuleType.STAR));

However you should read the relevant articles in the literature to understand the advantages and limitations of the approaches available. Some starting points:

http://owl.cs.manchester.ac.uk/research/modularity/

http://www.cs.man.ac.uk/~delvescc/dl-10.pdf

https://www.ncbi.nlm.nih.gov/pmc/articles/PMC3113511/