robocup_knowledge
rwc2023/challenge_gpsr.py
Go to the documentation of this file.
1 from robocup_knowledge import knowledge_loader
2 common = knowledge_loader.load_knowledge("common")
3 
4 not_understood_sentences = [
5  "I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
6  "I am deeply sorry. Please try again, but wait for the ping!",
7  "You and I have communication issues. Speak up!",
8  "All this noise is messing with my audio. Try again"
9  ]
10 
11 initial_pose = "initial_pose"
12 starting_pose = "gpsr_meeting_point"
13 exit_waypoint = "gpsr_exit_door_2"
14 
15 grammar_target = "T"
16 
17 
22 
23 grammar = """
24 T[A] -> C[A]
25 
26 C[{"actions": <A1>}] -> VP[A1]
27 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
28 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VP[A3]
29 """
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(manipulation_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 common.names:
67  grammar += "\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
68  for loc in common.get_locations():
69  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': %s}}] -> %s at the %s" % (name, loc, name, loc)
70 
71 grammar += '\nLOCATION[{"id": "gpsr_exit_door_1", "type": "waypoint"}] -> exit'
72 
73 
78 
79 grammar += """
80 V_FIND -> find | locate | look for
81 
82 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
83 UNNAMED_PERSON -> a person | someone
84 
85 VP[{"action": "find", "object": {'type': 'person'}}] -> V_FIND UNNAMED_PERSON
86 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y]
87 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
88 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM[Y]
89 
90 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MEETING_PP the ROOM_OR_LOCATION[Y]
91 
92 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
93 """
94 
95 
96 
101 
102 grammar += """
103 V_GOTO -> go to | navigate to
104 
105 VP[{"action": "navigate-to", "target-location": X}] -> V_GOTO the ROOM_OR_LOCATION[X]
106 """
107 
108 
113 
114 grammar += """
115 V_PICKUP -> get | grasp | take | pick up | grab
116 
117 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] from the LOCATION[Y]
118 """
119 
120 
125 
126 grammar += """
127 V_PLACE -> put | place
128 
129 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
130 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_PLACE PPN_OBJECT MANIPULATION_PP the LOCATION[X]
131 """
132 
133 
138 
139 grammar += """
140 OPERATOR[{"type": "person", "id": "operator"}] -> me
141 BRING_NAME -> OPERATOR | NAMED_PERSON
142 
143 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
144 
145 V_BRING -> bring | deliver | take | give | V_PICKUP
146 """
147 
148 # HAND OVER
149 
150 grammar += """
151 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z]
152 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z] from the LOCATION[X]
153 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]
154 
155 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to PERSON_AT_LOCATION[Y]
156 
157 
158 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to PERSON_AT_LOCATION[X]
159 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to OPERATOR[X]
160 """
161 
162 # PLACE
163 
164 grammar += """
165 VP[{"action": "place", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to the LOCATION[Y]
166 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]
167 """
168 
169 
174 
175 grammar += """
176 V_SAY -> tell | say
177 
178 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
179 VP[{"action": "say", "sentence": X, "object": Y}] -> V_SAY SAY_SENTENCE[X] to PERSON_AT_LOCATION[Y]
180 """
181 
182 grammar += '\nSAY_SENTENCE["time"] -> the time'
183 grammar += '\nSAY_SENTENCE["team_name"] -> your teams name'
184 grammar += '\nSAY_SENTENCE["country"] -> your teams country'
185 grammar += '\nSAY_SENTENCE["team_affiliation"] -> your teams affiliation'
186 grammar += '\nSAY_SENTENCE["day_of_month"] -> the day of the month'
187 grammar += '\nSAY_SENTENCE["day_of_week"] -> the day of the week'
188 grammar += '\nSAY_SENTENCE["today"] -> what day is today'
189 grammar += '\nSAY_SENTENCE["tomorrow"] -> what day is tomorrow'
190 grammar += '\nSAY_SENTENCE["joke"] -> a joke'
191 grammar += '\nSAY_SENTENCE["something_about_self"] -> something about yourself'
192 
193 
198 
199 grammar += """
200 V_ANSWER_QUESTION -> answer a question
201 VP[{"action": "answer-question"}] -> V_ANSWER_QUESTION
202 VP[{"action": "answer-question", "target-person": X}] -> V_ANSWER_QUESTION to NAMED_PERSON[X]
203 VP[{"action": "answer-question", "target-person": X}] -> V_ANSWER_QUESTION to PERSON_AT_LOCATION[X]
204 """
205 
206 
211 
212 grammar += """
213 VP[{"action": "tell-name-of-person", "location": X}] -> tell me the name of the person MEETING_PP the ROOM_OR_LOCATION[X]
214 VP[{"action": "count-and-tell", "object": X, "location": Y}] -> tell me how many NAMED_OBJECT[X] there are on the LOCATION[Y]
215 """
216 
217 
218 if __name__ == "__main__":
219  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
220 
221  from grammar_parser.cfgparser import CFGParser
222 
223  import sys
224  grammar_parser = CFGParser.fromstring(grammar)
225 
226  if len(sys.argv) > 2:
227  sentence = " ".join(sys.argv[2:])
228  else:
229  sentence = grammar_parser.get_random_sentence("T")
230 
231  print("Parsing sentence:\n\n{}\n\n".format(sentence))
232 
233  result = grammar_parser.parse("T", sentence)
234 
235  print("Result:\n\n{}".format(result))
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156