[Matrix] Matched() return index and value, as tuples
authorSimon Chabot <simon.chabot@logilab.fr>
Fri, 19 Oct 2012 11:21:44 +0200
changeset 30 6b2b4a8d5ff7
parent 29 5b1f828f36c6
child 31 1410ccfe08fd
[Matrix] Matched() return index and value, as tuples
matrix.py
test/test_alignment.py
--- a/matrix.py	Fri Oct 19 10:46:14 2012 +0200
+++ b/matrix.py	Fri Oct 19 11:21:44 2012 +0200
@@ -68,10 +68,10 @@
         allindexes = (zip(xrange(size[0]), xrange(size[1])))
         zeros = [index for index in allindexes if index not in rowcol]
         for (i, j) in zeros:
-            match[i].append(j)
+            match[i].append((j, 0))
 
         if cutoff > 0: #If more is wanted, return it too
             for (i, j) in rowcol:
                 if self._matrix[i, j] <= cutoff:
-                    match[i].append(j)
+                    match[i].append((j, self._matrix[i, j]))
         return match
--- a/test/test_alignment.py	Fri Oct 19 10:46:14 2012 +0200
+++ b/test/test_alignment.py	Fri Oct 19 11:21:44 2012 +0200
@@ -193,12 +193,13 @@
 
         #Only the element 1 of input1 has *exactly* matched with the element 1
         #of input2
-        self.assertEqual(m.matched(), {1: [1]})
+        self.assertEqual(m.matched(), {1: [(1, 0)]})
 
         #Victor Hugo --> Victor Wugo
         #Albert Camus --> Albert Camus, Albert Camu
         self.assertEqual(m.matched(cutoff = 0.1, normalized = True),
-                        {0: [0], 1: [1, 2]})
+                        {0: [(0, d(i1[0], i2[0]))], 1: [(1, d(i1[1], i2[1])), 
+                                                       (2, d(i1[1], i2[2]))]})
 
 
 if __name__ == '__main__':