Re: Support load() to provide explicit ontology file locations
Posted by ehe on
URL: http://owlready.306.s1.nabble.com/Support-load-to-provide-explicit-ontology-file-locations-tp3197p3246.html
For this I use a config file in my projects and save the import paths for each ontology, which are then always loaded before the actual ontology. When loading for the first time, the user is asked to specify the import paths.
def load_file_ontology_with_dependencies(self, file_name, world = default_world):
try:
for imp in self.current_project["ontologies"][file_name]["imports"]:
world.get_ontology(f"file://{imp}").load(only_local=True)
log.info(f"Loading import: {imp}")
onto = world.get_ontology(f"file://{file_name}").load(only_local=True)
log.info(f"Ontology loaded: {onto.base_iri}")
return onto
except OwlReadyOntologyParsingError as e:
dlg = wx.MessageDialog(None, f"{e} \n Would you like to specify a local path to this ontology?", 'Load Missing ontologies', wx.YES_NO | wx.ICON_QUESTION)
if dlg.ShowModal() == wx.ID_YES:
with wx.FileDialog(None, "Open Ontology", wildcard="Ontology files|*.owl;*.rdf",
style=wx.FD_OPEN | wx.FD_FILE_MUST_EXIST) as fileDialog:
if fileDialog.ShowModal() == wx.ID_CANCEL:
return
pathname = fileDialog.GetPath()
self.current_project["ontologies"][file_name]["imports"].insert(0, pathname)
onto_path.append(pathname)
self.save_config()
self.load_file_ontology_with_dependencies(file_name)
else:
return