robocup_knowledge
rgo2018/challenge_open.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 names = ['josja', 'lars', 'janno', 'loy', 'rein', 'kevin', 'ramon', 'max', 'matthijs', 'raphael']
7 
8 not_understood_sentences = [
9  "I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
10  "I am deeply sorry. Please try again, but wait for the ping!",
11  "You and I have communication issues. Speak up!",
12  "All this noise is messing with my audio. Try again"
13  ]
14 
15 initial_pose = "initial_pose_2"
16 starting_pose = "gpsr_meeting_point"
17 exit_waypoint = "gpsr_exit_door_2"
18 
19 grammar_target = "T"
20 
21 
26 
27 grammar = """
28 T[A] -> C[A]
29 
30 C[{"actions": <A1>}] -> VP[A1]
31 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
32 """
33 
34 
39 
40 grammar += """
41 V_GUIDE -> guide | escort | take | lead
42 
43 PPN_OBJECT -> it
44 PPN_PERSON -> him | her
45 
46 DET -> the | a | an | some
47 NUMBER -> one | two | three
48 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
49 """
50 
51 for room in common.location_rooms:
52  grammar += "\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
53 
54 for loc in common.get_locations():
55  grammar += '\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
56 
57 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
58 
59 for obj in common.object_names:
60  grammar += "\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
61 
62 for loc in common.get_locations(pick_location=True, place_location=True):
63  grammar += '\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
64 
65 for cat in common.object_categories:
66  grammar += "\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
67 
68 for name in names:
69  grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
70 
71 grammar += '\nLOCATION[{"id": "exit_4_rips", "type": "waypoint"}] -> door | exit | entrance'
72 
73 
74 
79 
80 grammar += """
81 V_FIND -> find | locate | look for
82 V_FIND_PERSON -> meet | V_FIND
83 
84 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
85 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man | NAMED_PERSON | someone
86 
87 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
88 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
89 
90 NEAR -> near | at
91 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] in the ROOM[Y]
92 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] NEAR the LOCATION[Y]
93 
94 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
95 VP[{"action": "find", "object": X}] -> V_FIND DET PERSON_TO_BE_FOUND[X]
96 
97 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
98 """
99 
100 
101 
102 
103 
108 
109 grammar += """
110 V_GOPL -> go to | navigate to
111 V_GOR -> V_GOPL | enter
112 
113 VP[{"action": "navigate-to", "target-location": X}] -> V_GOR the ROOM[X]
114 VP[{"action": "navigate-to", "target-location": X}] -> V_GOPL the LOCATION[X]
115 """
116 
117 
122 grammar += """
123 V_SEND_PICTURE -> check who is | show me who is
124 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE at the ROOM_OR_LOCATION[X]
125 """
126 
127 
128 
133 
134 grammar += """
135 V_PICKUP -> get | grasp | take | pick up | grab
136 
137 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
138 """
139 
140 
145 
146 grammar += """
147 V_PLACE -> put | place | set
148 
149 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
150 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
151 """
152 
153 
158 grammar += """
159 VP[{"action": "guide", "object": {"id": "reference", "type": "person"}, "target-location": Y}] -> V_GUIDE PPN_PERSON to the ROOM_OR_LOCATION[Y]
160 """
161 
162 
167 
168 grammar += """
169 V_FOLLOW -> follow | go after | come after
170 
171 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]
172 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]
173 
174 VP[{"action": "follow", "target": {"id": "operator"}}] -> V_FOLLOW me
175 VP[{"action": "follow", "target": {"id": "operator"}, "location-to": X}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X]
176 
177 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
178 VP[{"action": "follow", "target": {"type": "reference"}, "location-to": X}] -> V_FOLLOW PPN_PERSON to the ROOM_OR_LOCATION[X]
179 
180 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]
181 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]
182 
183 VP[{"action": "follow", "location-from": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X]
184 VP[{"action": "follow", "location-to": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X]
185 
186 VP[{"action": "follow", "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
187 """
188 
189 grammar += '\nFOLLOW_PERSONS[the person] -> DET person'
190 grammar += '\nFOLLOW_PERSONS[the woman] -> DET woman'
191 grammar += '\nFOLLOW_PERSONS[the man] -> DET man'
192 for name in names:
193  grammar += '\nFOLLOW_PERSONS[%s] -> %s' % (name, name)
194 
195 
200 
201 # BRING_TARGET[{"id": X, "type": person}] -> BRING_NAME[X]
202 
203 grammar += """
204 OPERATOR[{"type": "person", "id": "operator"}] -> me
205 BRING_NAME -> OPERATOR | BRING_PERSON
206 
207 BRING_TARGET[X] -> the ROOM_OR_LOCATION[X]
208 
209 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
210 
211 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over | place | put
212 
213 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]
214 
215 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_TARGET[X]
216 
217 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]
218 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z]
219 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]
220 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_PERSON[X]
221 VP[{"action": "hand-over", "target-location": X, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_PERSON[X]
222 """
223 
224 for name in names:
225  grammar += '\nBRING_PERSON[{"type": "person", "id": "%s"}] -> %s' % (name, name)
226  for loc in common.get_locations():
227  grammar += '\nBRING_PERSON[{"type": "person", "id": "%s", "location": %s}] -> %s MANIPULATION_AREA_DESCRIPTION the %s' % (name, loc, name, loc)
228 
229 
234 
235 grammar += """
236 V_SAY -> tell | say | speak
237 
238 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
239 """
240 
241 grammar += '\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
242 grammar += '\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
243 grammar += '\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
244 grammar += '\nSAY_SENTENCE["COUNTRY"] -> your teams country'
245 grammar += '\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
246 grammar += '\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
247 grammar += '\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
248 grammar += '\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
249 grammar += '\nSAY_SENTENCE["JOKE"] -> a joke'
250 grammar += '\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
251 
252 
253 
258 
259 grammar += """
260 VP[{"action": "answer-question"}] -> answer a question
261 """
262 
263 
268 
269 grammar += """
270 
271 HIM_HER -> him | her
272 
273 VP[{"action": "find", "object": {"type": "person", "id": Z}}] -> V_FIND MEET_PERSON[Z]
274 VP[{"action": "navigate-to"}] -> V_GUIDE HIM_HER
275 """
276 
277 grammar += '\nMEET_PERSON[the person] -> DET person'
278 grammar += '\nMEET_PERSON[the woman] -> DET woman'
279 grammar += '\nMEET_PERSON[the man] -> DET man'
280 for name in names:
281  grammar += '\nMEET_PERSON[%s] -> %s' % (name, name)
282 
283 # FOLLOW PERSON : (PERSON is at the BEACON)
284 # BRING me (a | some) CATEGORY : (which object of this category)
285 # DELIVER CATEGORY to PERSON : (which object of this category) && (PERSON is at the BEACON)
286 # meet PERSON(M) and GUIDE him : (PERSON is at the BEACON) && (guide him to BEACON)
287 # meet PERSON(F) and GUIDE her : (PERSON is at the BEACON) && (guide her to BEACON)
288 # NAVIGATE-TO BEACON, meet PERSON(M), and GUIDE him : (guide him to BEACON) && (keep him not lost)
289 # NAVIGATE-TO BEACON, meet PERSON(F), and GUIDE her : (guide her to BEACON) && (keep him not lost)
290 
291 loc_grammar = """
292 
293 HE_SHE -> he | she | it | him | her
294 
295 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]
296 """
297 
298 obj_grammar = """
299 
300 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]
301 """
302 
303 if __name__ == "__main__":
304  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
305 
306  from grammar_parser.cfgparser import CFGParser
307 
308  import sys
309  if sys.argv[1] == "object":
310  grammar_parser = CFGParser.fromstring(obj_grammar)
311  elif sys.argv[1] == "location":
312  grammar_parser = CFGParser.fromstring(loc_grammar)
313  elif sys.argv[1] == "full":
314  grammar_parser = CFGParser.fromstring(grammar)
315 
316  if len(sys.argv) > 2:
317  sentence = " ".join(sys.argv[2:])
318  else:
319  sentence = grammar_parser.get_random_sentence("T")
320 
321  print("Parsing sentence:\n\n{}\n\n".format(sentence))
322 
323  result = grammar_parser.parse("T", sentence)
324 
325  print("Result:\n\n{}".format(result))
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156