Skip to content

Commit

Permalink
Add SERVICE usage example to SPARQL intro page
Browse files Browse the repository at this point in the history
  • Loading branch information
dwinston committed May 6, 2020
1 parent 67a47f3 commit e2d6dae
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions docs/intro_to_sparql.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
^^^^^^^^^^^^^^^^

Expand Down

0 comments on commit e2d6dae

Please sign in to comment.