-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.py
85 lines (73 loc) · 3.42 KB
/
test.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
from data import DataMessage
from datetime import datetime
import bots.meetingsuggestor as ms
import parsing.MessageParser as mp
m = mp.MessageParser()
def generate_dialog(case='baseline'):
dialog = []
if case =='baseline':
dialog.append({'user_e': 'John',
'created_at': datetime.now(),
'message_e': 'I can do from 6 on Sunday.'})
dialog.append({'user_e': 'Mark',
'created_at': datetime.now(),
'message_e': "I can do at 9 on Sunday."})
dialog.append({'user_e': 'Jane',
'created_at': datetime.now(),
'message_e': 'I can do at 9 on Sunday. Or on Saturday at 2pm.'})
elif case=='negation':
dialog.append({'user_e': 'John',
'created_at': datetime.now(),
'message_e': 'I can do from 6 on Sunday.'})
dialog.append({'user_e': 'Mark',
'created_at': datetime.now(),
'message_e': "I can do at 9 on Sunday. I can not do 9 on Monday."})
dialog.append({'user_e': 'Jane',
'created_at': datetime.now(),
'message_e': "I can do at 9 on Sunday. Or on Saturday at 2pm."})
dialog.append({'user_e': 'Jane',
'created_at': datetime.now(),
'message_e': "I will not be able to come on Friday"})
elif case=='chatter':
dialog.append({'user_e': 'John',
'created_at': datetime.now(),
'message_e': 'I can do from 6 on Sunday.'})
dialog.append({'user_e': 'Mark',
'created_at': datetime.now(),
'message_e': "I can do at 9 on Sunday. My dog is sick so I can't on Saturday."})
dialog.append({'user_e': 'Jane',
'created_at': datetime.now(),
'message_e': "Sorry about your dog."})
dialog.append({'user_e': 'Jane',
'created_at': datetime.now(),
'message_e': "I won't be able to come on Friday, but Sunday works for me."})
else:
pass
return dialog
def generate_message_stack(dialog):
list_of_datamessage = []
for entry in dialog:
print '%s : %s' %(entry['user_e'], entry['message_e'])
if m.extract_intent(entry['message_e']) == 'times':
mes = DataMessage(testing=True,**entry)
print mes.list_of_times
list_of_datamessage.append(mes)
return list_of_datamessage
def simulate_bot_session(meeting_suggestion, case='baseline'):
dialog = generate_dialog(case)
message_stack = generate_message_stack(dialog)
get_consensus(message_stack,meeting_suggestion)
def get_consensus(message_stack, meeting_suggestion):
times_availability = []
for message in message_stack:
for interval in message.list_of_times:
times_availability.append(interval)
window_size = 2
meeting = meeting_suggestion(message_stack,window_size)[0] # takes highest ranked option
print meeting
a, start, end, c = meeting
text = 'A date could be between %s and %s'%(start.strftime('%H:%M %Y-%m-%d'),end.strftime('%H:%M %Y-%m-%d'))
print 'Bot response: ' + text
if __name__=='__main__':
meeting_suggestion = ms.get_suggested_meetings_topology_sort
simulate_bot_session(meeting_suggestion, case='chatter')