I'm a beginner in python, some time I've been interested in Text Mining and would like to ask for help with a question in a project.
Some time I've been studying how to use the Python NLTK Library to create a chatbot.
I even got to work out some codes, but there was a doubt.
My code:
#coding: utf-8
from nltk.chat.util import Chat, reflections
pairs = [
[
r'oi',
['olá', 'Como vai?', 'Tudo Bem?',]
],
]
def bob_bot():
print("Como posso te ajudar hoje?")
chat = Chat(pairs, reflections)
chat.converse()
if __name__ == "__main__":
bob_bot()
I noticed that in this tuple pairs the nltk.chat.util module uses a function of the python 're' module to create the bot dialog.
In the nltk.chat.util module it takes the contents of the tuple and uses this function:
[(re.compile(x, re.IGNORECASE),y) for (x,y) in pairs]
to transform the content of 'pairs' into:
[(re.compile('oi', re.IGNORECASE), ['olá', 'Como vai?', 'Tudo Bem?'])]
My question is whether you can get the dialogs from a text file, put them inside the pairs' tuple as if they were a sentence, eg 'How are you?', 'All right?'. So when I run the code python reads the dialogs from within the text file.
Someone who has experience, can you help me?