Re: ontology merging

Posted by gp on
URL: http://owlready.306.s1.nabble.com/ontology-merging-tp425p445.html

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")