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 graphs.

Fixes:
- RDFLib#1807
- RDFLib#1701
  • Loading branch information
aucampia committed Apr 23, 2022
1 parent 02dd2bf commit 8068241
Show file tree
Hide file tree
Showing 6 changed files with 490 additions and 163 deletions.
33 changes: 3 additions & 30 deletions rdflib/plugins/serializers/n3.py
Original file line number Diff line number Diff line change
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.

Loading

0 comments on commit 8068241

Please sign in to comment.