Having problem in loading local Sparql endpoint through get_ontology()

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

Having problem in loading local Sparql endpoint through get_ontology()

7klaus
This post was updated on .
import flask

from owlready2 import *
from owlready2.sparql.endpoint import *

# Load one or more ontologies
go = get_ontology("http://localhost:8000/repositories/semantic").load()

app = flask.Flask("Owlready_sparql_endpoint")
endpoint = EndPoint(default_world)
app.route("/sparql", methods = ["GET"])(endpoint)


import werkzeug.serving
werkzeug.serving.run_simple("localhost", 5008, app)


I am getting errors when loading the localhost SPARQL endpoint of Graph DB.

* Owlready2 * Warning: optimized Cython parser module 'owlready2_optimized' is not available, defaulting to slower Python implementation
Traceback (most recent call last):
  File "/home/gaurav/.local/lib/python3.8/site-packages/owlready2/namespace.py", line 899, in load
    try:     fileobj = urllib.request.urlopen(url or f)
  File "/usr/lib/python3.8/urllib/request.py", line 222, in urlopen
    return opener.open(url, data, timeout)
  File "/usr/lib/python3.8/urllib/request.py", line 531, in open
    response = meth(req, response)
  File "/usr/lib/python3.8/urllib/request.py", line 640, in http_response
    response = self.parent.error(
  File "/usr/lib/python3.8/urllib/request.py", line 569, in error
    return self._call_chain(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 502, in _call_chain
    result = func(*args)
  File "/usr/lib/python3.8/urllib/request.py", line 649, in http_error_default
    raise HTTPError(req.full_url, code, msg, hdrs, fp)
urllib.error.HTTPError: HTTP Error 400:

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "localqueries.py", line 17, in <module>
    go = get_ontology("http://gaurav-HP-Notebook:8000/repositories/semantic").load() # (~ 170 Mb), can take a moment!
  File "/home/gaurav/.local/lib/python3.8/site-packages/owlready2/namespace.py", line 900, in load
    except:  raise OwlReadyOntologyParsingError("Cannot download '%s'!" % f)



Please tell me what wrong I am doing, or there is another way of doing the same.

I got this link (http://gaurav-HP-Notebook:8000/repositories/semantic)   from Graph DB SE version, setup->repositories, and copied the link.


My intention was to connect to Ontologies imported in the localhost Graph DB server and query through python using owlready2 API.
Reply | Threaded
Open this post in threaded view
|

Re: Having problem in loading local Sparql endpoint through get_ontology()

Jiba
Administrator
Hi,

The owlready2.sparql.endpoint module is for opening a SPARQL endpoint receiving connection. It is not for connecting Owlready to an existing SPARQL endpoint. Currently, Owlready required the entire ontology to be imported into its inner SQLite3 database.

I think you should get an RDF / OWL / NT serialization of that ontology, and load it as usual. Then, you can used Owlready for querying the ontology.

Jiba