robocup_knowledge
rwc2017/challenge_gpsr.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 
30 C[{A}] -> VP[A]
31 """
32 
33 
38 
39 grammar += """
40 PPN_OBJECT[reference] -> it | them
41 PPN_PERSON -> him | her | them
42 
43 DET -> the | a | an | some
44 NUMBER -> one | two | three
45 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
46 """
47 
48 for room in common.location_rooms:
49  grammar += '\nROOM[%s] -> %s' % (room, room)
50 
51 for loc in common.get_locations():
52  grammar += '\nLOCATION[%s] -> %s' % (loc, loc)
53 
54 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
55 
56 for obj in common.object_names:
57  grammar += '\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
58 
59 for loc in common.get_locations(pick_location=True, place_location=True):
60  grammar += '\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
61 
62 for cat in common.object_categories:
63  grammar += '\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)
64 
65 for name in common.names:
66  grammar += '\nNAMED_PERSON[%s] -> %s' % (name, name)
67 
68 
73 
74 grammar += """
75 V_FIND -> find | locate | look for | meet
76 
77 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
78 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man | NAMED_PERSON | someone
79 
80 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
81 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
82 
83 VP["action": "find", "object": {"type": "person", "id": X}, "location": {"id": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] in the ROOM[Y]
84 VP["action": "find", "object": {"type": "person", "id": X}, "location": {"id": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] near the LOCATION[Y]
85 
86 VP["action": "find", "object": {"type": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
87 VP["action": "find", "object": {"type": person, "id": X}] -> V_FIND DET PERSON_TO_BE_FOUND[X]
88 """
89 
90 
95 
96 grammar += """
97 V_GOPL -> go to | navigate to
98 V_GOR -> V_GOPL | enter
99 
100 VP["action": "navigate-to", "object": {"id": X}] -> V_GOR the ROOM[X]
101 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATION[X]
102 """
103 
104 
109 
110 grammar += """
111 V_PICKUP -> get | grasp | take | pick up | grab
112 
113 VP["action": "pick-up", "object": {"type": X}, "location": {"id": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
114 """
115 
116 
121 
122 grammar += """
123 V_PLACE -> put | place
124 
125 VP["action": "place", "object": {"type": "reference"}, "location": {"id": Y}] -> V_PLACE PPN_OBJECT MANIPULATION_AREA_LOCATION[Y]
126 """
127 
128 
133 
134 for room in common.location_rooms:
135  grammar += '\nBRING_ROOM[{"type": room, "id": %s}] -> %s' % (room, room)
136 
137 for loc in common.get_locations():
138  grammar += '\nBRING_LOCATION[{"type": furniture, "id": %s}] -> %s' % (loc, loc)
139 
140 grammar += '\n BRING_ROOM_OR_LOCATION[X] -> BRING_ROOM[X] | BRING_LOCATION[X]'
141 
142 grammar += """
143 INAT -> in | at
144 
145 BRING_PERSON_AT_LOCATION[{"type": person, "id": X, "loc": Y}] -> NAMED_PERSON[X] INAT the ROOM_OR_LOCATION[Y]
146 BRING_OPERATOR[{"type": person, "id": operator}] -> me
147 BRING_PERSON -> BRING_OPERATOR | BRING_PERSON_AT_LOCATION
148 
149 BRING_TARGET[X] -> BRING_PERSON[X] | the BRING_LOCATION[X]
150 
151 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT | PPN_OBJECT
152 
153 V_BRING -> bring | deliver | take | give | get
154 """
155 
156 # Bring <object> from the <location> to the <location>
157 # Bring <object> to the <location> from the <location>
158 grammar += """
159 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]
160 """
161 
162 # Bring to <person> the <object> | Bring <object> to <person> | bring <person> the <object>
163 grammar += """
164 VP["action": "bring", "target-location": Y, "object": {"type": Z}] -> V_BRING to BRING_TARGET[Y] OBJECT_TO_BE_BROUGHT[Z] | V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_TARGET[Y] | V_BRING BRING_PERSON[Y] OBJECT_TO_BE_BROUGHT[Z]
165 """
166 
167 # Bring to <person> the <object> from the <location>
168 grammar += """
169 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] | V_BRING BRING_TARGET[Y] OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X]
170 """
171 
172 # Place the <object> on the <location>
173 grammar += """
174 VP["action": "bring", "object": {"type": Z}, "target-location": Y] -> V_PLACE OBJECT_TO_BE_BROUGHT[Z] MANIPULATION_AREA_DESCRIPTION the BRING_LOCATION[Y]
175 """
176 
177 
178 
183 
184 grammar += """
185 V_SAY -> tell | say | speak
186 
187 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
188 VP["action": "say", "sentence": X, "target-person": Y] -> V_SAY SAY_SENTENCE[X] to BRING_PERSON_AT_LOCATION[Y]
189 """
190 
191 grammar += '\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
192 grammar += '\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
193 grammar += '\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
194 grammar += '\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
195 grammar += '\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
196 grammar += '\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
197 grammar += '\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
198 grammar += '\nSAY_SENTENCE["JOKE"] -> a joke'
199 grammar += '\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
200 
201 
202 follow_action = "follow", {"location-from": {""}, "location-to": {}, "target": {}}
203 
204 
209 
210 grammar += """
211 VP["action": "answer-question"] -> answer a question
212 VP["action": "answer-question", "target-person": X] -> answer a question to BRING_PERSON_AT_LOCATION[X]
213 """
214 
215 
220 
221 grammar += """
222 PROPERTY["number"] -> number
223 PROPERTY["name"] -> name
224 
225 INVESTIGATION_LOCATION[X] -> MANIPULATION_AREA_LOCATION[X] | in the ROOM
226 
227 VP["action": "find-out-and-report", "property": X, "object": {"type": Y}] -> tell me the PROPERTY[X] of OBJECT_TO_BE_FOUND[Y] INVESTIGATION_LOCATION[Z]
228 """
229 
230 if __name__ == "__main__":
231  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
232 
233  from grammar_parser.cfgparser import CFGParser
234 
235  import sys
236  if sys.argv[1] == "object":
237  grammar_parser = CFGParser.fromstring(obj_grammar)
238  elif sys.argv[1] == "location":
239  grammar_parser = CFGParser.fromstring(loc_grammar)
240  elif sys.argv[1] == "full":
241  grammar_parser = CFGParser.fromstring(grammar)
242 
243  if len(sys.argv) > 2:
244  sentence = " ".join(sys.argv[2:])
245  else:
246  sentence = grammar_parser.get_random_sentence("T")
247 
248  print("Parsing sentence:\n\n{}\n\n".format(sentence))
249 
250  result = grammar_parser.parse("T", sentence)
251 
252  print("Result:\n\n{}".format(result))
253 
254 
255 
260 
261 question_grammar_target = "T"
262 
263 question_grammar = """
264 T[{actions : <A1>}] -> C[A1]
265 
266 C[{A}] -> Q[A]
267 """
268 
269 # Predefined questions
270 question_grammar += '''
271 
272 WHATWHICH -> what | which
273 
274 BIGGEST_ADJ -> biggest | heaviest
275 SMALLEST_ADJ -> smallest | lightest
276 
277 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ object
278 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ object
279 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ food
280 Q["action" : "answer", "solution": "onion"] -> WHATWHICH is the SMALLEST_ADJ food
281 Q["action" : "answer", "solution": "plate"] -> WHATWHICH is the BIGGEST_ADJ container
282 Q["action" : "answer", "solution": "soup_container"] -> WHATWHICH is the SMALLEST_ADJ container
283 Q["action" : "answer", "solution": "green_tea"] -> WHATWHICH is the BIGGEST_ADJ drink
284 Q["action" : "answer", "solution": "coke"] -> WHATWHICH is the SMALLEST_ADJ drink
285 Q["action" : "answer", "solution": "hair_spray"] -> WHATWHICH is the BIGGEST_ADJ cleaning stuff
286 Q["action" : "answer", "solution": "moisturizer"] -> WHATWHICH is the SMALLEST_ADJ cleaning stuff
287 Q["action" : "answer", "solution": "spoon"] -> WHATWHICH is the BIGGEST_ADJ cutlery
288 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ cutlery
289 
290 Q["action" : "answer", "solution": "the bedroom has one door"] -> how many doors has the bedroom
291 Q["action" : "answer", "solution": "the entrance has one door"] -> how many doors has the entrance
292 Q["action" : "answer", "solution": "the living room has one door"] -> how many doors has the living_room
293 Q["action" : "answer", "solution": "the kitchen has one door"] -> how many doors has the kitchen
294 Q["action" : "answer", "solution": "the corridor has zero doors"] -> how many doors has the corridor
295 Q["action" : "answer", "solution": "the balcony has zero doors"] -> how many doors has the balcony
296 '''
297 
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156