robocup_knowledge
siza_demo.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 = "hero_home"
14 
15 grammar_target = "T"
16 
17 
22 
23 grammar = """
24 T[A] -> C[A] | COURTESY C[A] | C[A] COURTESY | COURTESY C[A] COURTESY
25 
26 COURTESY -> please | robot please | could you | would you | hero | hero please
27 C[{"actions": <A1>}] -> VP[A1]
28 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
29 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VP[A3]
30 """
31 
32 
37 
38 grammar += """
39 PPN_OBJECT -> it | them
40 PPN_PERSON -> him | her | them
41 
42 DET -> the | a | an | some
43 NUMBER -> one | two | three
44 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
45 """
46 
47 for room in common.location_rooms:
48  grammar += "\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
49 
50 for loc in common.get_locations():
51  grammar += '\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
52 
53 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
54 
55 for obj in common.object_names:
56  grammar += "\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
57 
58 for loc in common.get_locations(pick_location=True, place_location=True):
59  grammar += '\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
60 
61 for cat in common.object_categories:
62  grammar += "\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
63 
64 for name in common.names:
65  grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
66 
67 
72 
73 grammar += """
74 VP[{"action": "demo-presentation"}] -> introduce yourself | present yourself | perform a demonstration
75 """
76 
77 
82 grammar += """
83 V_SEND_PICTURE -> check what is | show me what is | send me a picture of
84 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE MANIPULATION_AREA_DESCRIPTION the LOCATION[X]
85 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE the LOCATION[X]
86 """
87 
88 
89 
94 
95 grammar += """
96 V_CLEAR -> clear | clean up | clean-up | empty
97 
98 VP[{"action": "clear", "source-location": X, "target-location": {"id":"trashbin"}}] -> V_CLEAR the ROOM_OR_LOCATION[X]
99 VP[{"action": "clear", "source-location": X, "target-location": Y}] -> V_CLEAR the ROOM_OR_LOCATION[X] to the ROOM_OR_LOCATION[Y]
100 """
101 
102 
107 
108 grammar += """
109 V_RETURN -> bye | no thank you | no bye | go away
110 
111 VP[{"action": "navigate-to", "target-location": {"type":"waypoint", "id":"hero_home"}}] -> V_RETURN
112 """
113 
114 
119 
120 grammar += """
121 V_FIND -> find | locate | look for | pinpoint | spot
122 V_FIND_PERSON -> meet | V_FIND
123 
124 DEMO_HACK -> of apartment 11 | of appartment 11
125 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
126 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man
127 UNNAMED_PERSON -> a person | someone | me
128 
129 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
130 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y]
131 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y] DEMO_HACK
132 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM[Y]
133 
134 VP[{"action": "find", "object": {'type': 'person'}}] -> V_FIND UNNAMED_PERSON
135 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
136 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
137 
138 """
139 # VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] near the LOCATION[Y]
140 # VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
141 
142 
147 
148 grammar += """
149 V_GOPL -> go to | navigate to
150 V_GOR -> V_GOPL | enter to
151 
152 VP[{"action": "navigate-to", "target-location": X}] -> V_GOR the ROOM[X]
153 VP[{"action": "navigate-to", "target-location": X}] -> V_GOPL the LOCATION[X]
154 """
155 
156 
161 
162 grammar += """
163 
164 VP[{"action": "inspect", "entity": X}] -> inspect the LOCATION[X]
165 """
166 
167 
172 
173 grammar += """
174 V_PICKUP -> get | grasp | take | pick up | grab
175 
176 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
177 """
178 
179 
184 
185 grammar += """
186 V_PLACE -> put | place | set
187 
188 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
189 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
190 """
191 
192 
197 
198 grammar += """
199 V_FOLLOW -> follow | go after | come after | V_GUIDE
200 
201 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]
202 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]
203 
204 VP[{"action": "follow", "target": {"id": "operator"}}] -> V_FOLLOW me
205 VP[{"action": "follow", "target": {"id": "operator"}, "location-to": X}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X]
206 
207 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
208 VP[{"action": "follow", "target": {"type": "reference"}, "location-to": X}] -> V_FOLLOW PPN_PERSON to the ROOM_OR_LOCATION[X]
209 
210 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]
211 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]
212 
213 VP[{"action": "follow", "location-from": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X]
214 VP[{"action": "follow", "location-to": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X]
215 
216 VP[{"action": "follow", "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
217 """
218 
219 grammar += '\nFOLLOW_PERSONS[the person] -> DET person'
220 grammar += '\nFOLLOW_PERSONS[the woman] -> DET woman'
221 grammar += '\nFOLLOW_PERSONS[the man] -> DET man'
222 
223 
228 
229 # BRING_TARGET[{"id": X, "type": person}] -> BRING_NAME[X]
230 
231 grammar += """
232 OPERATOR[{"id": "operator"}] -> me
233 BRING_NAME -> OPERATOR | BRING_PERSON
234 
235 BRING_TARGET[X] -> the ROOM_OR_LOCATION[X]
236 
237 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
238 
239 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over | place | put
240 
241 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]
242 
243 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_TARGET[X]
244 
245 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]
246 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z]
247 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]
248 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_PERSON[X]
249 VP[{"action": "hand-over", "target-location": X, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_PERSON[X]
250 """
251 
256 
257 grammar += """
258 V_SAY -> tell | say | speak
259 
260 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
261 """
262 
263 grammar += '\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
264 grammar += '\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
265 grammar += '\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
266 grammar += '\nSAY_SENTENCE["COUNTRY"] -> your teams country'
267 grammar += '\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
268 grammar += '\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
269 grammar += '\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
270 grammar += '\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
271 grammar += '\nSAY_SENTENCE["JOKE"] -> a joke'
272 grammar += '\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
273 
274 
275 follow_action = "follow", {"location-from": {""}, "location-to": {}, "target": {}}
276 
277 
282 
283 grammar += """
284 VP[{"action": "answer-question"}] -> answer a question
285 """
286 
287 if __name__ == "__main__":
288  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
289 
290  from grammar_parser.cfgparser import CFGParser
291 
292  import sys
293  if sys.argv[1] == "object":
294  grammar_parser = CFGParser.fromstring(obj_grammar)
295  elif sys.argv[1] == "location":
296  grammar_parser = CFGParser.fromstring(loc_grammar)
297  elif sys.argv[1] == "full":
298  grammar_parser = CFGParser.fromstring(grammar)
299 
300  if len(sys.argv) > 2:
301  sentence = " ".join(sys.argv[2:])
302  else:
303  sentence = grammar_parser.get_random_sentence("T")
304 
305  print("Parsing sentence:\n\n{}\n\n".format(sentence))
306 
307  result = grammar_parser.parse("T", sentence)
308 
309  print("Result:\n\n{}".format(result))
310 
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156