Can I load a URI from the tool Allegrograph?

11 views
Skip to first unread message

stephen...@gmail.com

unread,
Feb 20, 2019, 1:36:29 PM2/20/19
to rdflib-dev
Hi I have been trying to run the following script and have not succeeded with loading the URI successfully. Does anyone know the issue + solution to this problem? This is the following script:


import rdflib
g = rdflib.Graph()
g.load("http://169.36.179.223:10035/repositories/cso_core_collector-20190124")

qres = g.query(
"""SELECT ?class
WHERE {
?s rdf:type ?class
} GROUP BY ?class"""
)

for row in qres:
print(row)

Richard Dijkstra

unread,
Mar 3, 2019, 2:56:04 PM3/3/19
to rdflib-dev
Stephen,

You should use SPARQLwrapper for querying a remote sparql end-point: https://rdflib.github.io/sparqlwrapper/

The following code will run:

from SPARQLWrapper import SPARQLWrapper, JSON

sparql = SPARQLWrapper("http://dbpedia.org/sparql")
sparql.setQuery("""
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    SELECT ?label
    WHERE { <http://dbpedia.org/resource/Asturias> rdfs:label ?label }
""")
sparql.setReturnFormat(JSON)
results = sparql.query().convert()

for result in results["results"]["bindings"]:
    print(result["label"]["value"])

Trying this code with your address does not give a response.
Hope this helps.

Richard
Reply all
Reply to author
Forward
0 new messages