Issues using W3C Time Ontology

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

Issues using W3C Time Ontology

MK
This post was updated on .
Hi There,
I'm wondering whether there is a parameter I can set when loading ontologies to request them in a specific format. I am currently having an issue loading the W3C Time ontology (and similarly, loading other ontologies that import the time ontology), because it seems that the IRI dereferences to a turtle file by default. See below for an example.

I can get around this issue when loading the time ontology individually by specifying a ".rdf" extension, but this does not resolve issues when loading ontologies that reuse the time ontology with its standard IRI. Has anyone run into this? Any suggestions on how I might resolve it?

Thanks in advance!

Megan

time = get_ontology('http://www.w3.org/2006/time')
>>> time.load()
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/driver.py", line 148, in parse
    s,p,o = splitter.split(line[:-3], 2)
ValueError: not enough values to unpack (expected 3, got 1)

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

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/namespace.py", line 777, in load
    try:     new_base_iri = self.graph.parse(fileobj, default_base = self.base_iri, **args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/driver.py", line 182, in parse
    raise OwlReadyOntologyParsingError("NTriples parsing error (or unrecognized file format) in %s, line %s." % (getattr(f, "name", getattr(f, "url", "???")), current_line)) from e
owlready2.base.OwlReadyOntologyParsingError: NTriples parsing error (or unrecognized file format) in http://www.w3.org/2006/time, line 11.
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontolgoy

Jiba
Administrator
Hi,

I've just added the 'url' argument to Ontology.load(), e.g.:

time = get_ontology('http://www.w3.org/2006/time').load(url = "http://www.w3.org/2006/time.rdf")

Alternatively, you can also put local copies of the ontology in a path listed in onto_path.

Jiba
MK
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

MK
Hi Jiba,

Thanks for this! Unfortunately, it doesn't quite solve my problem. The issue is that we are trying to use ontologies from other sources (we don't directly have control over them), and these ontologies import with W3C time ontology. So, what we need (I think) is some way to override how these imported ontologies are loaded. Is this possible?

Thanks again,
Megan
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

cknoll
Hi Megan,

I had a similar (but simpler) problem some time ago. I solved it by using this tool: https://github.com/sszuev/ont-converter

I think it could be automated, see this experiment (using http://www.w3.org/2006/time)

https://github.com/cknoll/demo-material/blob/main/expertise_system/experimental_onto_conversion.ipynb

Best, Carsten
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

cknoll
Today I came across that issue by myself again.

I think I now have a acceptable workaround, consisting of the following steps.

1. Download the problematic ontology as a file
2. Convert it to RDF_XML (e.g. with ont-converter or protege)
3. Load that ontology first e.g. as `time_ontology`
4. Load the ontology which imports this e.g. as `my_ontology`
5. Do `my_ontology.imported_ontologies.append(time_ontology)`

This notebook demonstrates the procedure:

https://nbviewer.jupyter.org/github/cknoll/demo-material/blob/main/expertise_system/experimental_onto_conversion.ipynb


Best,
Carsten
msf
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

msf
I tried following your steps, but it did not work.  I downloaded http://www.w3.org/2006/time using Protégé, and saved in RDF/XML format into time.owl.

I then tested the following:

time = get_ontology('time.owl').load()
ctime = get_ontology('http://ontology.eil.utoronto.ca/tove/ctime.owl').load()
ctime.imported_ontologies.append(time)

I received the following error when loading the ctime file (which imports http://www.w3.org/2006/time):

* Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/driver.py", line 148, in parse
    s,p,o = splitter.split(line[:-3], 2)
ValueError: not enough values to unpack (expected 3, got 1)

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

Traceback (most recent call last):
  File "/Users/markfox/Dropbox/Research/TOVE2/Code/OWL Time/timeTest.py", line 7, in <module>
    ctime = get_ontology('http://ontology.eil.utoronto.ca/tove/ctime.owl').load()
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/namespace.py", line 816, in load
    imported_ontologies = [self.world.get_ontology(self._unabbreviate(abbrev_iri)).load() for abbrev_iri in self.world._get_obj_triples_sp_o(self.storid, owl_imports)]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/namespace.py", line 816, in <listcomp>
    imported_ontologies = [self.world.get_ontology(self._unabbreviate(abbrev_iri)).load() for abbrev_iri in self.world._get_obj_triples_sp_o(self.storid, owl_imports)]
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/namespace.py", line 777, in load
    try:     new_base_iri = self.graph.parse(fileobj, default_base = self.base_iri, **args)
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/driver.py", line 182, in parse
    raise OwlReadyOntologyParsingError("NTriples parsing error (or unrecognized file format) in %s, line %s." % (getattr(f, "name", getattr(f, "url", "???")), current_line)) from e
owlready2.base.OwlReadyOntologyParsingError: NTriples parsing error (or unrecognized file format) in http://www.w3.org/2006/time#2016, line 11.
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

cknoll
I had a look on my example and noticed that I had messed up the different world-objects ("world3" was never used).

My current knowledge-status on this matter is: It seems to need one failing attempt to load the ontology, but the second attempt will work. See full example notebook here:

https://nbviewer.jupyter.org/github/cknoll/demo-material/blob/main/expertise_system/experimental_onto_conversion.ipynb#Short-Version-(works-with-freshly-restarted-kernel)


Short version:

from owlready2 import *
try:
    # while the following attempt fails, it is necessary to enable to load this ontology later
    ctime = default_world.get_ontology('http://ontology.eil.utoronto.ca/tove/ctime.owl').load()
except OwlReadyOntologyParsingError:
    print(f"could not import ontology on first attempt" )


time = default_world.get_ontology('time.owl').load()

# this now works
ctime = default_world.get_ontology('http://ontology.eil.utoronto.ca/tove/ctime.owl').load()

Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

Jiba
Administrator
In reply to this post by MK
Hi,

I think you can just "manually preload" the required ontologies.

For example, you may add:

time = get_ontology('http://www.w3.org/2006/time').load(url = "http://www.w3.org/2006/time.rdf")

at the beginning of your program (after importing Owlready) to force the loading of the right ontology. Then, when loading files, the ontologies they import are not reloaded if they are already in memory, so the time ontology will not be loaded again. This prevent to try to load it from the default turtle URL.

Jiba
msf
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

msf
Does not work. With this code:

  from owlready2 import *
  time = get_ontology('http://www.w3.org/2006/time').load(url = "http://www.w3.org/2006/time.rdf")

I get the following error:

* Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation
Traceback (most recent call last):
  File "resourceTest.py", line 20, in <module>
    time = get_ontology('http://www.w3.org/2006/time').load(url = "http://www.w3.org/2006/time.rdf")
  File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/site-packages/owlready2/namespace.py", line 777, in load
    try:     new_base_iri = self.graph.parse(fileobj, default_base = self.base_iri, **args)
TypeError: parse() got an unexpected keyword argument 'url'
Reply | Threaded
Open this post in threaded view
|

Re: Issues using W3C Time Ontology

Jiba
Administrator
Hi,

You need the development version of Owlready for having the "url =" argument support.

However, I will make a new release soon.

Jiba