robocup_knowledge
rwc2018/challenge_final.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 """
20 
21 
26 female_names = ["josja"]
27 male_names = ["max", "lars", "rein", "rokus", "ramon", "loy", "sam", "henk", "matthijs", "lieve"]
28 names = female_names + male_names
29 
30 
35 
36 grammar += """
37 PPN_OBJECT -> it | them
38 PPN_PERSON -> him | her | them
39 
40 DET -> the
41 NUMBER -> one | two | three
42 MEETING_PP -> at | in
43 MANIPULATION_PP -> on
44 """
45 
46 for room in common.location_rooms:
47  grammar += "\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
48 
49 for loc in common.get_locations():
50  grammar += '\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
51 
52 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
53 
54 for obj in common.object_names:
55  grammar += "\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
56 
57 for loc in common.get_locations(pick_location=True, place_location=True):
58  grammar += '\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_PP the %s' % (loc, loc)
59 
60 for cat in common.object_categories:
61  grammar += "\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
62 
63 for name in names:
64  grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
65  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_entrance', 'type': 'waypoint'}}] -> %s at the entrance" % (
66  name, name)
67  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_exit_door', 'type': 'waypoint'}}] -> %s at the exit" % (
68  name, name)
69  for loc in common.get_locations():
70  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': %s}}] -> %s at the %s" % (
71  name, loc, name, loc)
72 
73 grammar += '\nLOCATION[{"id": "gpsr_exit_door", "type": "waypoint"}] -> exit'
74 grammar += '\nLOCATION[{"id": "gpsr_entrance", "type": "waypoint"}] -> entrance'
75 
76 
81 
82 grammar += """
83 V_FIND -> find | locate | look for
84 
85 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
86 UNNAMED_PERSON -> a person | someone
87 
88 VP[{"action": "find", "object": {'type': 'person'}}] -> V_FIND UNNAMED_PERSON
89 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y]
90 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
91 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM[Y]
92 
93 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
94 
95 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
96 """
97 
98 
99 
100 
105 
106 grammar += """
107 V_GOTO -> go to | navigate to
108 
109 VP[{"action": "navigate-to", "target-location": X}] -> V_GOTO the ROOM_OR_LOCATION[X]
110 """
111 
112 
117 
118 grammar += """
119 V_SEND_PICTURE -> check who is | show me who is
120 
121 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE at the ROOM_OR_LOCATION[X]
122 """
123 
124 
125 
130 
131 grammar += """
132 V_GUIDE -> guide
133 
134 VP[{"action": "guide-final-challenge", "object": {"type": "reference"}, "target-location": X}] -> guide him to the ROOM_OR_LOCATION[X]
135 """
136 
137 
142 
143 grammar += """
144 V_PICKUP -> get | grasp | take | pick up | grab
145 
146 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] from the LOCATION[Y]
147 """
148 
149 
154 
155 grammar += """
156 V_PLACE -> put | place
157 
158 VP[{"action": "put", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] on the LOCATION[Y]
159 """
160 
161 
166 
167 grammar += """
168 GOAL[open] -> open
169 GOAL[close] -> close
170 
171 SIDE[left] -> left
172 SIDE[right] -> right
173 VP[{"action": "gripper-goal", "side": X, "goal": Y}] -> GOAL[Y] your SIDE[X] gripper
174 """
175 
176 
177 
182 
183 grammar += """
184 VP[{"action": "clear-table"}] -> clear the dining_table
185 """
186 
187 
188 
193 
194 grammar += """
195 VP[{"action": "open-door", "door-location": "cupboard"}] -> open the door of the cupboard
196 """
197 
198 
199 
204 
205 grammar += """
206 OPERATOR[{"type": "person", "id": "operator"}] -> me
207 BRING_NAME -> OPERATOR | NAMED_PERSON
208 
209 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
210 
211 V_BRING -> bring
212 """
213 
214 
219 
220 grammar += """
221 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z]
222 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z] from the LOCATION[X]
223 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]
224 
225 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to PERSON_AT_LOCATION[Y]
226 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to OPERATOR[Y]
227 
228 
229 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to PERSON_AT_LOCATION[X]
230 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to OPERATOR[X]
231 """
232 
233 
238 
239 grammar += """
240 V_SAY -> tell | say
241 
242 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
243 VP[{"action": "say", "sentence": "party"}] -> lets get the party started
244 """
245 
246 grammar += '\nSAY_SENTENCE["time"] -> the time'
247 grammar += '\nSAY_SENTENCE["team_name"] -> your teams name'
248 grammar += '\nSAY_SENTENCE["country"] -> your teams country'
249 grammar += '\nSAY_SENTENCE["team_affiliation"] -> your teams affiliation'
250 grammar += '\nSAY_SENTENCE["day_of_month"] -> the day of the month'
251 grammar += '\nSAY_SENTENCE["day_of_week"] -> the day of the week'
252 grammar += '\nSAY_SENTENCE["today"] -> what day is today'
253 grammar += '\nSAY_SENTENCE["tomorrow"] -> what day is tomorrow'
254 grammar += '\nSAY_SENTENCE["joke"] -> a joke'
255 grammar += '\nSAY_SENTENCE["something_about_self"] -> something about yourself'
256 grammar += '\nSAY_SENTENCE["you_shall_not_pass"] -> you shall not pass'
257 
258 
259 if __name__ == "__main__":
260  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
261 
262  from grammar_parser.cfgparser import CFGParser
263 
264  import sys
265  grammar_parser = CFGParser.fromstring(grammar)
266 
267  if len(sys.argv) > 2:
268  sentence = " ".join(sys.argv[2:])
269  else:
270  sentence = grammar_parser.get_random_sentence("T")
271 
272  print("Parsing sentence:\n\n{}\n\n".format(sentence))
273 
274  result = grammar_parser.parse("T", sentence)
275 
276  print("Result:\n\n{}".format(result))
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156