1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
import os
from rdflib import Graph, URIRef
from rdflib.namespace import FOAF
from rdflib.plugins.sparql import prepareQuery, prepareUpdate
def test_prepare_update():
q = prepareUpdate(
"""\
PREFIX dc: <http://purl.org/dc/elements/1.1/>
INSERT DATA
{ <http://example/book3> dc:title "A new book" ;
dc:creator "A.N.Other" .
} ;
""",
initNs={},
)
g = Graph()
g.update(q, initBindings={})
assert len(g) == 2
def test_prepare_query():
q = prepareQuery(
"SELECT ?name WHERE { ?person foaf:knows/foaf:name ?name . }",
initNs={"foaf": FOAF},
)
g = Graph()
g.parse(
location=os.path.join(
os.path.dirname(__file__), "..", "..", "examples", "foaf.n3"
),
format="n3",
)
tim = URIRef("http://www.w3.org/People/Berners-Lee/card#i")
assert len(list(g.query(q, initBindings={"person": tim}))) == 50
|