Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create project from owl file #230

Merged
merged 11 commits into from
Nov 8, 2022
57 changes: 51 additions & 6 deletions eddy/core/loaders/owl2.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,13 @@ def createProject(self):
"""
Create the Project by reading data from the parsed Owl File.
"""
ontologyIRI, ontologyV = self.getOntologyIRI()
MariaRosariaFraraccio marked this conversation as resolved.
Show resolved Hide resolved
self.nproject = Project(
parent=self.session,
profile=self.session.createProfile('OWL 2'),
ontologyIRI=self.getOntologyIRI()
ontologyIRI=ontologyIRI,
version=ontologyV,
imports=self.addImports()
)
LOGGER.info('Loaded project from ontology: %s...', self.path)

Expand All @@ -67,17 +70,59 @@ def getOntologyIRI(self):
vm.attachThreadToJVM()

OWLManager = vm.getJavaClass('org.semanticweb.owlapi.apibinding.OWLManager')
MissingImportHandlingStrategy = vm.getJavaClass('org.semanticweb.owlapi.model.MissingImportHandlingStrategy')
JavaFileClass = vm.getJavaClass('java.io.File')
fileInstance = JavaFileClass(self.path)
manager = OWLManager().createOWLOntologyManager()
manager.getOntologyLoaderConfiguration().setMissingImportHandlingStrategy(MissingImportHandlingStrategy.SILENT)
ontology = manager.loadOntologyFromOntologyDocument(fileInstance)
try:
ontology_version = ontology.getOntologyID().getVersionIRI().get().toString()
except Exception:
ontology_version = ontology.getOntologyID().getOntologyIRI().get().toString()
ontologyID = ontology.getOntologyID()
if ontologyID.isAnonymous():
ontologyIRI = None
ontologyV = None
else:
ontologyIRI = ontologyID.getOntologyIRI().get().toString()
if ontologyID.getVersionIRI().isPresent():
ontologyV = ontologyID.getVersionIRI().get().toString()
else:
ontologyV = None

return ontology_version
return ontologyIRI, ontologyV

def addImports(self):
MariaRosariaFraraccio marked this conversation as resolved.
Show resolved Hide resolved
"""
Add imported ontologies.
"""
vm = getJavaVM()
if not vm.isRunning():
vm.initialize()
vm.attachThreadToJVM()

OWLManager = vm.getJavaClass('org.semanticweb.owlapi.apibinding.OWLManager')
JavaFileClass = vm.getJavaClass('java.io.File')
fileInstance = JavaFileClass(self.path)
manager = OWLManager().createOWLOntologyManager()
ontology = manager.loadOntologyFromOntologyDocument(fileInstance)

directImports = ontology.getDirectImports()
importedOnto = set()
for imp in directImports:
ontologyID = imp.getOntologyID()
if ontologyID.isAnonymous():
ontologyIRI = None
ontologyURI = None
ontologyV = None
else:
ontologyIRI = ontologyID.getOntologyIRI().get().toString()
ontologyURI = ontologyID.getOntologyIRI().get().toURI().toString()
Copy link
Collaborator

@mnamici mnamici Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stessa cosa qui, va inserito il path al file altrimenti non riusciamo a caricarla nuovamente.
EDIT: mi riferisco alla riga 117

if ontologyID.getVersionIRI().isPresent():
ontologyV = ontologyID.getVersionIRI().get().toString()
else:
ontologyV = None
impOnto = ImportedOntology(ontologyIRI, ontologyURI, ontologyV, False)
importedOnto.add(impOnto)

return importedOnto

class OwlOntologyImportWorker(AbstractWorker):
"""
Expand Down