Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

attempt to fix #633 #634

Merged
merged 1 commit into from
Jan 12, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
attempt to fix #633
  • Loading branch information
pchampin committed May 15, 2016
commit 70916a2d4aad6abbf3b90dad289d3eca9d70198e
6 changes: 4 additions & 2 deletions rdflib/plugins/sparql/evaluate.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,10 @@ def evalLeftJoin(ctx, join):
# before we yield a solution without the OPTIONAL part
# check that we would have had no OPTIONAL matches
# even without prior bindings...
if not any(_ebv(join.expr, b) for b in
evalPart(ctx.thaw(a.remember(join.p1._vars)), join.p2)):
p1_vars = join.p1._vars
if p1_vars is None \
or not any(_ebv(join.expr, b) for b in
evalPart(ctx.thaw(a.remember(p1_vars)), join.p2)):

yield a

Expand Down
71 changes: 71 additions & 0 deletions test-update.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
from rdflib import *

ex = Namespace('http://ex.co/')
g = Graph()
g.namespace_manager.bind('', ex)

g.add((ex.s1, ex.p, ex.o1))
g.add((ex.s1, ex.p, ex.o2))
g.add((ex.s1, ex.p, ex.o3))

g.add((ex.s2, ex.p, ex.o2))
g.add((ex.s2, ex.p, ex.o3))
g.add((ex.s2, ex.p, ex.o4))
g.add((ex.s2, ex.p, ex.o5))

g.add((ex.s3, ex.p, ex.o1))
g.add((ex.s3, ex.p, ex.o3))
g.add((ex.s3, ex.p, ex.o5))


print(g.serialize(format="n3"))

# should be
# :s1 :p :o1, :o2, :o3 .
# :s2 :p :o2, :o3, :o4, :o5 .
# :s3 :p :o1, :o3, :o5 .

print '---'

print(g.query("""
PREFIX : <http://ex.co/>

SELECT ?o ?new
WHERE {
:s1 :p ?o .
:s2 :p ?o .
OPTIONAL {
:s3 :p ?o .
BIND(:s4 as ?new)
}
}
""").serialize(format="csv"))

# should be
# :o2 ,
# :o3 , :s4

print '---'

g.update("""
PREFIX : <http://ex.co/>

DELETE { :s1 :p ?o }
INSERT { ?new :p ?o }
WHERE {
:s1 :p ?o .
:s2 :p ?o .
OPTIONAL {
:s3 :p ?o .
BIND(:s4 as ?new)
}
}
""")

print(g.serialize(format="n3"))

# should now be
# :s1 :p :o1 .
# :s2 :p :o2, :o3, :o4, :o5 .
# :s3 :p :o1, :o3, :o5 .
# :s4 :p :o3 .