Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encountering "TypeError: 'NoneType' object is not subscriptable" while saving an ontology (onto.save()) #26

Open
arundhati-b opened this issue May 31, 2022 · 2 comments

Comments

@arundhati-b
Copy link

This is happening after I try to save an ontology after removing some of its Object Properties. Not sure what the exact cause is and how to fix it.

TypeError                                 Traceback (most recent call last)
<ipython-input-20-a50699e0134c> in <module>
     39     filename = "raw/"+DATASET+"_"+split+".owl"
     40     print(onto, len(list(onto.properties())), list(onto.properties()))
---> 41     onto.save(file = filename, format = "rdfxml")

d:\Programs\Anaconda3\envs\pytorch\lib\site-packages\owlready2\namespace.py in save(self, file, format, **kargs)
   1004       if _LOG_LEVEL: print("* Owlready2 * Saving ontology %s to %s..." % (self.name, file), file = sys.stderr)
   1005       file = open(file, "wb")
-> 1006       self.graph.save(file, format, **kargs)
   1007       file.close()
   1008     else:

d:\Programs\Anaconda3\envs\pytorch\lib\site-packages\owlready2\driver.py in save(self, f, format, commit, **kargs)
    223   def save(self, f, format = "rdfxml", commit = False, **kargs):
    224     if commit: self.parent.commit()
--> 225     _save(f, format, self, **kargs)
    226 
    227 

d:\Programs\Anaconda3\envs\pytorch\lib\site-packages\owlready2\driver.py in _save(f, format, graph, filter)
    500 
    501       else:
--> 502         o = _unabbreviate(o)
    503         s_lines.append("""  <%s rdf:resource="%s"/>""" % (p, o))
    504 

d:\Programs\Anaconda3\envs\pytorch\lib\site-packages\owlready2\driver.py in _unabbreviate(storid)
    290     @lru_cache(None)
    291     def _unabbreviate(storid):
--> 292       r = graph._unabbreviate(storid).replace("&", "&amp;")
    293       if r.startswith(base_iri):
    294         if base_iri.endswith("/"): return r[len(base_iri) :]

d:\Programs\Anaconda3\envs\pytorch\lib\site-packages\owlready2\triplelite.py in _unabbreviate(self, storid)
    489 
    490   def _unabbreviate(self, storid):
--> 491     return self.execute("SELECT iri FROM resources WHERE storid=? LIMIT 1", (storid,)).fetchone()[0]
    492 
    493   def get_storid_dict(self):
@therhappy
Copy link

Up: I get the same problem.
The saving mechanism doesn't work for custom ontologies. Given the error I thought it was a matter of IRI, but I couldn't find any quick fix.

@therhappy
Copy link

therhappy commented Oct 13, 2022

OK, I have a fix actually.

First, make sure your IRI has a protocol, so for instance you'd init with:
onto = owlready2.get_ontology('http://local_ontology.owl')

Then allow it to be saved by bytes writing:

p = 'local.owl'
with open(p, 'wb') as f:
    onto.save(f)

Remember however that this here is an unofficial and unmaintained fork, the actual repo is here:
https://bitbucket.org/jibalamy/owlready2/src/master/
And official issue board here:
http://owlready.306.s1.nabble.com/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants