【问题标题】:IndexError: list index out of range ontology annotationIndexError:列表索引超出范围本体注释
【发布时间】:2021-01-27 10:01:36
【问题描述】:

我正在使用以下代码向本体添加注释

from owlready import *
onto = get_ontology("C://Users//sharm//Documents//ISWC2020//Ontology_read_play//Covid_v1.owl")
ANNOTATIONS[Thing].add_annotation("comment", "My comment")
onto.save()

然后它显示一个IndexError,当我使用 on.save() 保存它时

IndexError Traceback (most recent call last)<module>
--> onto.save()

C:\ProgramData\Anaconda3\lib\site-packages\owlready\__init__.py in save(self, filename)
282     owl = to_owl(self)
283     if filename: f = open(filename, "w")
--> 284     else:        f = _open_onto_file(self.base_iri, self.name, "w")
285     print("* Owlready * Saving ontology %s to %s..." % (self.name, getattr(f, "name", "???")), file = sys.stderr)
286     f.write(owl)

C:\ProgramData\Anaconda3\lib\site-packages\owlready\__init__.py in _open_onto_file(base_iri, name, mode, only_local)
199     if os.path.exists(filename): return open(filename, mode)
200   if (mode == "r") and not only_local: return urllib.request.urlopen(base_iri)
--> 201   if (mode == "w"): return open(os.path.join(onto_path[0], "%s.owl" % name), "w")
202   raise FileNotFoundError
203 

IndexError: list index out of range

【问题讨论】:

    标签: python-3.x data-annotations ontology index-error owlready


    【解决方案1】:

    在文档 (https://pythonhosted.org/Owlready2/onto.html) 上的快速搜索显示,如果您未在 save 方法中指定文件或文件名,它会使用 onto_path 模块变量中的第一个路径。你从来没有设置它,显然onto_path 开始是空的。

    save 方法中添加适当的名称参数,下次遇到问题时检查文档。

    【讨论】:

      猜你喜欢
      • 2011-10-31
      • 2015-06-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多