Closed
Description
TrieNode.is_prefix always crashes with exception (and all execution paths return False).
Example:
from adapt.tools.text.trie import Trie
trie = Trie()
trie.insert("play", "PlayVerb")
trie.insert("the big bang theory", "Television Show")
trie.insert("the big", "Not a Thing")
trie.insert("barenaked ladies", "Radio Station")
print(trie.root.is_prefix("play"))
produces:
Traceback (most recent call last):
File "prueba.py", line 10, in <module>
trie.root.is_prefix("play")
File "/home/pma/.virtualenvs/mycroft/local/lib/python2.7/site-packages/adapt/tools/text/trie.py", line 80, in is_prefix
return self.children[iterable[index]].is_prefix(iterable, index + 1)
File "/home/pma/.virtualenvs/mycroft/local/lib/python2.7/site-packages/adapt/tools/text/trie.py", line 80, in is_prefix
return self.children[iterable[index]].is_prefix(iterable, index + 1)
File "/home/pma/.virtualenvs/mycroft/local/lib/python2.7/site-packages/adapt/tools/text/trie.py", line 80, in is_prefix
return self.children[iterable[index]].is_prefix(iterable, index + 1)
File "/home/pma/.virtualenvs/mycroft/local/lib/python2.7/site-packages/adapt/tools/text/trie.py", line 80, in is_prefix
return self.children[iterable[index]].is_prefix(iterable, index + 1)
File "/home/pma/.virtualenvs/mycroft/local/lib/python2.7/site-packages/adapt/tools/text/trie.py", line 79, in is_prefix
if iterable[index] in self.children:
IndexError: string index out of range
see related pull request for cause and solution.