UnicodeDecodeError when trying to load default world

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

UnicodeDecodeError when trying to load default world

sparrowhank
Hello, Im consistently getting the following error while trying to load a antology from a sqlite file created by owlready2:

Traceback (most recent call last):
  File "C:\Users\Jpint\PycharmProjects\Ontologialivros\venv\lib\site-packages\owlready2\driver.py", line 149, in parse
    line = f.readline().decode("utf8")
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x80 in position 16: invalid start byte

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

Traceback (most recent call last):
  File "C:/Users/Jpint/PycharmProjects/Ontologialivros/main.py", line 14, in <module>
    onto = default_world.get_ontology("OntoFile.sqlite3").load()
  File "C:\Users\Jpint\PycharmProjects\Ontologialivros\venv\lib\site-packages\owlready2\namespace.py", line 1044, in load
    try:     new_base_iri = self.graph.parse(fileobj, default_base = self._base_iri, **args)
  File "C:\Users\Jpint\PycharmProjects\Ontologialivros\venv\lib\site-packages\owlready2\driver.py", line 190, in parse
    raise OwlReadyOntologyParsingError("NTriples parsing error (or unrecognized file format) in %s." % getattr(f, "name", getattr(f, "url", "???"))) from e
owlready2.base.OwlReadyOntologyParsingError: NTriples parsing error (or unrecognized file format) in OntoFile.sqlite3.

Process finished with exit code 1

I get this error in any ontology saved, even one created by owlready, this error comes from:

from owlready2 import *
#
# onto = get_ontology("http://test.org/onto.owl")
#
# class Book(Thing):
#     namespace = onto
#
#
# default_world.set_backend(filename = "OntoFile.sqlite3")
#
# default_world.save()

onto = default_world.get_ontology("OntoFile.sqlite3").load()

print(onto.Book.iri)

Im kinda lost what I could possibly be doing wrong ? Thank you very much in advance.
Reply | Threaded
Open this post in threaded view
|

Re: UnicodeDecodeError when trying to load default world

Jiba
Administrator
Hello,

Sqlite3 files created by Owlready are NOT ontology files, but quadstore files (possibly containing several ontologies).

To load an Sqlite3 file, you should use set_backend(), either on default_world, or on a newly created World, e.g. :

default_world.set_backend(filename = "OntoFile.sqlite3")

onto = default_world.get_ontology("http://test.org/onto.owl").load()
print(onto.Book)

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: UnicodeDecodeError when trying to load default world

sparrowhank
Hello,

I got it working didnt realize that was the case.

thank you very much for your help.