示例#1
0
文件: TrieTest.py 项目: Ace139/adapt
 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
示例#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
示例#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"
示例#4
0
文件: TrieTest.py 项目: Ace139/adapt
 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"
示例#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
示例#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
示例#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"]
示例#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
示例#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
示例#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
示例#11
0
文件: TrieTest.py 项目: Ace139/adapt
 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
示例#12
0
文件: TrieTest.py 项目: Ace139/adapt
 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
示例#13
0
文件: TrieTest.py 项目: Ace139/adapt
 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