diff options
| author | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-04-25 19:27:53 +1000 |
|---|---|---|
| committer | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-04-25 19:27:53 +1000 |
| commit | 86351aca27e9bd8bc08039bf254b4cb92f3eefb3 (patch) | |
| tree | 80ba722b48b02d3b0d026314784a35a01972c2cb | |
| parent | dfd700ecfa52b0cc8a04e6102111967b807fc924 (diff) | |
| download | rdflib-86351aca27e9bd8bc08039bf254b4cb92f3eefb3.tar.gz | |
load() --> parse()
| -rw-r--r-- | examples/prepared_query.py | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/examples/prepared_query.py b/examples/prepared_query.py index 95912e59..d8b83466 100644 --- a/examples/prepared_query.py +++ b/examples/prepared_query.py @@ -2,6 +2,8 @@ SPARQL Queries be prepared (i.e parsed and translated to SPARQL algebra) by the :meth:`rdflib.plugins.sparql.prepareQuery` method. +``initNs`` can be used instead of PREFIX values. + When executing, variables can be bound with the ``initBindings`` keyword parameter """ @@ -10,16 +12,18 @@ import rdflib from rdflib.plugins.sparql import prepareQuery from rdflib.namespace import FOAF + if __name__ == "__main__": q = prepareQuery( - "SELECT ?s WHERE { ?person foaf:knows ?s .}", initNs={"foaf": FOAF} + "SELECT ?name WHERE { ?person foaf:knows/foaf:name ?name . }", + initNs={"foaf": FOAF} ) g = rdflib.Graph() - g.load("foaf.n3", format="n3") + g.parse("foaf.n3") tim = rdflib.URIRef("http://www.w3.org/People/Berners-Lee/card#i") for row in g.query(q, initBindings={"person": tim}): - print(row) + print(row.name) |
