ontology merging

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

ontology merging

Jui Guram
Hi ,

I want to know if Owlready has support for merge ontologies?

Regards,
Jui
Reply | Threaded
Open this post in threaded view
|

Re: ontology merging

Jiba
Administrator
Hi,

By "merging ontology", you mean "copying all facts asserted in a given ontology to another ontology"? There is no support for that yet, but I think it would be rather easy and interesting to implement.

Best regards
Jiba
gp
Reply | Threaded
Open this post in threaded view
|

Re: ontology merging

gp
I effectively did something similar, where I gathered all imports (in some imports folder) and the main owl file (where the imports statements are placed) into one single rdf/xml file.

The code simply involved the world ontology and the rdflib hook. Here it is for inspiration:

import owlready2 as owl
import pathlib
import os

importPath = pathlib.Path('../TissuePhenomics.owl')
exportPath = pathlib.Path('../TissuePhenomicsAll.owl')



if os.path.exists(os.path.join(importPath.parent, 'imports')):
    owl.onto_path.append(os.path.join(importPath.parent, 'imports'))
else:
    raise Exception

if importPath.exists():
    owl.onto_path.append(str(importPath.parent.resolve()))
    tpoImport = owl.get_ontology(str(importPath.resolve())).load(only_local=True)
else:
    raise FileNotFoundError

world = owl.default_world

graph = world.as_rdflib_graph()

graph.serialize(destination=str(exportPath.resolve()), format="xml")