From da3e0d8c8da1ef6be4c946317157faf2b6928933 Mon Sep 17 00:00:00 2001 From: Jim McCusker Date: Sun, 9 Aug 2015 18:39:08 -0400 Subject: Fixed bnode collision bug. --- rdflib/compare.py | 9 ++++++--- test/test_canonicalization.py | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/rdflib/compare.py b/rdflib/compare.py index 0f93639c..6cb23f85 100644 --- a/rdflib/compare.py +++ b/rdflib/compare.py @@ -204,7 +204,9 @@ class Color: return unicode(x) if isinstance(color, Node): return stringify(color) - value = sum(map(self.hashfunc, ' '.join([stringify(x) for x in color]))) + value = 0 + for triple in color: + value += self.hashfunc(' '.join([stringify(x) for x in triple])) val = u"%x" % value self._hash_cache[color] = val return val @@ -290,7 +292,7 @@ class _TripleCanonicalizer(object): def _individuate(self, color, individual): new_color = list(color.color) - new_color.append((len(color.nodes))) + new_color.append(tuple([len(color.nodes)])) color.nodes.remove(individual) c = Color([individual], self.hashfunc, tuple(new_color), @@ -320,6 +322,7 @@ class _TripleCanonicalizer(object): sequence = sequence[:si] + colors + sequence[si+1:] except ValueError: sequence = colors[1:] + sequence + return coloring @_runtime("to_hash_runtime") @@ -407,7 +410,6 @@ class _TripleCanonicalizer(object): stats['prunings'] += 1 discrete = [x for x in best if self._discrete(x)] if len(discrete) == 0: - very_best = None best_score = None best_depth = None for coloring in best: @@ -434,6 +436,7 @@ class _TripleCanonicalizer(object): if stats is not None: stats['initial_coloring_runtime'] = _total_seconds(datetime.now() - start_coloring) stats['initial_color_count'] = len(coloring) + if not self._discrete(coloring): depth = [0] coloring = self._traces(coloring, stats=stats, depth=depth) diff --git a/test/test_canonicalization.py b/test/test_canonicalization.py index 30fb0bb1..87b5eeaa 100644 --- a/test/test_canonicalization.py +++ b/test/test_canonicalization.py @@ -144,7 +144,9 @@ def negative_graph_match_test(): def fn(rdf1, rdf2, identical): digest1 = get_digest_value(rdf1,"text/turtle") digest2 = get_digest_value(rdf2,"text/turtle") + print rdf1 print digest1 + print rdf2 print digest2 assert (digest1 == digest2) == identical for inputs in testInputs: -- cgit v1.2.1