通过 owlready 加载本体会产生错误

问题描述

我想使用本体“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,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,"???"))) 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

解决方法

来自Owlready2's doc

Owlready2 可以:

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

使用 RDFLib 解析 Turtle。