I am adding annotation to ontology using following code
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()
Then it shows an IndexError
, when I have save it using onto.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
Quick search on the doc (https://pythonhosted.org/Owlready2/onto.html) shows that if you don't specify a file or a filename in the
save
method, it uses the first path inonto_path
module variable. You never set it up and apparentlyonto_path
starts empty.Add the appropriate name parameter to the
save
method and checkout the doc next time you have problems.