Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IndexError and KeyError #1290

Open
dylib opened this issue Apr 30, 2018 · 3 comments
Open

IndexError and KeyError #1290

dylib opened this issue Apr 30, 2018 · 3 comments
Labels

Comments

@dylib
Copy link

dylib commented Apr 30, 2018

I noticed there seems to be a couple of issues when inputting mixed words with numbers in the terminal_example.py:

KeyError

$ python terminal_example.py
Type something to begin...
ninety seven - 7
Traceback (most recent call last):
  File "terminal_example.py", line 30, in <module>
    bot_input = bot.get_response(None)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/chatterbot.py", line 113, in get_response
    statement, response = self.generate_response(input_statement, conversation_id)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/chatterbot.py", line 132, in generate_response
    response = self.logic.process(input_statement)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/multi_adapter.py", line 49, in process
    if adapter.can_process(statement):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/mathematical_evaluation.py", line 33, in can_process
    response = self.process(statement)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/mathematical_evaluation.py", line 59, in process
    mathparse.parse(expression, language=self.language)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mathparse/mathparse.py", line 269, in parse
    postfix = to_postfix(tokens)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mathparse/mathparse.py", line 176, in to_postfix
    while (opstack != []) and (precedence[opstack[-1]] >= precedence[token]):
KeyError: '9ty'

IndexError

$ python terminal_example.py
sType something to begin...
seven - 7
Traceback (most recent call last):
  File "terminal_example.py", line 30, in <module>
    bot_input = bot.get_response(None)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/chatterbot.py", line 113, in get_response
    statement, response = self.generate_response(input_statement, conversation_id)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/chatterbot.py", line 132, in generate_response
    response = self.logic.process(input_statement)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/multi_adapter.py", line 49, in process
    if adapter.can_process(statement):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/mathematical_evaluation.py", line 33, in can_process
    response = self.process(statement)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/mathematical_evaluation.py", line 59, in process
    mathparse.parse(expression, language=self.language)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mathparse/mathparse.py", line 271, in parse
    return evaluate_postfix(postfix)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mathparse/mathparse.py", line 203, in evaluate_postfix
    a = stack.pop()
IndexError: pop from empty list

...and...

$ python terminal_example.py
Type something to begin...
ninetyseven - seven
Traceback (most recent call last):
  File "terminal_example.py", line 30, in <module>
    bot_input = bot.get_response(None)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/chatterbot.py", line 113, in get_response
    statement, response = self.generate_response(input_statement, conversation_id)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/chatterbot.py", line 132, in generate_response
    response = self.logic.process(input_statement)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/multi_adapter.py", line 49, in process
    if adapter.can_process(statement):
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/mathematical_evaluation.py", line 33, in can_process
    response = self.process(statement)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/chatterbot/logic/mathematical_evaluation.py", line 59, in process
    mathparse.parse(expression, language=self.language)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mathparse/mathparse.py", line 271, in parse
    return evaluate_postfix(postfix)
  File "/opt/local/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/mathparse/mathparse.py", line 203, in evaluate_postfix
    a = stack.pop()
IndexError: pop from empty list

Some type of exception handling here would probably be better than just crashing perhaps.

@vkosuri
Copy link
Collaborator

vkosuri commented Apr 30, 2018

@dylib This due to lack of statements present SQLStorageAdapter

storage_adapter="chatterbot.storage.SQLStorageAdapter",

may you could try to train your bot with some statements using list trainer http://chatterbot.readthedocs.io/en/stable/training.html#training-via-list-data

@gunthercox
Copy link
Owner

Looks like this is related to the mathparse library. @dylib thank you for the test data, it'll make fixing this issue much easier.

@gunthercox gunthercox added the bug label May 8, 2018
@AskellAytch
Copy link

for the key error here is the solution i found:
#2256

Hope it helps!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants