robocup_knowledge
rwc2017/challenge_eegpsr.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 from robocup_knowledge import knowledge_loader
4 common = knowledge_loader.load_knowledge("common")
5 
6 not_understood_sentences = [
7  "I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
8  "I am deeply sorry. Please try again, but wait for the ping!",
9  "You and I have communication issues. Speak up!",
10  "All this noise is messing with my audio. Try again"
11  ]
12 
13 initial_pose = "initial_pose"
14 starting_pose = "gpsr_meeting_point"
15 exit_waypoint = "gpsr_exit_door"
16 
17 grammar_target = "T"
18 
19 
24 
25 grammar = """
26 T[{actions : <A1>}] -> C[A1]
27 T[{actions : <A1, A2>}] -> C[A1] and C[A2]
28 T[{actions : <A1, A2, A3>}] -> C[A1] C[A2] and C[A3]
29 T[{actions : <A1, A2, A3, A4>}] -> C[A1] C[A2] and C[A3] C[A4]
30 T[{actions : <A1, A2, A3, A4>}] -> C[A1] C[A2] C[A3] and C[A4]
31 
32 C[{A}] -> VP[A]
33 """
34 
35 
40 
41 grammar += """
42 PPN_OBJECT["reference"] -> it | them
43 PPN_PERSON["reference"] -> him | her | them | it
44 
45 DET -> the | a | an | some
46 NUMBER -> one | two | three
47 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
48 
49 ROOM["exit_area"] -> exit
50 """
51 
52 for room in common.location_rooms:
53  grammar += '\nROOM[%s] -> %s' % (room, room)
54 
55 for loc in common.get_locations():
56  grammar += '\nLOCATION[%s] -> %s' % (loc, loc)
57 
58 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
59 
60 for obj in common.object_names:
61  grammar += '\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
62 
63 for loc in common.get_locations(pick_location=True, place_location=True):
64  grammar += '\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
65 
66 for cat in common.object_categories:
67  grammar += '\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)
68 
69 for name in common.names:
70  grammar += '\nNAMED_PERSON[%s] -> %s' % (name, name)
71 
72 
73 
78 
79 grammar += """
80 V_FIND -> find | locate | look for
81 
82 PERSON_TO_BE_FOUND -> NAMED_PERSON
83 
84 VP["action": "find", "object": {"type": X}] -> V_FIND DET NAMED_OBJECT[X]
85 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y] | V_FIND DET NAMED_OBJECT[X] in the ROOM_OR_LOCATION[Y]
86 
87 VP["action": "find", "object": {"type": person, "id": X}] -> V_FIND NAMED_PERSON[X]
88 VP["action": "find", "object": {"type": "person", "id": X}, "location": {"id": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM_OR_LOCATION[Y]
89 """
90 
91 
92 
93 
98 grammar += """
99 V_GUIDE -> guide | escort | take
100 
101 VP["action": "guide", "object": {"id": X}] -> V_GUIDE PPN_PERSON[Y] to the ROOM_OR_LOCATION[X]
102 
103 V_GOPL -> go to | navigate to
104 V_GOR -> V_GOPL | enter to | enter
105 
106 VP["action": "navigate-to", "object": {"id": X}] -> V_GOR the ROOM[X]
107 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATION[X]
108 """
109 
110 
111 
116 
117 grammar += """
118 V_PICKUP -> get | grasp | take | pick up | grab
119 
120 VP["action": "pick-up", "object": {"type": X}, "location": {"id": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
121 """
122 
123 
124 
129 
130 grammar += """
131 V_PLACE -> put | place
132 
133 VP["action": "place", "object": {"type": X}, "location": {"id": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
134 """
135 
136 
141 
142 grammar += """
143 V_FOLLOW -> follow
144 
145 VP["action": "follow", "target": {"type": X}] -> V_FOLLOW PPN_PERSON[X]
146 """
147 
148 
149 
154 
155 for room in common.location_rooms:
156  grammar += '\nBRING_ROOM[{"type": room, "id": %s}] -> %s' % (room, room)
157 
158 for loc in common.get_locations():
159  grammar += '\nBRING_LOCATION[{"type": furniture, "id": %s}] -> %s' % (loc, loc)
160 
161 grammar += '\n BRING_ROOM_OR_LOCATION[X] -> BRING_ROOM[X] | BRING_LOCATION[X]'
162 
163 grammar += """
164 INAT -> in | at
165 
166 BRING_PERSON_AT_LOCATION[{"type": person, "id": X, "loc": Y}] -> NAMED_PERSON[X] INAT the ROOM_OR_LOCATION[Y]
167 BRING_OPERATOR[{"type": person, "id": operator}] -> me
168 BRING_PERSON -> BRING_OPERATOR | BRING_PERSON_AT_LOCATION
169 
170 BRING_TARGET[X] -> BRING_PERSON[X] | the BRING_LOCATION[X]
171 
172 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT | PPN_OBJECT
173 
174 V_BRING -> bring | deliver | give | hand
175 """
176 
177 # (give | bring | deliver | hand) it to <person>
178 # deliver <object> on the <location>
179 
180 # locate <person> take (him|her)
181 
182 
183 grammar += """
184 VP["action": "bring", "source-location": X, "target-location": Y, "object": {"type": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X] to BRING_TARGET[Y] | V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_TARGET[Y] from the ROOM_OR_LOCATION[X]
185 """
186 
187 # Bring to <person> the <object> | Bring <object> to <person> | bring <person> the <object>
188 grammar += """
189 VP["action": "bring", "target-location": Y, "object": {"type": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_TARGET[Y] | V_BRING BRING_PERSON[Y] OBJECT_TO_BE_BROUGHT[Z] | V_BRING OBJECT_TO_BE_BROUGHT[Z] on BRING_TARGET[Y]
190 """
191 
192 # Bring <person> the <object> from the <location>
193 grammar += """
194 VP["action": "bring", "source-location": X, "target-location": Y, "object": {"type": Z}] -> V_BRING to BRING_TARGET[Y] OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X]
195 """
196 
197 grammar += """
198 VP["action": "bring", "object": {"type": Z}, "target-location": Y] -> V_PLACE OBJECT_TO_BE_BROUGHT[Z] MANIPULATION_AREA_DESCRIPTION the BRING_LOCATION[Y]
199 """
200 
201 
202 
207 
208 grammar += """
209 V_SAY -> tell | say
210 
211 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
212 VP["action": "say", "sentence": X, "target-person": Y] -> V_SAY SAY_SENTENCE[X] to BRING_PERSON_AT_LOCATION[Y]
213 VP["action": "say", "sentence": "DARK_SIDE"] -> join the dark side
214 """
215 
216 grammar += '\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
217 grammar += '\nSAY_SENTENCE["TEAM_NAME"] -> the name of your team'
218 grammar += '\nSAY_SENTENCE["TEAM_COUNTRY"] -> your teams country'
219 grammar += '\nSAY_SENTENCE["TEAM_AFFILIATION"] -> your teams affiliation'
220 grammar += '\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
221 grammar += '\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
222 grammar += '\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
223 grammar += '\nSAY_SENTENCE["TODAY"] -> what day is today'
224 grammar += '\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
225 grammar += '\nSAY_SENTENCE["JOKE"] -> a joke'
226 grammar += '\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
227 
228 
229 
234 
235 grammar += """
236 VP["action": "answer-question"] -> answer a question
237 """
238 
239 
240 if __name__ == "__main__":
241  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
242 
243  from grammar_parser.cfgparser import CFGParser
244 
245  grammar_parser = CFGParser.fromstring(grammar)
246 
247  sentence = grammar_parser.get_random_sentence("T")
248 
249  print("Parsing sentence:\n\n{}\n\n".format(sentence))
250 
251  result = grammar_parser.parse("T", sentence)
252 
253  print("Result:\n\n{}".format(result))
254 
255 
256 
261 
262 question_grammar_target = "T"
263 
264 question_grammar = """
265 T[{actions : <A1>}] -> C[A1]
266 
267 C[{A}] -> Q[A]
268 """
269 
270 # Predefined questions
271 question_grammar += '''
272 
273 WHATWHICH -> what | which
274 
275 BIGGEST_ADJ -> biggest | heaviest
276 SMALLEST_ADJ -> smallest | lightest
277 
278 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ object
279 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ object
280 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ food
281 Q["action" : "answer", "solution": "onion"] -> WHATWHICH is the SMALLEST_ADJ food
282 Q["action" : "answer", "solution": "plate"] -> WHATWHICH is the BIGGEST_ADJ container
283 Q["action" : "answer", "solution": "soup_container"] -> WHATWHICH is the SMALLEST_ADJ container
284 Q["action" : "answer", "solution": "green_tea"] -> WHATWHICH is the BIGGEST_ADJ drink
285 Q["action" : "answer", "solution": "coke"] -> WHATWHICH is the SMALLEST_ADJ drink
286 Q["action" : "answer", "solution": "hair_spray"] -> WHATWHICH is the BIGGEST_ADJ cleaning stuff
287 Q["action" : "answer", "solution": "moisturizer"] -> WHATWHICH is the SMALLEST_ADJ cleaning stuff
288 Q["action" : "answer", "solution": "spoon"] -> WHATWHICH is the BIGGEST_ADJ cutlery
289 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ cutlery
290 
291 Q["action" : "answer", "solution": "the bedroom has one door"] -> how many doors has the bedroom
292 Q["action" : "answer", "solution": "the entrance has one door"] -> how many doors has the entrance
293 Q["action" : "answer", "solution": "the living room has one door"] -> how many doors has the living_room
294 Q["action" : "answer", "solution": "the kitchen has one door"] -> how many doors has the kitchen
295 Q["action" : "answer", "solution": "the corridor has zero doors"] -> how many doors has the corridor
296 Q["action" : "answer", "solution": "the balcony has zero doors"] -> how many doors has the balcony
297 '''
298 
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156