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