Query sparql without reasoner

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

Query sparql without reasoner

Hamico
This post was updated on .
Hi Jiba,
Is it possible to execute sparql query without reasoner? What’s happen if i don’t write the istruction sync_reasoner()? It is necessary to have:
closed_world(onto) to close full ontology
or
closed_world(class) to close class, subclasses and individual istances

without closing relations to accelerate the activity and the execution of the reasoner? The ontology has a size of 20 MB.

When I close the ontology, I have the following error:


Traceback (most recent call last):
  File "C:/Users/hamico/PycharmProjects/App/Parte14/ClosedWorld.py", line 7, in <module>
    onto.save(file="onto2.owl", format="rdfxml")
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\namespace.py", line 809, in save
    self.graph.save(file, format, **kargs)
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\driver.py", line 218, in save
    _save(f, format, self, **kargs)
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\driver.py", line 482, in _save
    f.write( """\n""".join(flatten(sum(lines, []))).encode("utf8"))
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\driver.py", line 469, in flatten
    if isinstance(i, list): yield from flatten(i, deep + "    ")
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\driver.py", line 469, in flatten
    if isinstance(i, list): yield from flatten(i, deep + "    ")
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\driver.py", line 469, in flatten
    if isinstance(i, list): yield from flatten(i, deep + "    ")
  [Previous line repeated 990 more times]
RecursionError: maximum recursion depth exceeded


Many thanks.
Best regards,
Hamico
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Jiba
Administrator
Hi,

You don't need to call the reasoner before making SPARQL queries, unless you want to query the inferred facts.

close_world() adds constraints in the ontology, consequently, the reasoning will actually take more time, not less.

The error you obtained seems to be caused by nested lists, possibly related to blank nodes. Could you send me the ontologye and the code, so I can reproduce (and fix) the problem?

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Hamico
This post was updated on .
Hi Jiba,
Can you write me a gmail address so we can share our working ontology through google drive? Or also an official email address so I can send you the ontology through my other email address of libero?

Many thanks.
Best regards,
Hamico
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Jiba
Administrator
Hi,

I have the following address : petitmusiciensansnom @ gmail.com


(but I don't read it regularly, so please do not use it after that).

Best regards,
Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Hamico
Hi Jiba,
I have sent you the ontology at your google email. My script is the following:

from owlready2 import *
import sys
sys.setrecursionlimit(10000)
onto = get_ontology(".\\myontology.owl").load()
print("Closing world...")
close_world(onto)
print("World closed...")
onto.save(file=".\\myontology.owl", format="rdfxml")

Many thanks.
Best regards,
Hamico
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Jiba
Administrator
Hi,

I fixed the bug (it was a tricky problem with RDF list serialization) in the development version of Owlready.

As a workaround, you may also save your ontology in NTriple format, which did not suffer from this problem.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Hamico
This post was updated on .
Hi Jiba,
I have tried to change the "format" of saving from "rdfxml" to "rdf" and It works.
I have tried to use the development version of Owlready with the "format=rdfxml" of saving and It works.
Many thanks.
Hamico
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Hamico
Hi Jiba,
I have tried to run the reasoner on the closed ontology and I have had the following error:

C:\Users\hamico\PycharmProjects\App\venv\Scripts\python.exe C:/Users/hamico/PycharmProjects/App/Parte14/Test_Reasoner.py
Run reasoner...
* Owlready2 * Running HermiT...
    java -Xmx2000M -cp C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\hermit;C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\hermit\HermiT.jar org.semanticweb.HermiT.cli.CommandLine -c -O -D -I file:///C:/Users/HAMICO/AppData/Local/Temp/tmpjovkhs2h
Traceback (most recent call last):
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\reasoning.py", line 133, in sync_reasoner_hermit
    output = subprocess.check_output(command, stderr = subprocess.STDOUT)
  File "C:\Users\hamico\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 356, in check_output
    **kwargs).stdout
  File "C:\Users\hamico\AppData\Local\Programs\Python\Python36\lib\subprocess.py", line 438, in run
    output=stdout, stderr=stderr)
subprocess.CalledProcessError: Command '['java', '-Xmx2000M', '-cp', 'C:\\Users\\hamico\\PycharmProjects\\App\\venv\\lib\\site-packages\\owlready2\\hermit;C:\\Users\\hamico\\PycharmProjects\\App\\venv\\lib\\site-packages\\owlready2\\hermit\\HermiT.jar', 'org.semanticweb.HermiT.cli.CommandLine', '-c', '-O', '-D', '-I', 'file:///C:/Users/HAMICO/AppData/Local/Temp/tmpjovkhs2h']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/Users/hamico/PycharmProjects/App/Parte14/Test_Reasoner.py", line 7, in <module>
    sync_reasoner(debug=9)
  File "C:\Users\hamico\PycharmProjects\App\venv\lib\site-packages\owlready2\reasoning.py", line 138, in sync_reasoner_hermit
    raise OwlReadyJavaError("Java error message is:\n%s" % (e.stderr or b"").decode("utf8"))
owlready2.base.OwlReadyJavaError: Java error message is:


Process finished with exit code 1



How can I solve the problem?
Many thanks.
Best regards,
Hamico
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Jiba
Administrator
Hi,

I've investigated the problem; the Java error is a StackOverflowError. I fear that your ontology is too big / too complex for Hermit. Pellet does the same error.

Can you classify it in Protege?

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Hamico
Hi Jiba,
please can you tell me what's the meaning of classify the ontology in Protege?

Many thanks.
Best regards,
Hamico
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Jiba
Administrator
Hi,

I mean "execute the reasoner". I tested that, but I get the same error :(

Either the ontology is too big, of something went bad when closing it. I think the best approach here would be to try on subsets of the ontology, to see whether it works or not.

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Hamico
Hi Jiba,
I think the ontology is too big because both the reasoner and Protegè work very good when the ontology is opened. If I have some news, I write you here or through private email of the forum, not google email.

I wish to thank you very much.
Best regards,

Hamico
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Jiba
Administrator
Hello,

I also think the size of your ontology is the problem. Possibly you may reduce it -- in particular, closing the world entirely generate a lot of constraints, thus increasing the size and the complexity of the ontology.

I'm planning about writing a new reasoner in Python, and making this reasoner work at the SQL level -- thus allowing reasoning on large ontology. However, do not expect something working soon !

Jiba
Reply | Threaded
Open this post in threaded view
|

Re: Query sparql without reasoner

Hamico
Hi Jiba,
I hope to see as soon as possible the features of the new reasoner.
Many thanks.
Best regards,
Hamico