diff options
author | Donny Winston <dwinston@alum.mit.edu> | 2020-05-06 18:20:59 -0400 |
---|---|---|
committer | Donny Winston <dwinston@alum.mit.edu> | 2020-05-06 18:20:59 -0400 |
commit | e2d6dae0020000d26e7e31c9161730c04505ce6e (patch) | |
tree | 55248a4e57eb7e9c4d7513a3924d87845d8d044c /docs | |
parent | 67a47f3b6cc87c827d50ad67a6d9384b29b028ed (diff) | |
download | rdflib-e2d6dae0020000d26e7e31c9161730c04505ce6e.tar.gz |
Add SERVICE usage example to SPARQL intro page
Diffstat (limited to 'docs')
-rw-r--r-- | docs/intro_to_sparql.rst | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/docs/intro_to_sparql.rst b/docs/intro_to_sparql.rst index 5ab34287..97c7f281 100644 --- a/docs/intro_to_sparql.rst +++ b/docs/intro_to_sparql.rst @@ -71,6 +71,35 @@ Variables can also be pre-bound, using ``initBindings`` kwarg can be used to pass in a ``dict`` of initial bindings, this is particularly useful for prepared queries, as described below. +Query a Remote Service +^^^^^^^^^^^^^^^^^^^^^^ + +The SERVICE keyword of SPARQL 1.1 can send a query to a remote SPARQL endpoint. + +.. code-block:: python + + import rdflib + + g = rdflib.Graph() + qres = g.query(''' + SELECT ?s + WHERE { + SERVICE <http://dbpedia.org/sparql> { + ?s <http://purl.org/linguistics/gold/hypernym> <http://dbpedia.org/resource/Leveller> . + } + } LIMIT 3''') + for row in qres: + print(row.s) + +This example sends a query to `DBPedia +<https://dbpedia.org/>`_'s SPARQL endpoint service so that it can run the query and then send back the result: + +.. code-block:: text + + http://dbpedia.org/resource/Elizabeth_Lilburne + http://dbpedia.org/resource/Thomas_Prince_(Leveller) + http://dbpedia.org/resource/John_Lilburne + Prepared Queries ^^^^^^^^^^^^^^^^ |