-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.py
138 lines (126 loc) · 3.89 KB
/
actions.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
from rasa_sdk import Action
def get_restaurants(restaurant=None, cuisine=None):
restaurants = [
{
"id": 0,
"name": "سپائس بازار",
"cuisine": "دیسی",
"price-range": "mid-range"
},
{
"id": 1,
"name": "دی لکھنوی",
"cuisine": "دیسی",
"price-range": "cheap"
},
{
"id": 2,
"name": "انداز ریسٹورنٹ",
"cuisine": "English",
"price-range": "mid-range"
},
{
"id": 3,
"name": "آر کیڈین کیفے",
"cuisine": "اٹالین",
"price-range": "cheap"
},
{
"id": 4,
"name": "پاستا لا وستا",
"cuisine": "اٹالین",
"price-range": "mid-range"
},
{
"id": 5,
"name": "لاہور چٹخارہ",
"cuisine": "دیسی",
"price-range": "mid-range"
},
{
"id": 6,
"name": "واسابی",
"cuisine": "English",
"price-range": "cheap"
}
]
if cuisine:
return [restaurant for restaurant in restaurants if
restaurant['cuisine'] == cuisine], "یہ ہیں کچھ مشہور {} ریسٹورنٹس".format(cuisine)
else:
return restaurants, "یہ ہیں کچھ مشہور ریسٹورنٹس"
def get_hotels():
hotels = [
{
"id": 0,
"name": "پی سی ہوٹل",
"price-range": "expensive",
"city": "Lahore",
"star-rating": 5,
},
{
"id": 1,
"name": "دی نشاط ہوٹل",
"price-range": "expensive",
"city": "Lahore",
"star-rating": 4,
},
{
"id": 2,
"name": "فیملی ہوٹل",
"price-range": "mid-range",
"city": "Lahore",
"star-rating": 4,
},
{
"id": 3,
"name": "سٹپ ان ہوٹل",
"price-range": "mid-range",
"city": "Lahore",
"star-rating": 4,
},
{
"id": 4,
"name": "لاہور پیلس ہوٹل",
"price-range": "expensive",
"city": "Lahore",
"star-rating": 4,
}
]
return hotels, "یہ ہیں کچھ مشہور ہوٹلز"
# def get_cuisine(cuisine):
# restaurants = get_restaurants()
# return [restaurant for restaurant in restaurants if restaurant['cuisine'] == cuisine]
class ActionQueryDatabase(Action):
def name(self):
return "action_query_database"
def run(self, dispatcher, tracker, domain):
restaurant = tracker.get_slot("restaurant")
hotel = tracker.get_slot("hotel")
cuisine = tracker.get_slot("cuisine")
results = [{"name": "دی لکھنوی"}]
message = ""
if restaurant or cuisine:
results, message = get_restaurants(restaurant=restaurant, cuisine=cuisine)
elif hotel:
results, message = get_hotels()
dispatcher.utter_message(message)
# limit to top 5 queries
for i, obj in enumerate(results[:5]):
dispatcher.utter_message(str(i + 1) + " - " + obj['name'])
return []
# class ActionQueryCuisine(Action):
# def name(self):
# return "action_query_cuisine"
#
# def run(self, dispatcher, tracker, domain):
# cuisine = tracker.get_slot("cuisine")
#
# results = get_cuisine(cuisine)
#
# dispatcher.utter_message("یہ ہیں کچھ مشہور {} ریسٹورنٹس".format(cuisine))
# # limit to top 5 queries
# for i, obj in enumerate(results[:3]):
# dispatcher.utter_message(str(i+1) + " - " + obj['name'])
#
# return []