Exemplo n.º 1
0
def _fuzzy_match(query, entries):
    stations = [entry.getAttribute("text") for entry in entries]
    if len(stations):
        _match, perc = match_one(query, stations)
        for entry in entries:
            if _match == entry.getAttribute("text"):
                return entry, perc
    return None, None
Exemplo n.º 2
0
 def test_match_one(self):
     # test list of choices
     choices = ['frank', 'kate', 'harry', 'henry']
     self.assertEqual(match_one('frank', choices)[0], 'frank')
     self.assertEqual(match_one('fran', choices)[0], 'frank')
     self.assertEqual(match_one('enry', choices)[0], 'henry')
     self.assertEqual(match_one('katt', choices)[0], 'kate')
     # test dictionary of choices
     choices = {'frank': 1, 'kate': 2, 'harry': 3, 'henry': 4}
     self.assertEqual(match_one('frank', choices)[0], 1)
     self.assertEqual(match_one('enry', choices)[0], 4)