Search code examples
pythonpython-3.xontologyturtle-rdfowlready

Loading ontology via owlready yields error


I would like to use the ontology "dbnary" and I am using owlready When trying to load the ontology from the website, I get this error :

Maybe I am using the wrong library, is there a library to work with ontology in turtle format. I want to extract synonym of words via that library.

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, f, format, delete_existing_triples, 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, "name", getattr(f, "url", "???"))) 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

Solution

  • From Owlready2's doc:

    Owlready2 can:

    • Import OWL 2.0 ontologies in NTriples, RDF/XML or OWL/XML format

    Use RDFLib for parsing Turtle.