-
Notifications
You must be signed in to change notification settings - Fork 2
/
Assignment-5.py
45 lines (39 loc) · 1.52 KB
/
Assignment-5.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import chatterbot
import chatterbot_corpus
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
my_bot = ChatBot(name='PyBot', read_only=True,
logic_adapters=['chatterbot.logic.MathematicalEvaluation',
'chatterbot.logic.BestMatch'])
small_talk = ['hi there!',
'hi!',
'how do you do?',
'how are you?',
'i\'m cool.',
'fine, you?',
'always cool.',
'i\'m ok',
'glad to hear that.',
'i\'m fine',
'glad to hear that.',
'i feel awesome',
'excellent, glad to hear that.',
'not so good',
'sorry to hear that.',
'what\'s your name?',
'i\'m pybot. ask me a math question, please.']
math_talk_1 = ['pythagorean theorem',
'a squared plus b squared equals c squared.']
math_talk_2 = ['law of cosines',
'c**2 = a**2 + b**2 - 2 * a * b * cos(gamma)']
list_trainer = ListTrainer(my_bot)
for item in (small_talk, math_talk_1, math_talk_2):
list_trainer.train(item)
from chatterbot.trainers import ChatterBotCorpusTrainer
corpus_trainer = ChatterBotCorpusTrainer(my_bot)
corpus_trainer.train('chatterbot.corpus.english')
print(my_bot.get_response("how are you?"))
print(my_bot.get_response("hi"))
print(my_bot.get_response("what's your name?"))
print(my_bot.get_response("ask me something"))
print(my_bot.get_response("tell me about story"))