0

我正在尝试加载一个导入其他一些本体的本体。这些其他本体位于我的机器上,而不是在网络上。如果我尝试 my_ontology.load() 它会尝试从它们的 URI 加载这些其他本体。但这失败了。我如何告诉 owlready2 这些本体在哪里?

The traceback looks like this:

    Traceback (most recent call last):
  File "~Software/PyOntologyChecker/app.py", line 12, in <module>
    covid_onto = get_ontology_from_file(COVID_ONTOLOGY)
  File "~Software/PyOntologyChecker/app.py", line 8, in get_ontology_from_file
    return get_ontology("file://" + file_path).load()
  File "~.local/lib/python3.8/site-packages/owlready2/namespace.py", line 813, in load
    imported_ontologies = [self.world.get_ontology(self._unabbreviate(abbrev_iri)).load() for abbrev_iri in self.world._get_obj_triples_sp_o(self.storid, owl_imports)]
  File "~.local/lib/python3.8/site-packages/owlready2/namespace.py", line 813, in <listcomp>
    imported_ontologies = [self.world.get_ontology(self._unabbreviate(abbrev_iri)).load() for abbrev_iri in self.world._get_obj_triples_sp_o(self.storid, owl_imports)]
  File "~.local/lib/python3.8/site-packages/owlready2/namespace.py", line 773, in load
    except:  raise OwlReadyOntologyParsingError("Cannot download '%s'!" % f)
owlready2.base.OwlReadyOntologyParsingError: Cannot download 'http://ontofox.hegroup.org/CHEBI_module11.owl'!
4

1 回答 1

1

假设您有CHEBI_module11.owl依赖项的本地副本(例如SOME_DIR/HEBI_module11.owl),请将其位置添加到onto_path(如文档中所述):

onto_path.append("SOME_DIR")

在做之前my_ontology.load()。这告诉 Owlready2 在SOME_DIR. 路径可以是相对的或绝对的(如c:/data/ontologies)。

默认情况下不扫描当前 Python 的工作目录,但可以使用onto_path.append(".").

如果所需的本体由不以通常文件名结尾的 URI 描述,例如"http://rdf.webofcode.org/woc/",则本地文件名(woc在这种情况下)不应具有扩展名。

于 2021-02-19T13:15:23.770 回答