def test_issue682_signing_named_graphs():
    ns = Namespace("http://love.com#")

    mary = BNode()
    john = URIRef("http://love.com/lovers/john#")

    cmary = URIRef("http://love.com/lovers/mary#")
    cjohn = URIRef("http://love.com/lovers/john#")

    store = Memory()

    g = ConjunctiveGraph(store=store)
    g.bind("love", ns)

    gmary = Graph(store=store, identifier=cmary)

    gmary.add((mary, ns["hasName"], Literal("Mary")))
    gmary.add((mary, ns["loves"], john))

    gjohn = Graph(store=store, identifier=cjohn)
    gjohn.add((john, ns["hasName"], Literal("John")))

    ig = to_isomorphic(g)
    igmary = to_isomorphic(gmary)

    assert len(igmary) == len(gmary)
    assert len(ig) == len(g)
    assert len(igmary) < len(ig)
    assert ig.graph_digest() != igmary.graph_digest()
Example #2
0
    def test_issue_1141_2(self):
        file = b"@prefix : <http://example.com/> . :s :p :o ."
        # with formula
        graph = Graph(store=Memory())
        self.assertTrue(graph.store.formula_aware)
        graph.parse(data=file, format="turtle")
        self.assertEqual(len(graph), 1)

        # without
        graph = Graph(store=SimpleMemory())
        self.assertFalse(graph.store.formula_aware)
        graph.parse(data=file, format="turtle")
        self.assertEqual(len(graph), 1)
Example #3
0
    def test_issue_1141_3(self):
        file = b"<a:> <b:> <c:> ."
        # with contexts
        graph = Graph(store=Memory())
        self.assertTrue(graph.store.context_aware)
        self.assertTrue(graph.store.formula_aware)
        graph.parse(data=file, format="nt")
        self.assertEqual(len(graph), 1)

        # without
        graph = Graph(store=SimpleMemory())
        self.assertFalse(graph.store.context_aware)
        self.assertFalse(graph.store.formula_aware)
        graph.parse(data=file, format="nt")
        self.assertEqual(len(graph), 1)
Example #4
0
    def test_issue_1141_1(self):
        file = b"@prefix : <http://example.com/> . :s :p :o ."

        for format in ("turtle", "trig"):
            # with formula
            graph = Graph()
            self.assertTrue(graph.store.formula_aware)
            graph.parse(data=file, format=format)
            self.assertEqual(len(graph), 1)

            # without
            graph = Graph(store=AuditableStore(Memory()))
            self.assertFalse(graph.store.formula_aware)
            graph.parse(data=file, format=format)
            self.assertEqual(len(graph), 1)
Example #5
0
 def setUp(self):
     self.gcold = gc.isenabled()
     gc.collect()
     gc.disable()
     if self.store is None:
         store = Memory()
     else:
         store = self.store
     self.graph = Graph(store=store)
     self.tempdir = None
     if not self.path:
         self.tempdir = mkdtemp()
         path = pathname2url(self.tempdir)
     else:
         path = self.path
     self.path = path
     self.graph.open(self.path, create=True)
     self.input = Graph()
Example #6
0
from rdflib import Namespace, Literal, URIRef
from rdflib.graph import Graph, ConjunctiveGraph
from rdflib.plugins.stores.memory import Memory

if __name__ == "__main__":

    ns = Namespace("http://love.com#")

    mary = URIRef("http://love.com/lovers/mary")
    john = URIRef("http://love.com/lovers/john")

    cmary = URIRef("http://love.com/lovers/mary")
    cjohn = URIRef("http://love.com/lovers/john")

    store = Memory()

    g = ConjunctiveGraph(store=store)
    g.bind("love", ns)

    # add a graph for Mary's facts to the Conjunctive Graph
    gmary = Graph(store=store, identifier=cmary)
    # Mary's graph only contains the URI of the person she love, not his cute name
    gmary.add((mary, ns["hasName"], Literal("Mary")))
    gmary.add((mary, ns["loves"], john))

    # add a graph for John's facts to the Conjunctive Graph
    gjohn = Graph(store=store, identifier=cjohn)
    # John's graph contains his cute name
    gjohn.add((john, ns["hasCuteName"], Literal("Johnny Boy")))