def testJaro(
            self):  # - - - - - - - - - - - - - - - - - - - - - - - - - - -
        """Test 'Jaro' approximate string comparator"""

        for pair in self.string_pairs:

            approx_str_value = stringcmp.jaro(pair[0], pair[1])

            assert (isinstance(approx_str_value,float)), \
                   '"Jaro" does not return a floating point number for: '+str(pair)

            assert (approx_str_value >= 0.0), \
                   '"Jaro" returns a negative number for: '+str(pair)

            assert (approx_str_value <= 1.0), \
                   '"Jaro" returns a number larger than 1.0 for: '+str(pair)

            approx_str_value_1 = stringcmp.jaro(pair[0], pair[1])
            approx_str_value_2 = stringcmp.jaro(pair[1], pair[0])

            assert (approx_str_value_1 == approx_str_value_2), \
                   '"Jaro" returns different values for pair and swapped pair: '+ \
                   str(pair)+': '+str(approx_str_value_1)+', '+ \
                   str(approx_str_value_2)

            # Check for value 1.0 if the strings are the same
            #
            if (pair[0] == pair[1]):

                assert (approx_str_value == 1.0), \
                       '"Jaro" does not return 1.0 if strings are equal: '+str(pair)
예제 #2
0
  def testJaro(self):   # - - - - - - - - - - - - - - - - - - - - - - - - - - -
    """Test 'Jaro' approximate string comparator"""

    for pair in self.string_pairs:

      approx_str_value = stringcmp.jaro(pair[0],pair[1])

      assert (isinstance(approx_str_value,float)), \
             '"Jaro" does not return a floating point number for: '+str(pair)

      assert (approx_str_value >= 0.0), \
             '"Jaro" returns a negative number for: '+str(pair)

      assert (approx_str_value <= 1.0), \
             '"Jaro" returns a number larger than 1.0 for: '+str(pair)

      approx_str_value_1 = stringcmp.jaro(pair[0],pair[1])
      approx_str_value_2 = stringcmp.jaro(pair[1],pair[0])

      assert (approx_str_value_1 == approx_str_value_2), \
             '"Jaro" returns different values for pair and swapped pair: '+ \
             str(pair)+': '+str(approx_str_value_1)+', '+ \
             str(approx_str_value_2)

      # Check for value 1.0 if the strings are the same
      #
      if (pair[0] == pair[1]):

        assert (approx_str_value == 1.0), \
               '"Jaro" does not return 1.0 if strings are equal: '+str(pair)
예제 #3
0
    def testWinkler(
            self):  # - - - - - - - - - - - - - - - - - - - - - - - - - -
        """Test 'Winkler' approximate string comparator"""

        for pair in self.string_pairs:

            approx_str_value = stringcmp.winkler(pair[0], pair[1])

            assert isinstance(
                approx_str_value, float
            ), '"Winkler" does not return a floating point number for:' + str(
                pair)

            assert (approx_str_value >= 0.0
                    ), '"Winkler" returns a negative number for:' + str(pair)

            assert (
                approx_str_value <= 1.0
            ), '"Winkler" returns a number larger than 1.0 for:' + str(pair)

            approx_str_value_1 = stringcmp.winkler(pair[0], pair[1])
            approx_str_value_2 = stringcmp.winkler(pair[1], pair[0])

            assert approx_str_value_1 == approx_str_value_2, (
                '"Winkler" returns different values for pair and swapped ' +
                "pair: " + str(pair) + ": " + str(approx_str_value_1) + ", " +
                str(approx_str_value_2))

            # Check for value 1.0 if the strings are the same
            #
            if pair[0] == pair[1]:

                assert (
                    approx_str_value == 1.0
                ), '"Winkler" does not return 1.0 if strings are equal: ' + str(
                    pair)

            # Winkler should always return a value equal to or larger than Jaro
            #
            approx_str_value_winkler = stringcmp.winkler(pair[0], pair[1])
            approx_str_value_jaro = stringcmp.jaro(pair[0], pair[1])

            assert (
                approx_str_value_winkler >= approx_str_value_jaro
            ), '"Winkler" value smaller than "Jaro" value for:' + str(pair)
예제 #4
0
  def testWinkler(self):  # - - - - - - - - - - - - - - - - - - - - - - - - - -
    """Test 'Winkler' approximate string comparator"""

    for pair in self.string_pairs:

      approx_str_value = stringcmp.winkler(pair[0],pair[1])

      assert (isinstance(approx_str_value,float)), \
             '"Winkler" does not return a floating point number for:'+ \
             str(pair)

      assert (approx_str_value >= 0.0), \
             '"Winkler" returns a negative number for:'+str(pair)

      assert (approx_str_value <= 1.0), \
             '"Winkler" returns a number larger than 1.0 for:'+str(pair)

      approx_str_value_1 = stringcmp.winkler(pair[0],pair[1])
      approx_str_value_2 = stringcmp.winkler(pair[1],pair[0])

      assert (approx_str_value_1 == approx_str_value_2), \
             '"Winkler" returns different values for pair and swapped ' + \
             'pair: '+str(pair)+': '+str(approx_str_value_1)+', '+ \
             str(approx_str_value_2)

      # Check for value 1.0 if the strings are the same
      #
      if (pair[0] == pair[1]):

        assert (approx_str_value == 1.0), \
               '"Winkler" does not return 1.0 if strings are equal: '+str(pair)

      # Winkler should always return a value equal to or larger than Jaro
      #
      approx_str_value_winkler = stringcmp.winkler(pair[0],pair[1])
      approx_str_value_jaro =    stringcmp.jaro(pair[0],pair[1])

      assert (approx_str_value_winkler >= approx_str_value_jaro), \
             '"Winkler" value smaller than "Jaro" value for:'+str(pair)
예제 #5
0
import time
import stringcmp

with open('TEST_DATA.csv', 'rb') as f_open:
    msg = []
    # data =  [line.rstrip('\n\r').split(',') for line in f_open]

    for line in f_open:
        twoNames = line.rstrip('\n\r').split(',')
        #print(twoNames)
        s = '%13s,%13s,' % (twoNames[0], twoNames[1])

        ##------Jaro------##
        start_time = time.time()
        s += ' %.3f' % (stringcmp.jaro(twoNames[0], twoNames[1]))
        time_used = time.time() - start_time
        s += ' %.10f' % (time_used)

        ##------winkler------##
        start_time1 = time.time()
        s += ' %.3f' % (stringcmp.winkler(twoNames[0], twoNames[1]))
        time_used1 = time.time() - start_time1
        s += ' %.10f' % (time_used1)

        ##------qgram 1------##
        start_time2 = time.time()
        s += ' %.3f' % (stringcmp.qgram(twoNames[0], twoNames[1], 1))
        time_used2 = time.time() - start_time2
        s += ' %.10f' % (time_used2)