Skip to content

Commit

Permalink
fix: two issues with the N3 serializer
Browse files Browse the repository at this point in the history
This patch fixes two issues with the N3 serializer:
- The N3 serializer incorrectly considered a subject as already
  serialized if it has been serialized inside a quoted graph.
- The N3 serializer does not consider that the predicate of
  a triple can also be a graph.

Other changes included in this patch:
- Changed `test.testutils.GraphHelper` to support nested/quoted graphs.
- Moved the tests from `test/test_n3_formula.py` into
  `test/test_serializers/test_serializer_n3.py`.
- Include positive syntax tests from the N3 test suite that is smaller
  than 1024KB and that is not using new N3 syntax into round trip tests.
  This is mainly to check that there is no regressions after the changes
  made.

Fixes:
- #1807
- #1701
  • Loading branch information
aucampia committed May 16, 2022
1 parent 06a4395 commit b4f779b
Show file tree
Hide file tree
Showing 6 changed files with 507 additions and 152 deletions.
33 changes: 3 additions & 30 deletions rdflib/plugins/serializers/n3.py
Expand Up @@ -23,36 +23,6 @@ def reset(self):
super(N3Serializer, self).reset()
self._stores = {}

def subjectDone(self, subject):
super(N3Serializer, self).subjectDone(subject)
if self.parent:
self.parent.subjectDone(subject)

def isDone(self, subject):
return super(N3Serializer, self).isDone(subject) and (
not self.parent or self.parent.isDone(subject)
)

def startDocument(self):
super(N3Serializer, self).startDocument()
# if not isinstance(self.store, N3Store):
# return
#
# all_list = [self.label(var) for var in
# self.store.get_universals(recurse=False)]
# all_list.sort()
# some_list = [self.label(var) for var in
# self.store.get_existentials(recurse=False)]
# some_list.sort()
#
# for var in all_list:
# self.write('\n'+self.indent()+'@forAll %s. '%var)
# for var in some_list:
# self.write('\n'+self.indent()+'@forSome %s. '%var)
#
# if (len(all_list) + len(some_list)) > 0:
# self.write('\n')

def endDocument(self):
if not self.parent:
super(N3Serializer, self).endDocument()
Expand All @@ -68,6 +38,9 @@ def preprocessTriple(self, triple):
if isinstance(triple[0], Graph):
for t in triple[0]:
self.preprocessTriple(t)
if isinstance(triple[1], Graph):
for t in triple[1]:
self.preprocessTriple(t)
if isinstance(triple[2], Graph):
for t in triple[2]:
self.preprocessTriple(t)
Expand Down
57 changes: 0 additions & 57 deletions test/test_n3_formula.py

This file was deleted.

0 comments on commit b4f779b

Please sign in to comment.