Agent47
Agent47

Reputation: 147

Merging a class sub hierarchy to another ontology using OWL API

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.

Upvotes: 2

Views: 520

Answers (1)

Ignazio
Ignazio

Reputation: 10659

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/

Upvotes: 0

Related Questions