-
Notifications
You must be signed in to change notification settings - Fork 0
/
doctor.py
58 lines (39 loc) · 1.58 KB
/
doctor.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
46
47
48
49
50
51
52
53
54
55
56
57
import random
class Doctor():
QUALIFIERS = ['Why do you say that ', 'You seem to think that ',
'Did I just hear you say that ', 'Why do you believe that ' ]
REPLACEMENTS = {'I': 'you', 'me': 'you', 'my': 'your',
'we': 'you', 'us': 'you', 'am': 'are',
'you': 'I', 'You': 'I'}
HEDGES = ['Go on.', 'I would like to hear more about that.',
'And what do you think about this?', 'Please continue.']
def __init__(self):
self.history = []
def greeting(self):
return 'Good morning, how can I help you today?'
def farewell(self):
return 'Have a nice day!'
def reply(self, sentence):
choice = random.randint (1, 10)
if choice == 1:
if len(self.history) > 3:
answer = 'Earlier you said that ' + \
self.change_person(random.choice(self.history))
else:
answer = random.choice(Doctor.HEDGES)
elif choice in (2,3,4,5):
answer = random.choice(Doctor.QUALIFIERS) + \
self.change_person(sentence)
else:
answer = random.choice(Doctor.HEDGES)
self.history.append(sentence)
return answer
def change_person(self, sentence):
oldlist = sentence.split()
newlist = []
for word in oldlist:
if word in Doctor.REPLACEMENTS:
newlist.append(Doctor.REPLACEMENTS[word])
else:
newlist.append(word)
return " ".join(newlist)