robocup_knowledge
rgo2019/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 spr = knowledge_loader.load_knowledge("challenge_spr")
6 
7 not_understood_sentences = [
8  "I'm so sorry! Can you please speak clearly and fluently? And wait for the ping!",
9  "I am deeply sorry. Please try again, but wait for the ping!",
10  "You and I have communication issues. Speak clearly!",
11  "All this noise is messing with my audio. Try again."
12  ]
13 
14 initial_pose = "gpsr_meeting_point"
15 starting_pose = "gpsr_meeting_point"
16 exit_waypoint = "exit_1_rips"
17 
18 grammar_target = "T"
19 
20 
25 
26 grammar = """
27 T[A] -> COURTESY_PREFIX C[A] | C[A]
28 
29 C[{"actions": <A1>}] -> VP[A1]
30 C[{"actions": <A1, A2>}] -> VP[A1] and VPT[A2]
31 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VPT[A3]
32 
33 VPT -> VP | VPS
34 
35 COURTESY_PREFIX -> robot please | could you | could you please | please
36 """
37 
38 
43 
44 grammar += """
45 PPN_OBJECT -> it
46 PPN_PERSON -> him | her
47 
48 OPERATOR_PROPERTY -> my
49 GEN_VERB -> may | can | will
50 
51 DET -> the | a
52 NUMBER -> one | two | three
53 MEETING_PP -> at | in
54 MANIPULATION_PP -> on | to
55 """
56 
57 for room in common.location_rooms:
58  grammar += "\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
59 
60 for loc in common.get_locations():
61  grammar += '\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
62 
63 grammar += '\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
64 
65 for obj in common.object_names:
66  grammar += "\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
67 
68 for loc in common.get_locations(pick_location=True, place_location=True):
69  grammar += '\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_PP the %s' % (loc, loc)
70 
71 for cat in common.object_categories:
72  grammar += "\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
73 
74 for name in common.names:
75  grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
76  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_entrance', 'type': 'waypoint'}}] -> %s at the entrance" % (
77  name, name)
78  for loc in common.get_locations():
79  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': %s}}] -> %s at the %s" % (name, loc, name, loc)
80 
81 grammar += '\nLOCATION[{"id": "gpsr_entrance", "type": "waypoint"}] -> entrance'
82 
83 
84 
89 
90 grammar += """
91 V_FIND -> find | locate | look for | pinpoint | spot | meet
92 
93 TYPE_OR_CATEGORY -> NAMED_OBJECT | OBJECT_CATEGORY
94 UNNAMED_PERSON -> a person | someone
95 
96 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
97 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] MEETING_PP the ROOM_OR_LOCATION[Y]
98 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET TYPE_OR_CATEGORY[X] in the ROOM[Y]
99 VP[{"action": "find"}] -> V_FIND DET NAMED_OBJECT
100 """
101 
102 
106 
107 # ##############################################################################
108 #
109 # Follow
110 #
111 # ##############################################################################
112 
113 grammar += """
114 V_FOLLOW -> come behind | come after | follow | go after | go behind
115 
116 VP[{"action": "follow", "target": X}] -> V_FOLLOW NAMED_PERSON[X]
117 VP[{"action": "follow", "target": X, "source-location": Y, "target-location": Z}] -> V_FOLLOW NAMED_PERSON[X] from DET ROOM_OR_LOCATION[Y] to DET ROOM_OR_LOCATION[Z]
118 VP[{"action": "follow", "target-location": Y, "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON to DET ROOM_OR_LOCATION[Y]
119 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
120 """
121 
123 
124 
129 
130 grammar += """
131 V_GUIDE -> guide | escort | take | lead | accompany | conduct
132 
133 VP[{"action": "guide", "object": X}] -> V_GUIDE NAMED_PERSON[X]
134 VP[{"action": "guide", "object": X, "target-location": Y}] -> V_GUIDE NAMED_PERSON[X] to the LOCATION[Y]
135 VP[{"action": "guide", "object": X, "source-location": Y, "target-location": Z}] -> V_GUIDE NAMED_PERSON[X] to the LOCATION[Z] you GEN_VERB find PPN_PERSON MEETING_PP the LOCATION[Y]
136 VP[{"action": "guide", "object": X, "source-location": Y, "target-location": Z}] -> V_GUIDE NAMED_PERSON[X] from the LOCATION[Y] to the LOCATION[Z]
137 VPS[{"action": "guide", "object": {"type": "reference"}}] -> V_GUIDE PPN_PERSON
138 VP[{"action": "guide", "target-location": Y, "object": {"type": "reference"}}] -> V_GUIDE PPN_PERSON to the ROOM_OR_LOCATION[Y]
139 """
140 
141 
142 
147 
148 grammar += """
149 V_GOTO -> go to | navigate to | enter to
150 
151 VP[{"action": "navigate-to", "target-location": X}] -> V_GOTO the ROOM_OR_LOCATION[X]
152 """
153 
154 
155 
160 
161 grammar += """
162 V_PICKUP -> get | grasp | take | pick up | grab | retrieve
163 
164 VP[{"action": "pick-up", "object": {"type": "reference"}, "source-location": Y}] -> V_PICKUP PPN_OBJECT from the LOCATION[Y]
165 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET TYPE_OR_CATEGORY[X] from the LOCATION[Y]
166 VP[{"action": "pick-up", "object": X}] -> V_PICKUP DET NAMED_OBJECT[X]
167 """
168 
170 
171 
176 
177 grammar += """
178 OPERATOR[{"type": "person", "id": "operator"}] -> me
179 BRING_NAME -> OPERATOR | NAMED_PERSON
180 
181 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
182 
183 V_BRING -> bring | deliver | give | hand over | hand | take
184 """
185 
186 grammar += """
187 
188 VP[{"action": "hand-over", "target-location": Y, "category": Z}] -> V_BRING OBJECT_CATEGORY[Z] to OPERATOR[Y]
189 VP[{"action": "hand-over", "target-location": Y, "category": Z}] -> V_BRING OPERATOR[Y] DET OBJECT_CATEGORY[Z]
190 
191 
192 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z]
193 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR_PROPERTY NAMED_OBJECT[Z] to the LOCATION[Y]
194 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to the LOCATION[Y]
195 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to OPERATOR[Y]
196 VPS[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to PERSON_AT_LOCATION[X]
197 VPS[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to OPERATOR[X]
198 """
199 
200 
207 
208 
214 
215 
216 
221 
222 grammar += """
223 V_PLACE -> put | place | leave | set
224 
225 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_PLACE PPN_OBJECT on the LOCATION[X]
226 """
227 
231 
232 
237 
238 grammar += """
239 V_SAY -> tell | say | ask
240 V_SAY_UNDEFINED -> speak | say something
241 
242 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
243 """
244 grammar += '\nSAY_SENTENCE["can you please leave"] -> PPN_PERSON to leave'
245 grammar += '\nSAY_SENTENCE["time"] -> the time'
246 grammar += '\nSAY_SENTENCE["team_name"] -> your teams name'
247 grammar += '\nSAY_SENTENCE["country"] -> your teams country'
248 grammar += '\nSAY_SENTENCE["team_affiliation"] -> your teams affiliation'
249 grammar += '\nSAY_SENTENCE["day_of_month"] -> the day of the month'
250 grammar += '\nSAY_SENTENCE["day_of_week"] -> the day of the week'
251 grammar += '\nSAY_SENTENCE["today"] -> what day is today'
252 grammar += '\nSAY_SENTENCE["tomorrow"] -> what day is tomorrow'
253 grammar += '\nSAY_SENTENCE["joke"] -> a joke'
254 grammar += '\nSAY_SENTENCE["something_about_self"] -> something about yourself'
255 
256 
258 
259 
264 
265 grammar += """
266 V_ANSWER_QUESTION -> answer a question
267 VP[{"action": "answer-question"}] -> V_ANSWER_QUESTION
268 """
269 
270 if __name__ == "__main__":
271  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
272 
273  from grammar_parser.cfgparser import CFGParser
274 
275  import sys
276  grammar_parser = CFGParser.fromstring(grammar)
277 
278  if len(sys.argv) > 2:
279  sentence = " ".join(sys.argv[2:])
280  else:
281  sentence = grammar_parser.get_random_sentence("T")
282 
283  print("Parsing sentence:\n\n{}\n\n".format(sentence))
284 
285  result = grammar_parser.parse("T", sentence)
286 
287  print("Result:\n\n{}".format(result))
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156