File: test_issue733.py

package info (click to toggle)
rdflib 7.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 77,852 kB
  • sloc: python: 59,555; sh: 153; makefile: 83; ruby: 74; xml: 45
file content (69 lines) | stat: -rw-r--r-- 1,952 bytes parent folder | download | duplicates (2)
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
"""
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 Graph
from test.utils.namespace import EGDO


def test_issue_733():
    g = Graph()
    g.add((EGDO.S, EGDO.P, EGDO.O1))
    g.add((EGDO.S, EGDO.P, EGDO.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():
    g = Graph()
    g.add((EGDO.S, EGDO.P, EGDO.O1))
    g.add((EGDO.S, EGDO.P, EGDO.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