[Matrix] Matrices are not symetric. Correct it
authorSimon Chabot <simon.chabot@logilab.fr>
Fri, 19 Oct 2012 16:58:27 +0200
changeset 28 d9c1ef721418
parent 27 f03d58d3c7f3
child 29 5b1f828f36c6
[Matrix] Matrices are not symetric. Correct it
matrix.py
test/test_alignment.py
--- a/matrix.py	Fri Oct 19 10:06:50 2012 +0200
+++ b/matrix.py	Fri Oct 19 16:58:27 2012 +0200
@@ -47,18 +47,13 @@
 
     def _compute(self):
        for i in xrange(len(self.input1)):
-           # The matrix is an upper triangular one, so don't compute the
-           # bottom
-           for j in xrange(i, len(self.input2)):
+           for j in xrange(len(self.input2)):
                self._matrix[i,j] = self.distance(self.input1[i], self.input2[j])
                if self._matrix[i,j] > self._maxdist:
                    self._maxdist = self._matrix[i,j]
 
     def __getitem__(self, index):
-        (i, j) = index
-        if i <= j:
-            return self._matrix[index]
-        return self._matrix[j, i]
+        return self._matrix[index]
 
     def matched(self, cutoff = 0, normalized = False):
         match = defaultdict(list)
--- a/test/test_alignment.py	Fri Oct 19 10:06:50 2012 +0200
+++ b/test/test_alignment.py	Fri Oct 19 16:58:27 2012 +0200
@@ -174,7 +174,7 @@
     def setUp(self):
         self.input1 = [u'Victor Hugo', u'Albert Camus', 'Jean Valjean']
         self.input2 = [u'Victor Wugo', u'Albert Camus', 'Albert Camu']
-        self.distance = jaccard
+        self.distance = levenshtein
         self.matrix = Distancematrix(self.input1, self.input2, self.distance)
 
     def test_matrixconstruction(self):
@@ -195,7 +195,8 @@
         #of input2
         self.assertEqual(m.matched(), {1: [1]})
 
-        #Everything partially matched, except Jean Valjean
+        #Victor Hugo --> Victor Wugo
+        #Albert Camus --> Albert Camus, Albert Camu
         self.assertEqual(m.matched(cutoff = 0.1, normalized = True),
                         {0: [0], 1: [1, 2]})