def test_lev6(self): 
        for t in TEXTS:
            s1, s2 = t[0], t[1]
       
            m1 = DistanceMatrix(def_value = 111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m1)
         
            m2 = UprightDistanceMatrix(def_value = 111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m2)
            
            m3 = HybridSubsetDistanceMatrix(def_value = 111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m3)
        
            m4 = UprightSubsetDistanceMatrix(7, def_value = 111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m4)

            m5 = fLevDistanceDiag(3).matrix(s1, s2, def_value = 111)

            m6 = c_lev_distance.fLevDistanceDiag(3).matrix(s1, s2, def_value = 111)

            self.assertEqual(m1, m2)        
            self.assertEqual(m2, m3)        
            self.assertEqual(m3, m4)        
            self.assertEqual(m4, m5)        
            self.assertEqual(m5, m6)        
Exemple #2
0
    def test_lev6(self):
        for t in TEXTS:
            s1, s2 = t[0], t[1]

            m1 = DistanceMatrix(def_value=111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m1)

            m2 = UprightDistanceMatrix(def_value=111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m2)

            m3 = HybridSubsetDistanceMatrix(def_value=111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m3)

            m4 = UprightSubsetDistanceMatrix(7, def_value=111)
            fLevDistanceDiag(3).fill_matrix(s1, s2, m4)

            m5 = fLevDistanceDiag(3).matrix(s1, s2, def_value=111)

            m6 = c_lev_distance.fLevDistanceDiag(3).matrix(s1,
                                                           s2,
                                                           def_value=111)

            self.assertEqual(m1, m2)
            self.assertEqual(m2, m3)
            self.assertEqual(m3, m4)
            self.assertEqual(m4, m5)
            self.assertEqual(m5, m6)
    def test_lev3(self): 
        for t in TEXTS:
            s1, s2 = t[0], t[1]

            d = fClassicalLevDistance()(s1, s2)
        
            m1 = DistanceMatrix()
            fClassicalLevDistance().fill_matrix(s1, s2, m1)
         
            m2 = DistanceMatrix()
            fLevDistance().fill_matrix(s1, s2, m2)
         
            m3 = DistanceMatrix()
            fLevDistance2().fill_matrix(s1, s2, m3)
         
            m4 = DistanceMatrix(111)
            fLevDistanceDiag(len(s1) - 1).fill_matrix(s1, s2, m4)
         
            m5 = fLevDistanceDiag(len(s1) - 1).matrix(s1, s2)
            
            # C-code
            m6 = c_lev_distance.fLevDistance().matrix(s1, s2)       
           
            m6_1 = DistanceMatrix()
            c_lev_distance.fLevDistance().fill_matrix(s1, s2, m6_1)
            m7 = c_lev_distance.fLevDistanceDiag(len(s1) - 1).matrix(s1, s2)
            
            m7_1 = DistanceMatrix(def_value = 111)
            c_lev_distance.fLevDistanceDiag(len(s1) - 1).fill_matrix(s1, s2, m7_1)

            
            self.assertEqual(m1, m2)        
            self.assertEqual(m2, m3)        
            self.assertEqual(m3, m4)        
            self.assertEqual(m4, m5)        
            self.assertEqual(m5, m6)        
            self.assertEqual(m6, m7)        
            self.assertEqual(m6, m6_1)        
            self.assertEqual(m7, m7_1)        


            # test C and Python diagonal 
            m8 = c_lev_distance.fLevDistanceDiag(2).matrix(s1, s2)
            m9 = fLevDistanceDiag(2).matrix(s1, s2)
            self.assertEqual(m6, m7) 
    def test_lev2(self): 
        for t in TEXTS:
            s1, s2 = t[0], t[1]

            d = fClassicalLevDistance()(s1, s2)
            self.assertEqual(fLevDistance()(s1, s2) , d)        
            self.assertEqual(fLevDistance2()(s1, s2) , d)       
            
            # C-code             
            self.assertEqual(c_lev_distance.fLevDistance()(s1, s2) , d)        
            self.assertEqual(c_lev_distance.fLevDistanceDiag(len(s1))(s1, s2) , d)        
           
            # diagonal levenshtein
            self.assertEqual(fLevDistanceDiag(len(s1))(s1, s2) , d)        
            
            # test diag bounds handling
            self.assertEqual(fLevDistanceDiag(10*len(s1))(s1, s2) , d)        
            self.assertEqual(c_lev_distance.fLevDistanceDiag(10*len(s1))(s1, s2) , d)        
Exemple #5
0
    def test_lev3(self):
        for t in TEXTS:
            s1, s2 = t[0], t[1]

            d = fClassicalLevDistance()(s1, s2)

            m1 = DistanceMatrix()
            fClassicalLevDistance().fill_matrix(s1, s2, m1)

            m2 = DistanceMatrix()
            fLevDistance().fill_matrix(s1, s2, m2)

            m3 = DistanceMatrix()
            fLevDistance2().fill_matrix(s1, s2, m3)

            m4 = DistanceMatrix(111)
            fLevDistanceDiag(len(s1) - 1).fill_matrix(s1, s2, m4)

            m5 = fLevDistanceDiag(len(s1) - 1).matrix(s1, s2)

            # C-code
            m6 = c_lev_distance.fLevDistance().matrix(s1, s2)

            m6_1 = DistanceMatrix()
            c_lev_distance.fLevDistance().fill_matrix(s1, s2, m6_1)
            m7 = c_lev_distance.fLevDistanceDiag(len(s1) - 1).matrix(s1, s2)

            m7_1 = DistanceMatrix(def_value=111)
            c_lev_distance.fLevDistanceDiag(len(s1) - 1).fill_matrix(
                s1, s2, m7_1)

            self.assertEqual(m1, m2)
            self.assertEqual(m2, m3)
            self.assertEqual(m3, m4)
            self.assertEqual(m4, m5)
            self.assertEqual(m5, m6)
            self.assertEqual(m6, m7)
            self.assertEqual(m6, m6_1)
            self.assertEqual(m7, m7_1)

            # test C and Python diagonal
            m8 = c_lev_distance.fLevDistanceDiag(2).matrix(s1, s2)
            m9 = fLevDistanceDiag(2).matrix(s1, s2)
            self.assertEqual(m6, m7)
Exemple #6
0
    def test_lev2(self):
        for t in TEXTS:
            s1, s2 = t[0], t[1]

            d = fClassicalLevDistance()(s1, s2)
            self.assertEqual(fLevDistance()(s1, s2), d)
            self.assertEqual(fLevDistance2()(s1, s2), d)

            # C-code
            self.assertEqual(c_lev_distance.fLevDistance()(s1, s2), d)
            self.assertEqual(
                c_lev_distance.fLevDistanceDiag(len(s1))(s1, s2), d)

            # diagonal levenshtein
            self.assertEqual(fLevDistanceDiag(len(s1))(s1, s2), d)

            # test diag bounds handling
            self.assertEqual(fLevDistanceDiag(10 * len(s1))(s1, s2), d)
            self.assertEqual(
                c_lev_distance.fLevDistanceDiag(10 * len(s1))(s1, s2), d)
Exemple #7
0
    def test_lev1(self):
        s1 = s2 = "abcdef gk lmn"
        self.assertEqual(fLevDistance()(s1, s2), 0)
        self.assertEqual(fLevDistance2()(s1, s2), 0)
        self.assertEqual(fClassicalLevDistance()(s1, s2), 0)
        self.assertEqual(fLevDistanceDiag()(s1, s2), 0)

        # C code testing
        self.assertEqual(c_lev_distance.fLevDistance()(s1, s2), 0)
        self.assertEqual(c_lev_distance.fLevDistanceDiag()(s1, s2), 0)

        # unicode strings (contains Greek characters)
        s1 = s2 = u"abcdef \u03A0 gk \u03A3 lmn \u03A9"
        self.assertEqual(c_lev_distance.fLevDistance()(s1, s2), 0)
        self.assertEqual(c_lev_distance.fLevDistanceDiag()(s1, s2), 0)
 def test_lev1(self): 
     s1 = s2 = "abcdef gk lmn"
     self.assertEqual(fLevDistance()(s1, s2) , 0)        
     self.assertEqual(fLevDistance2()(s1, s2) , 0)        
     self.assertEqual(fClassicalLevDistance()(s1, s2) , 0)        
     self.assertEqual(fLevDistanceDiag()(s1, s2) , 0)        
    
     # C code testing  
     self.assertEqual(c_lev_distance.fLevDistance()(s1, s2) , 0)        
     self.assertEqual(c_lev_distance.fLevDistanceDiag()(s1, s2) , 0)        
     
     # unicode strings (contains Greek characters)
     s1 = s2 = u"abcdef \u03A0 gk \u03A3 lmn \u03A9"
     self.assertEqual(c_lev_distance.fLevDistance()(s1, s2) , 0)        
     self.assertEqual(c_lev_distance.fLevDistanceDiag()(s1, s2) , 0)        
Exemple #9
0
from gravity.tae.match import lev_distance
from gravity.tae import distance
from gravity.tae.match.c_lev_distance import fLevDistanceDiag
from gravity.tae.match.c_lev_distance import fLevPath

s1 = "Test Den   Haag entity"
s2 = "Test Den Haag entity"
m1 = fLevDistanceDiag(2).matrix(s1, s2, 111)
print m1.toString(s1, s2)

m2 = lev_distance.fLevDistanceDiag(2).matrix(s1, s2, 111)
print m2.toString(s1, s2)
print m1 == m2

p1_1 = fLevPath()(m1)
p1_2 = fLevPath()(m2)
print p1_1
print p1_2

p2_1 = lev_distance.fLevPath()(m1)
p2_2 = lev_distance.fLevPath()(m2)
print p2_1
print p2_2

print m2.toString(s1, s2, p1_2)

assert m1 == m2
assert p1_1 == p1_2 and p1_2 == p2_1 and p2_1 == p2_2

##    01234567890123456
s1 = "Test  amsterdamm    entity"
Exemple #10
0
from gravity.tae.match import lev_distance 
from gravity.tae import distance
from gravity.tae.match.c_lev_distance import fLevDistanceDiag
from gravity.tae.match.c_lev_distance import fLevPath


s1 = "Test Den   Haag entity"
s2 = "Test Den Haag entity"
m1 = fLevDistanceDiag(2).matrix(s1, s2, 111)
print m1.toString(s1, s2)

m2 = lev_distance.fLevDistanceDiag(2).matrix(s1, s2, 111)
print m2.toString(s1, s2)
print m1 == m2


p1_1 = fLevPath()(m1)
p1_2 = fLevPath()(m2)
print p1_1
print p1_2


p2_1 = lev_distance.fLevPath()(m1)
p2_2 = lev_distance.fLevPath()(m2)
print p2_1
print p2_2


print m2.toString(s1, s2, p1_2)

assert m1 == m2