File: test_issue1404.py

package info (click to toggle)
rdflib 6.1.1-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 38,248 kB
  • sloc: python: 39,216; sh: 153; makefile: 110
file content (42 lines) | stat: -rw-r--r-- 1,342 bytes parent folder | download
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
from rdflib import Graph, URIRef, FOAF
from rdflib.term import RDFLibGenid
from rdflib.compare import isomorphic


def test_skolem_de_skolem_roundtrip():
    """Test round-trip of skolemization/de-skolemization of data.

    Issue: https://github.com/RDFLib/rdflib/issues/1404
    """

    ttl = '''
    @prefix wd: <http://www.wikidata.org/entity/> .
    @prefix foaf: <http://xmlns.com/foaf/0.1/> .

    wd:Q1203 foaf:knows [ a foaf:Person;
        foaf:name "Ringo" ].
    '''

    graph = Graph()
    graph.parse(data=ttl, format='turtle')

    query = {"subject": URIRef("http://www.wikidata.org/entity/Q1203"), "predicate": FOAF.knows}

    # Save the original bnode id.
    bnode_id = graph.value(**query)

    skolemized_graph = graph.skolemize()

    # Check the BNode is now an RDFLibGenid after skolemization.
    skolem_bnode = skolemized_graph.value(**query)
    assert type(skolem_bnode) == RDFLibGenid

    # Check that the original bnode id exists somewhere in the uri.
    assert bnode_id in skolem_bnode

    # Check that the original data is not isomorphic with the skolemized data.
    assert not isomorphic(graph, skolemized_graph)

    # Check that the original graph data is the same as the de-skolemized data.
    de_skolemized_graph = skolemized_graph.de_skolemize()
    assert isomorphic(graph, de_skolemized_graph)