【问题标题】:Loading ontology via owlready yields error通过 owlready 加载本体会产生错误
【发布时间】:2021-06-08 11:21:03
【问题描述】:

我想使用本体“dbnary”并且我正在使用 owlready 尝试从网站加载本体时,我收到此错误:

也许我使用了错误的库,是否有一个库可以处理海龟格式的本体。 我想通过该库提取单词的同义词。

from owlready2 import *
onto_path.append(r"C:\Users\Em\Docu\tal\Substitution\fr_dbnary_ontolex\fr_dbnary_ontolex.ttl")
onto = get_ontology(r"C:\Users\Em\Docu\tal\Substitution\fr_dbnary_ontolex\fr_dbnary_ontolex.ttl")
onto.load()

#error 
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
~\Anaconda3\lib\site-packages\owlready2\driver.py in parse(self, f, format, delete_existing_triples, default_base)
    153               if not line.endswith("\n"): line = "%s\n" % line
--> 154               s,p,o = splitter.split(line[:-3], 2)
    155 

ValueError: not enough values to unpack (expected 3, got 1)

The above exception was the direct cause of the following exception:

OwlReadyOntologyParsingError              Traceback (most recent call last)
<ipython-input-6-259cabd311da> in <module>
      2 onto_path.append(r"C:\Users\Emmanuelle\Documents\tal\Substitution\fr_dbnary_ontolex\fr_dbnary_ontolex.ttl")
      3 onto = get_ontology(r"C:\Users\Emmanuelle\Documents\tal\Substitution\fr_dbnary_ontolex\fr_dbnary_ontolex.ttl")
----> 4 onto.load()

~\Anaconda3\lib\site-packages\owlready2\namespace.py in load(self, only_local, fileobj, reload, reload_if_newer, url, **args)
    785         if _LOG_LEVEL: print("* Owlready2 *     ...loading ontology %s from %s..." % (self.name, f), file = sys.stderr)
    786         fileobj = open(f, "rb")
--> 787         try:     new_base_iri = self.graph.parse(fileobj, default_base = self.base_iri, **args)
    788         finally: fileobj.close()
    789       else:

~\Anaconda3\lib\site-packages\owlready2\driver.py in parse(self, f, format, delete_existing_triples, default_base)
    186           self._add_obj_triple_raw_spo(self.onto.storid, rdf_type, owl_ontology)
    187         if current_line:
--> 188           raise OwlReadyOntologyParsingError("NTriples parsing error (or unrecognized file format) in %s, line %s." % (getattr(f, "name", getattr(f, "url", "???")), current_line)) from e
    189         else:
    190           raise OwlReadyOntologyParsingError("NTriples parsing error (or unrecognized file format) in %s." % getattr(f, "name", getattr(f, "url", "???"))) from e

OwlReadyOntologyParsingError: NTriples parsing error (or unrecognized file format) in C:\Users\Emmanuelle\Documents\tal\Substitution\fr_dbnary_ontolex\fr_dbnary_ontolex.ttl, line 29

【问题讨论】:

  • 我想,你在 Turtle 中的本体,而 Owlready 仅支持 RDF/XML、OWL/XML 和 N-Triples。

标签: python python-3.x ontology turtle-rdf owlready


【解决方案1】:

来自Owlready2's doc

Owlready2 可以:

  • 以 NTriples、RDF/XML 或 OWL/XML 格式导入 OWL 2.0 本体

使用RDFLib 解析Turtle。

【讨论】:

    猜你喜欢
    • 2012-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-15
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多