summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAshley Sommer <ashleysommer@gmail.com>2020-09-18 00:11:27 +1000
committerGitHub <noreply@github.com>2020-09-18 00:11:27 +1000
commit5fb74b4f49baaff4be0cf0019013958debafea8f (patch)
tree269050eb55eba089a29b09f95be0dd20b3fcafa7
parent0ed594eb8ca8a595863c18c4b3065f8f7ca56c01 (diff)
parent328fab19d0bfc4632fc037cc7e0207c893ba5d4c (diff)
downloadrdflib-5fb74b4f49baaff4be0cf0019013958debafea8f.tar.gz
Merge pull request #1142 from Tpt/#1141
N3 parser: do not create formulas if the Turtle mode is activated
-rwxr-xr-xrdflib/plugins/parsers/notation3.py5
-rw-r--r--test/test_issue1141.py27
2 files changed, 30 insertions, 2 deletions
diff --git a/rdflib/plugins/parsers/notation3.py b/rdflib/plugins/parsers/notation3.py
index 742deaf6..9915b1aa 100755
--- a/rdflib/plugins/parsers/notation3.py
+++ b/rdflib/plugins/parsers/notation3.py
@@ -404,7 +404,7 @@ class SinkParser:
else:
self._genPrefix = uniqueURI()
- if openFormula is None:
+ if openFormula is None and not turtle:
if self._thisDoc:
self._formula = store.newFormula(thisDoc + "#_formula")
else:
@@ -1726,6 +1726,7 @@ r_hibyte = re.compile(r"([\x80-\xff])")
class RDFSink(object):
def __init__(self, graph):
self.rootFormula = None
+ self.uuid = uuid4().hex
self.counter = 0
self.graph = graph
@@ -1745,7 +1746,7 @@ class RDFSink(object):
return arg.newBlankNode(uri)
elif isinstance(arg, Graph) or arg is None:
self.counter += 1
- bn = BNode("n" + str(self.counter))
+ bn = BNode("n%sb%s" % (self.uuid, self.counter))
else:
bn = BNode(str(arg[0]).split("#").pop().replace("_", "b"))
return bn
diff --git a/test/test_issue1141.py b/test/test_issue1141.py
new file mode 100644
index 00000000..78940052
--- /dev/null
+++ b/test/test_issue1141.py
@@ -0,0 +1,27 @@
+import unittest
+from io import BytesIO
+
+from rdflib import Graph
+from rdflib.plugins.memory import IOMemory
+from rdflib.plugins.stores.auditable import AuditableStore
+
+
+class TestIssue1141(unittest.TestCase):
+ """
+ Tests is Turtle and TriG parsing works with a store with or without formula support
+ """
+ def test_issue_1141(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.load(BytesIO(file), format=format)
+ self.assertEqual(len(graph), 1)
+
+ # without
+ graph = Graph(store=AuditableStore(IOMemory()))
+ self.assertFalse(graph.store.formula_aware)
+ graph.load(BytesIO(file), format=format)
+ self.assertEqual(len(graph), 1)