forked from RDFLib/rdflib
-
Notifications
You must be signed in to change notification settings - Fork 1
/
test_issue733.py
77 lines (70 loc) · 2.37 KB
/
test_issue733.py
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
"""
Issue 715 - path query chaining issue
Some incorrect matches were found when using oneOrMore ('+') and
zeroOrMore ('*') property paths and specifying neither the
subject or the object.
"""
from rdflib import URIRef, Graph
import unittest
from rdflib.namespace import RDF, RDFS, NamespaceManager, Namespace
class TestIssue733(unittest.TestCase):
def test_issue_733(self):
g = Graph()
example = Namespace("http://example.org/")
g.add((example.S, example.P, example.O1))
g.add((example.S, example.P, example.O2))
q = """
prefix ex:<http://example.org/>
select ?lexical_or_value ?ot ?gt where {
{SELECT (count(*) as ?lexical_or_value) where {
?s ?p ?o .
FILTER (?s=ex:S)
}}
{SELECT (count(*) as ?ot) where {
?s ?p ?o .
FILTER (?o=ex:O1)
}}
{SELECT (count(*) as ?gt) where {
?s ?p ?o .
FILTER (?o!=ex:O1 && ?s!=ex:O2)
}}
}
"""
res = g.query(q)
assert len(res) == 1
results = [[lit.toPython() for lit in line] for line in res]
assert results[0][0] == 2
assert results[0][1] == 1
assert results[0][2] == 1
def test_issue_733_independant(self):
g = Graph()
example = Namespace("http://example.org/")
g.add((example.S, example.P, example.O1))
g.add((example.S, example.P, example.O2))
q = """
prefix ex:<http://example.org/>
select ?lexical_or_value where {
{SELECT (count(*) as ?lexical_or_value) where {
?s ?p ?o .
FILTER (?s=ex:S)
}}
}
"""
res = g.query(q)
assert len(res) == 1
results = [[lit.toPython() for lit in line] for line in res]
assert results[0][0] == 2
q = """
prefix ex:<http://example.org/>
select ?lexical_or_value where {
{SELECT (count(*) as ?lexical_or_value) where {
?s ?p ?o .
FILTER (?o=ex:O1)
}}
}
"""
res = g.query(q)
results = [[lit.toPython() for lit in line] for line in res]
assert results[0][0] == 1
if __name__ == "__main__":
unittest.main()