added a chatbot to answer
parent
75302e0457
commit
317a515b55
@ -0,0 +1,34 @@
|
|||||||
|
|
||||||
|
from chatterbot import ChatBot
|
||||||
|
from sys import stdin, stderr, stdout
|
||||||
|
import nltk.data
|
||||||
|
|
||||||
|
|
||||||
|
text = stdin.read()
|
||||||
|
|
||||||
|
sent_detector = nltk.data.load('tokenizers/punkt/english.pickle')
|
||||||
|
sentences = sent_detector.tokenize(text.strip())
|
||||||
|
|
||||||
|
ns = []
|
||||||
|
|
||||||
|
chatbot = ChatBot(
|
||||||
|
'Ron Obvious',
|
||||||
|
trainer='chatterbot.trainers.ChatterBotCorpusTrainer',
|
||||||
|
output_format="text"
|
||||||
|
)
|
||||||
|
|
||||||
|
# Train based on the english corpus
|
||||||
|
chatbot.train("chatterbot.corpus.english")
|
||||||
|
|
||||||
|
for sen in sentences:
|
||||||
|
# Get a response to an input statement
|
||||||
|
response=chatbot.get_response(sen)
|
||||||
|
ns.append(sen)
|
||||||
|
ns.append(response.text)
|
||||||
|
|
||||||
|
|
||||||
|
file = open('output/whatdoesthechatbotsay.txt','w')
|
||||||
|
|
||||||
|
file.write("\n".join(ns))
|
||||||
|
|
||||||
|
file.close()
|
Loading…
Reference in New Issue