MycroftAI / adapt

Adapt Intent Parser
Apache License 2.0
712 stars 154 forks source link

error in TrieNode.is_prefix #53

Closed SoloVeniaASaludar closed 3 years ago

SoloVeniaASaludar commented 7 years ago

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.

clusterfudge commented 3 years ago

@SoloVeniaASaludar I see your PR, however this has gone stale (did not respond to a request for a test, and no CLA). I'm going to cut my own and merge, including a test and will tag you on it. Thanks for contributing!