diff options
author | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-04-24 23:05:06 +1000 |
---|---|---|
committer | Nicholas Car <nicholas.car@surroundaustralia.com> | 2021-04-24 23:05:06 +1000 |
commit | 57e180b4ca1f074c3ab08ff6ff8ef09ed143de58 (patch) | |
tree | d031c970da1e5d30c93b2f891e90204eaea65b6d | |
parent | 554e5cdf07737a78806d4b32983ce1c28326fba9 (diff) | |
download | rdflib-57e180b4ca1f074c3ab08ff6ff8ef09ed143de58.tar.gz |
Python 3 syntax, rdflib 5+ namespacing
-rw-r--r-- | examples/custom_eval.py | 19 |
1 files changed, 14 insertions, 5 deletions
diff --git a/examples/custom_eval.py b/examples/custom_eval.py index 74c393a4..21e46a40 100644 --- a/examples/custom_eval.py +++ b/examples/custom_eval.py @@ -19,9 +19,9 @@ i.e. in your setup.py:: import rdflib from rdflib.plugins.sparql.evaluate import evalBGP -from rdflib.namespace import FOAF +from rdflib.namespace import FOAF, RDFS -inferredSubClass = rdflib.RDFS.subClassOf * "*" # any number of rdfs.subClassOf +inferredSubClass = RDFS.subClassOf * "*" # any number of rdfs.subClassOf def customEval(ctx, part): @@ -53,11 +53,20 @@ if __name__ == "__main__": rdflib.plugins.sparql.CUSTOM_EVALS["exampleEval"] = customEval g = rdflib.Graph() - g.load("foaf.n3") + g.parse("foaf.n3") # Add the subClassStmt so that we can query for it! - g.add((FOAF.Person, rdflib.RDFS.subClassOf, FOAF.Agent)) + g.add((FOAF.Person, RDFS.subClassOf, FOAF.Agent)) # Find all FOAF Agents - for x in g.query("PREFIX foaf: <%s> SELECT * WHERE { ?s a foaf:Agent . }" % FOAF): + for x in g.query( + f""" + PREFIX foaf: <{FOAF}> + + SELECT * + WHERE {{ + ?s a foaf:Agent . + }} + """ + ): print(x) |