summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJörn Hees <joernhees@users.noreply.github.com>2015-08-10 19:34:28 +0200
committerJörn Hees <joernhees@users.noreply.github.com>2015-08-10 19:34:28 +0200
commit3e6d754e1ccbcfdaf998a15552f180184231c00f (patch)
tree27f2b77ae3ff6f68f5ec5509cb007684bd4f4549
parent5c806a23a89a92687e82c03958b4a5d178b3c83a (diff)
parentda3e0d8c8da1ef6be4c946317157faf2b6928933 (diff)
downloadrdflib-3e6d754e1ccbcfdaf998a15552f180184231c00f.tar.gz
Merge pull request #506 from jimmccusker/fix_canonicalization
Fixed bnode collision bug, fixes #494
-rw-r--r--rdflib/compare.py9
-rw-r--r--test/test_canonicalization.py2
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: