Exemple #1
0
 def lexicon_entry_for(self, token: Token) -> LexiconEntry:
     """
     Entry in lexicon that best matches ``token``.
     """
     result = None
     lexicon_size = len(self.entries)
     lexicon_entry_index = 0
     best_matching = 0.0
     while lexicon_entry_index < lexicon_size and not tools.is_close(best_matching, 1.0):
         lexicon_entry = self.entries[lexicon_entry_index]
         matching = lexicon_entry.matching(token)
         if matching > best_matching:
             result = lexicon_entry
             best_matching = matching
         lexicon_entry_index += 1
     return result
Exemple #2
0
def test_can_match_exact_lexicon_entry(nlp_en: Language):
    chicken_token = _token_for(nlp_en, _CHICKEN)
    chicken_entry = analysis.LexiconEntry(_CHICKEN, RestaurantTopic.FOOD)
    assert tools.is_close(chicken_entry.matching(chicken_token), 1.0)
Exemple #3
0
def test_can_detect_close_float_numbers():
    assert tools.is_close(0.0, 0.0)
    assert tools.is_close(1.0, 1.0)
    assert not tools.is_close(1.0, 0.99)