robocup_knowledge
rwc2018/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 grammar_target = "T"
7 
8 
13 
14 grammar = """
15 T[A] -> C[A]
16 
17 C[{"actions": <A1>}] -> VP[A1]
18 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
19 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VP[A3]
20 """
21 
22 
27 female_names = ["josja"]
28 male_names = ["max", "lars", "rein", "rokus", "ramon", "loy", "sam", "henk", "matthijs", "lieve"]
29 names = female_names + male_names
30 
31 
36 
37 grammar += """
38 V_GUIDE -> guide | escort | take | lead | accompany | conduct
39 
40 PPN_OBJECT -> it | them
41 PPN_PERSON -> him | her | them
42 
43 DET -> the
44 NUMBER -> one | two | three
45 MEETING_PP -> at | in
46 MANIPULATION_PP -> on
47 """
48 
49 for room in common.location_rooms:
50  grammar += "\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
51 
52 for loc in common.get_locations():
53  grammar += '\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
54 
55 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
56 
57 for obj in common.object_names:
58  grammar += "\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
59 
60 for loc in common.get_locations(pick_location=True, place_location=True):
61  grammar += '\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_PP the %s' % (loc, loc)
62 
63 for cat in common.object_categories:
64  grammar += "\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
65 
66 for name in names:
67  grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
68  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_entrance', 'type': 'waypoint'}}] -> %s at the entrance" % (
69  name, name)
70  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_exit_door', 'type': 'waypoint'}}] -> %s at the exit" % (
71  name, name)
72  for loc in common.get_locations():
73  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': %s}}] -> %s at the %s" % (
74  name, loc, name, loc)
75 
76 grammar += '\nLOCATION[{"id": "gpsr_exit_door", "type": "waypoint"}] -> exit'
77 grammar += '\nLOCATION[{"id": "gpsr_entrance", "type": "waypoint"}] -> entrance'
78 
79 
84 
85 grammar += """
86 V_FIND -> find | locate | look for
87 
88 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
89 UNNAMED_PERSON -> a person | someone
90 
91 VP[{"action": "find", "object": {'type': 'person'}}] -> V_FIND UNNAMED_PERSON
92 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y]
93 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
94 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM[Y]
95 
96 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
97 
98 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
99 """
100 
101 
102 
103 
108 
109 grammar += """
110 V_GOTO -> go to | navigate to
111 
112 VP[{"action": "navigate-to", "target-location": X}] -> V_GOTO the ROOM_OR_LOCATION[X]
113 """
114 
115 
120 
121 grammar += """
122 V_SEND_PICTURE -> check who is | show me who is
123 
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_GUIDE -> guide
136 
137 VP[{"action": "guide", "object": X, "target-location": Y, "source-location": Z}] -> V_GUIDE NAMED_PERSON[X] from the ROOM_OR_LOCATION[Z] to the ROOM_OR_LOCATION[Y]
138 """
139 
140 
145 
146 grammar += """
147 V_INSPECT -> inspect
148 
149 VP[{"action": "inspect", "object": X}] -> V_INSPECT the LOCATION[X]
150 """
151 
152 
157 
158 grammar += """
159 V_PICKUP -> get | grasp | take | pick up | grab
160 
161 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] from the LOCATION[Y]
162 """
163 
164 
169 
170 grammar += """
171 V_PLACE -> put | place
172 
173 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
174 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_PLACE PPN_OBJECT MANIPULATION_PP the LOCATION[X]
175 """
176 
177 
182 
183 grammar += """
184 OPERATOR[{"type": "person", "id": "operator"}] -> me
185 BRING_NAME -> OPERATOR | NAMED_PERSON
186 
187 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
188 
189 V_BRING -> bring | deliver | take | give | V_PICKUP
190 """
191 
192 # HAND OVER
193 
194 grammar += """
195 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z]
196 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z] from the LOCATION[X]
197 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING to PERSON_AT_LOCATION[Y] DET NAMED_OBJECT[Z] from the LOCATION[X]
198 
199 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to PERSON_AT_LOCATION[Y]
200 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to OPERATOR[Y]
201 
202 
203 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to PERSON_AT_LOCATION[X]
204 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to OPERATOR[X]
205 """
206 
207 # PLACE
208 
209 grammar += """
210 VP[{"action": "place", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to the LOCATION[Y]
211 VP[{"action": "place", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] from the LOCATION[X] to the LOCATION[Y]
212 """
213 
214 
219 
220 grammar += """
221 V_SAY -> tell | say
222 
223 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
224 VP[{"action": "say", "sentence": X, "object": Y}] -> V_SAY SAY_SENTENCE[X] to PERSON_AT_LOCATION[Y]
225 VP[{"action": "say", "sentence": "party"}] -> lets get the party started
226 """
227 
228 grammar += '\nSAY_SENTENCE["time"] -> the time'
229 grammar += '\nSAY_SENTENCE["team_name"] -> your teams name'
230 grammar += '\nSAY_SENTENCE["country"] -> your teams country'
231 grammar += '\nSAY_SENTENCE["team_affiliation"] -> your teams affiliation'
232 grammar += '\nSAY_SENTENCE["day_of_month"] -> the day of the month'
233 grammar += '\nSAY_SENTENCE["day_of_week"] -> the day of the week'
234 grammar += '\nSAY_SENTENCE["today"] -> what day is today'
235 grammar += '\nSAY_SENTENCE["tomorrow"] -> what day is tomorrow'
236 grammar += '\nSAY_SENTENCE["joke"] -> a joke'
237 grammar += '\nSAY_SENTENCE["something_about_self"] -> something about yourself'
238 grammar += '\nSAY_SENTENCE["you_shall_not_pass"] -> you shall not pass'
239 
240 
245 
246 grammar += """
247 V_ANSWER_QUESTION -> answer a question
248 VP[{"action": "answer-question"}] -> V_ANSWER_QUESTION
249 VP[{"action": "answer-question", "target-person": X}] -> V_ANSWER_QUESTION to NAMED_PERSON[X]
250 VP[{"action": "answer-question", "target-person": X}] -> V_ANSWER_QUESTION to PERSON_AT_LOCATION[X]
251 """
252 
253 
258 
259 grammar += """
260 VP[{"action": "tell-name-of-person", "location": X}] -> tell me the name of the person MEETING_PP the ROOM_OR_LOCATION[X]
261 VP[{"action": "count-and-tell", "object": X, "location": Y}] -> tell me how many NAMED_OBJECT[X] there are on the LOCATION[Y]
262 """
263 
264 
265 if __name__ == "__main__":
266  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
267 
268  from grammar_parser.cfgparser import CFGParser
269 
270  import sys
271  grammar_parser = CFGParser.fromstring(grammar)
272 
273  if len(sys.argv) > 2:
274  sentence = " ".join(sys.argv[2:])
275  else:
276  sentence = grammar_parser.get_random_sentence("T")
277 
278  print("Parsing sentence:\n\n{}\n\n".format(sentence))
279 
280  result = grammar_parser.parse("T", sentence)
281 
282  print("Result:\n\n{}".format(result))
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156