robocup_knowledge
siza_demo/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[A] -> C[A]
27 
28 C[{"actions": <A1>}] -> VP[A1]
29 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
30 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VP[A3]
31 """
32 
33 
38 
39 grammar += """
40 V_GUIDE -> guide | escort | take | lead | accompany | conduct
41 
42 PPN_OBJECT -> it | them
43 PPN_PERSON -> him | her | them
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 
50 for room in common.location_rooms:
51  grammar += "\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
52 
53 for loc in common.get_locations():
54  grammar += '\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
55 
56 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
57 
58 for obj in common.object_names:
59  grammar += "\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
60 
61 for loc in common.get_locations(pick_location=True, place_location=True):
62  grammar += '\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
63 
64 for cat in common.object_categories:
65  grammar += "\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
66 
67 for name in common.names:
68  grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
69 
70 grammar += '\nLOCATION[{"id": "gpsr_exit_door_1", "type": "waypoint"}] -> exit'
71 
72 
77 
78 grammar += """
79 VP[{"action": "demo-presentation"}] -> introduce yourself | present yourself | perform a demonstration
80 """
81 
82 
87 
88 grammar += """
89 V_FIND -> find | locate | look for | pinpoint | spot
90 V_FIND_PERSON -> meet | V_FIND
91 
92 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
93 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man | NAMED_PERSON | someone
94 
95 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
96 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
97 
98 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] in the ROOM[Y]
99 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] near the LOCATION[Y]
100 
101 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
102 VP[{"action": "find", "object": X}] -> V_FIND DET PERSON_TO_BE_FOUND[X]
103 """
104 
105 
106 
107 
112 
113 grammar += """
114 V_GOPL -> go to | navigate to
115 V_GOR -> V_GOPL | enter to
116 
117 VP[{"action": "navigate-to", "target-location": X}] -> V_GOR the ROOM[X]
118 VP[{"action": "navigate-to", "target-location": X}] -> V_GOPL the LOCATION[X]
119 """
120 
121 
126 
127 grammar += """
128 
129 VP[{"action": "inspect", "entity": X}] -> inspect the LOCATION[X]
130 """
131 
132 
137 
138 grammar += """
139 V_PICKUP -> get | grasp | take | pick up | grab
140 
141 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
142 """
143 
144 
149 
150 grammar += """
151 V_PLACE -> put | place | set
152 
153 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
154 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
155 """
156 
157 
162 
163 grammar += """
164 V_FOLLOW -> follow | go after | come after | V_GUIDE
165 
166 VP[{"action": "follow", "location-from": X, "location-to": Y, "target": {"id": "operator"}}] -> V_FOLLOW me from the ROOM_OR_LOCATION[X] to the ROOM_OR_LOCATION[Y]
167 VP[{"action": "follow", "location-to": X, "location-from": Y, "target": {"id": "operator"}}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X] from the ROOM_OR_LOCATION[Y]
168 
169 VP[{"action": "follow", "target": {"id": "operator"}}] -> V_FOLLOW me
170 VP[{"action": "follow", "target": {"id": "operator"}, "location-to": X}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X]
171 
172 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
173 VP[{"action": "follow", "target": {"type": "reference"}, "location-to": X}] -> V_FOLLOW PPN_PERSON to the ROOM_OR_LOCATION[X]
174 
175 VP[{"action": "follow", "location-from": X, "location-to": Y, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X] to the ROOM_OR_LOCATION[Y]
176 VP[{"action": "follow", "location-to": X, "location-from": Y, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X] from the ROOM_OR_LOCATION[Y]
177 
178 VP[{"action": "follow", "location-from": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X]
179 VP[{"action": "follow", "location-to": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X]
180 
181 VP[{"action": "follow", "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
182 """
183 
184 grammar += '\nFOLLOW_PERSONS[the person] -> DET person'
185 grammar += '\nFOLLOW_PERSONS[the woman] -> DET woman'
186 grammar += '\nFOLLOW_PERSONS[the man] -> DET man'
187 for name in common.names:
188  grammar += '\nFOLLOW_PERSONS[%s] -> %s' % (name, name)
189 
190 
195 
196 # BRING_TARGET[{"id": X, "type": person}] -> BRING_NAME[X]
197 
198 grammar += """
199 OPERATOR[{"type": "person", "id": "operator"}] -> me
200 BRING_NAME -> OPERATOR | BRING_PERSON
201 
202 BRING_TARGET[X] -> the ROOM_OR_LOCATION[X]
203 
204 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
205 
206 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over | place | put
207 
208 VP[{"action": "place", "source-location": X, "target-location": Y, "object": 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]
209 
210 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_TARGET[X]
211 
212 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X] to BRING_NAME[Y] | V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_NAME[Y] from the ROOM_OR_LOCATION[X]
213 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z]
214 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X]
215 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_PERSON[X]
216 VP[{"action": "hand-over", "target-location": X, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_PERSON[X]
217 """
218 
219 for name in common.names:
220  grammar += '\nBRING_PERSON[{"type": "person", "id": "%s"}] -> %s' % (name, name)
221  for loc in common.get_locations():
222  grammar += '\nBRING_PERSON[{"type": "person", "id": "%s", "location": %s}] -> %s MANIPULATION_AREA_DESCRIPTION the %s' % (name, loc, name, loc)
223 
224 
229 
230 grammar += """
231 V_SAY -> tell | say | speak
232 
233 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
234 """
235 
236 grammar += '\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
237 grammar += '\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
238 grammar += '\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
239 grammar += '\nSAY_SENTENCE["COUNTRY"] -> your teams country'
240 grammar += '\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
241 grammar += '\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
242 grammar += '\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
243 grammar += '\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
244 grammar += '\nSAY_SENTENCE["JOKE"] -> a joke'
245 grammar += '\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
246 
247 
248 follow_action = "follow", {"location-from": {""}, "location-to": {}, "target": {}}
249 
250 
255 
256 grammar += """
257 VP[{"action": "answer-question"}] -> answer a question
258 """
259 
260 
265 
266 # grammar += """
267 # PERSON_PROPERTY -> age | name
268 
269 # VP[{"action": "find_out_and_report", "object": {"type": "person"}, "subject": X, "target": {"id": Z}}] -> V_SAY the PERSON_PROPERTY[X] of the person in the ROOM_OR_LOCATION[Z]
270 # """
271 
272 
277 
278 grammar += """
279 
280 HIM_HER -> him | her
281 
282 VP[{"action": "find", "object": {"type": "person", "id": Z}}] -> V_FIND MEET_PERSON[Z]
283 VP[{"action": "navigate-to"}] -> V_GUIDE HIM_HER
284 """
285 
286 grammar += '\nMEET_PERSON[the person] -> DET person'
287 grammar += '\nMEET_PERSON[the woman] -> DET woman'
288 grammar += '\nMEET_PERSON[the man] -> DET man'
289 for name in common.names:
290  grammar += '\nMEET_PERSON[%s] -> %s' % (name, name)
291 
292 # FOLLOW PERSON : (PERSON is at the BEACON)
293 # BRING me (a | some) CATEGORY : (which object of this category)
294 # DELIVER CATEGORY to PERSON : (which object of this category) && (PERSON is at the BEACON)
295 # meet PERSON(M) and GUIDE him : (PERSON is at the BEACON) && (guide him to BEACON)
296 # meet PERSON(F) and GUIDE her : (PERSON is at the BEACON) && (guide her to BEACON)
297 # NAVIGATE-TO BEACON, meet PERSON(M), and GUIDE him : (guide him to BEACON) && (keep him not lost)
298 # NAVIGATE-TO BEACON, meet PERSON(F), and GUIDE her : (guide her to BEACON) && (keep him not lost)
299 
300 loc_grammar = """
301 
302 HE_SHE -> he | she | it | him | her
303 
304 VP[{"object": {"id": X}}] -> HE_SHE is in the ROOM_OR_LOCATION[X] | in the ROOM_OR_LOCATION[X] | you could find HE_SHE in the ROOM_OR_LOCATION[X]
305 """
306 
307 obj_grammar = """
308 
309 VP[{"object": {"id": Y}}] -> the NAMED_OBJECT[Z] is DET NAMED_OBJECT[Y] | the NAMED_OBJECT[Z] is NAMED_OBJECT[Y] | NAMED_OBJECT[Y] | DET NAMED_OBJECT[Y]
310 """
311 
312 if __name__ == "__main__":
313  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
314 
315  from grammar_parser.cfgparser import CFGParser
316 
317  import sys
318  if sys.argv[1] == "object":
319  grammar_parser = CFGParser.fromstring(obj_grammar)
320  elif sys.argv[1] == "location":
321  grammar_parser = CFGParser.fromstring(loc_grammar)
322  elif sys.argv[1] == "full":
323  grammar_parser = CFGParser.fromstring(grammar)
324 
325  if len(sys.argv) > 2:
326  sentence = " ".join(sys.argv[2:])
327  else:
328  sentence = grammar_parser.get_random_sentence("T")
329 
330  print("Parsing sentence:\n\n{}\n\n".format(sentence))
331 
332  result = grammar_parser.parse("T", sentence)
333 
334  print("Result:\n\n{}".format(result))
335 
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156