ChatterBot:
The program selects the closest matching response by searching for the closest matching known statement that matches the input, it then returns the most likely response to that statement based on how frequently each response is issued by the people the bot communicates with.
chat.txt
こんにちは こちらこそ こんにちは 今日もよろしくお願いします
chat2.txt
こんばんは こちらこそ こんばんは もう眠いですね おやすみなさい
main.py
from chatterbot import ChatBot from chatterbot.trainers import ListTrainer bot = ChatBot("チャットボット試作品") training_ = open('chat.text','r').readlines() training2_ = open('chat2.text','r').readlines() trainer = ListTrainer(bot) trainer.train(training_) trainer.train(training2_) while True: try: bot_input = bot.get_response(input()) print(bot_input) except(KeyboardInterrupt, EOFError, SystemExit): break
$ pip3 install chatterbot
$ pip3 install chatterbot-corpus
$ python3 main.py
[nltk_data] Downloading package stopwords to
[nltk_data] /home/vagrant/nltk_data…
[nltk_data] Package stopwords is already up-to-date!
[nltk_data] Downloading package averaged_perceptron_tagger to
[nltk_data] /home/vagrant/nltk_data…
[nltk_data] Package averaged_perceptron_tagger is already up-to-
[nltk_data] date!
List Trainer: [####################] 100%
List Trainer: [####################] 100%
こんにちは
こちらこそ こんにちは
もう眠いですね
おやすみなさい
もう眠いですね
おやすみなさい
こちらこそ こんばんは
もう眠いですね
aaa
もう眠いですね
そうですか
こちらこそ こんばんは
おはよう
もう眠いですね
こんにちは
こちらこそ こんにちは
なんだこれ…