Ejemplo n.º 1
0
 def test_edit_distance_confidence(self):
     trie = Trie(max_edit_distance=2)
     trie.insert("a")
     trie.insert("bb")
     trie.insert("ccc")
     trie.insert("dddd")
     trie.insert("100")
     results = list(trie.gather("b"))
     assert len(results) == 1
     assert results[0].get('confidence') == 0.5
     results = list(trie.gather("1 of"))
     assert len(results) == 3
Ejemplo n.º 2
0
 def test_edit_distance_confidence(self):
     trie = Trie(max_edit_distance=2)
     trie.insert("a")
     trie.insert("bb")
     trie.insert("ccc")
     trie.insert("dddd")
     trie.insert("100")
     results = list(trie.gather("b"))
     assert len(results) == 1
     assert results[0].get('confidence') == 0.5
     results = list(trie.gather("1 of"))
     assert len(results) == 3
Ejemplo n.º 3
0
 def test_gather(self):
     trie = Trie()
     trie.insert("rest")
     trie.insert("restaurant")
     results = list(trie.gather("restaurant"))
     assert len(results) == 1
     assert results[0].get('key') == "restaurant"
Ejemplo n.º 4
0
 def test_gather(self):
     trie = Trie()
     trie.insert("rest")
     trie.insert("restaurant")
     results = list(trie.gather("restaurant"))
     assert len(results) == 1
     assert results[0].get('key') == "restaurant"
Ejemplo n.º 5
0
    def test_remove(self):
        trie = Trie(max_edit_distance=2)
        trie.insert("1", "Number")
        trie.insert("2", "Number")
        trie.remove("2")

        one_lookup = list(trie.gather("1"))
        two_lookup = list(trie.gather("2"))
        assert len(one_lookup) == 1  # One match found
        assert len(two_lookup) == 0  # Zero matches since removed
Ejemplo n.º 6
0
    def test_remove_multi_last(self):
        trie = Trie(max_edit_distance=2)
        trie.insert("Kermit", "Muppets")
        trie.insert("Kermit", "Frogs")
        kermit_lookup = list(trie.lookup("Kermit"))[0]
        assert 'Frogs' in kermit_lookup['data']
        assert 'Muppets' in kermit_lookup['data']

        trie.remove("Kermit", "Frogs")

        kermit_lookup = list(trie.gather("Kermit"))[0]
        assert kermit_lookup['data'] == {"Muppets"}  # Right data remains
Ejemplo n.º 7
0
 def test_missing_entities(self):
     trie = Trie()
     trie.insert("restaurant", "Concept")
     trie.insert("rest", "Concept")
     trie.insert("restaurant2", "Fast")
     results = list(trie.gather("restaurant"))
     assert len(results) == 1
     assert trie.root.entities() == ['root', 'Concept', 'Fast']
     assert trie.checkForMissingEntites("Concept") is None
     assert trie.checkForMissingEntites("root") is None
     assert trie.checkForMissingEntites("Fast") is None
     assert trie.checkForMissingEntites(['root', 'Concept', 'Fast']) is None
     assert trie.checkForMissingEntites(['root2', 'Concept',
                                         'Fast']) == ["root2"]
     assert trie.checkForMissingEntites(
         ('root2', 'Concept', 'Fast')) == ["root2"]
Ejemplo n.º 8
0
 def test_insert_single_character_entity(self):
     trie = Trie()
     trie.insert("1", "Number")
     results = list(trie.gather("1 of the big bang theory"))
     assert len(results) == 1
     assert len(results[0].get('data')) == 1
Ejemplo n.º 9
0
 def test_retrieval_of_multi_word_entity(self):
     trie = Trie()
     trie.insert("play", "PlayVerb")
     trie.insert("the big bang theory", "Television Series")
     results = list(trie.gather("1 of the big bang theory"))
     assert len(results) == 0
Ejemplo n.º 10
0
 def test_edit_distance_no_confidence(self):
     trie = Trie(max_edit_distance=2)
     trie.insert("1", "Number")
     results = list(trie.gather("of the big bang theory"))
     assert len(results) == 0
Ejemplo n.º 11
0
 def test_insert_single_character_entity(self):
     trie = Trie()
     trie.insert("1", "Number")
     results = list(trie.gather("1 of the big bang theory"))
     assert len(results) == 1
     assert len(results[0].get('data')) == 1
Ejemplo n.º 12
0
 def test_retrieval_of_multi_word_entity(self):
     trie = Trie()
     trie.insert("play", "PlayVerb")
     trie.insert("the big bang theory", "Television Series")
     results = list(trie.gather("1 of the big bang theory"))
     assert len(results) == 0
Ejemplo n.º 13
0
 def test_edit_distance_no_confidence(self):
     trie = Trie(max_edit_distance=2)
     trie.insert("1", "Number")
     results = list(trie.gather("of the big bang theory"))
     assert len(results) == 0