4
I am beginner in python, for some time I have been interested in Text Mining and I would like to ask for a help with a doubt in a project.
For some time I have been studying how to use the Python NLTK Library to create a chatbot.
I even worked 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 realized that in this tuple 'pairs' the module nltk.chat.util uses a function of the module’re' python to create the bot dialogs.
In the nltk.chat.util module it takes the content of the tuple and uses this function:
[(re.compile(x, re.IGNORECASE),y) for (x,y) in pairs]
to transform the content of 'pairs' in:
[(re.compile('oi', re.IGNORECASE), ['olá', 'Como vai?', 'Tudo Bem?'])]
My question is whether there is a way to take the dialogs in a text file, put them in the tuple 'pairs' as if they were a sentence, e.g.: 'How are you? ', 'All right? '. Why when I run the python code read the dialogs from inside the text file.
Someone who has experience can help me?