robocup_knowledge
rwc2018/challenge_eegpsr.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 clearly and fluently? 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 clearly!",
10  "All this noise is messing with my audio. Try again."
11  ]
12 
13 initial_pose = "initial_pose"
14 starting_pose = "eegpsr_starting_point1"
15 exit_waypoint = "exit_3_rips"
16 
17 grammar_target = "T"
18 
19 
24 
25 grammar = """
26 T[A] -> COURTESY_PREFIX C[A] | C[A]
27 
28 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VPT[A3]
29 
30 VPT -> VP | VPS
31 
32 COURTESY_PREFIX -> robot please | could you | could you please
33 """
34 
35 
40 
41 grammar += """
42 PPN_OBJECT -> it
43 PPN_PERSON -> him | her
44 
45 DET -> the | a
46 NUMBER -> one | two | three
47 MEETING_PP -> at | in
48 MANIPULATION_PP -> on | to
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  grammar += "\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_entrance', 'type': 'waypoint'}}] -> %s at the entrance" % (
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" % (name, loc, name, loc)
74 
75 grammar += '\nLOCATION[{"id": "gpsr_entrance", "type": "waypoint"}] -> entrance'
76 
77 
82 
83 grammar += """
84 V_FIND -> find | locate | look for | pinpoint | spot
85 
86 TYPE_OR_CATEGORY -> NAMED_OBJECT | OBJECT_CATEGORY
87 UNNAMED_PERSON -> a person | someone
88 
89 VP[{"action": "find", "object": {'type': 'person'}}] -> V_FIND UNNAMED_PERSON
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] MEETING_PP the ROOM_OR_LOCATION[Y]
92 
93 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET TYPE_OR_CATEGORY[X] in the ROOM[Y]
94 
95 VP[{"action": "find"}] -> V_FIND DET object
96 VP[{"action": "find", "source-location": Y}] -> V_FIND DET object in the ROOM[Y]
97 
98 VP[{"action": "find", "object": X}] -> V_FIND DET TYPE_OR_CATEGORY[X]
99 """
100 
101 
102 # ##############################################################################
103 #
104 # Follow
105 #
106 # ##############################################################################
107 
108 grammar += """
109 V_FOLLOW -> come behind | come after | follow | go after | go behind
110 
111 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
112 """
113 
114 
119 
120 grammar += """
121 V_GUIDE -> guide | escort | take | lead | accompany | conduct
122 
123 VPS[{"action": "guide", "object": {"type": "reference"}}] -> V_GUIDE PPN_PERSON
124 VP[{"action": "guide", "target-location": Y, "object": {"type": "reference"}}] -> V_GUIDE PPN_PERSON to the ROOM_OR_LOCATION[Y]
125 """
126 
127 
128 
133 
134 grammar += """
135 V_GOTO -> go to | navigate to | enter to
136 
137 VP[{"action": "navigate-to", "target-location": X}] -> V_GOTO the ROOM_OR_LOCATION[X]
138 """
139 
140 
141 
146 
147 grammar += """
148 V_PICKUP -> get | grasp | take | pick up | grab | retrieve
149 
150 VP[{"action": "pick-up", "object": X}] -> V_PICKUP DET TYPE_OR_CATEGORY[X]
151 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET TYPE_OR_CATEGORY[X] from the LOCATION[Y]
152 """
153 
154 
159 
160 grammar += """
161 OPERATOR[{"type": "person", "id": "operator"}] -> me
162 BRING_NAME -> OPERATOR | NAMED_PERSON
163 
164 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
165 
166 V_BRING -> bring | deliver | give | hand over | hand
167 """
168 
169 grammar += """
170 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z]
171 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z] from the LOCATION[X]
172 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]
173 
174 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to PERSON_AT_LOCATION[Y]
175 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to OPERATOR[Y]
176 
177 VPS[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to PERSON_AT_LOCATION[X]
178 VPS[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to OPERATOR[X]
179 """
180 
181 
186 
187 grammar += """
188 V_PLACE -> put | place | leave | set
189 
190 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
191 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
192 
193 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_PLACE PPN_OBJECT on the LOCATION[X]
194 VP[{"action": "place", "object": {"type": "reference"}}] -> V_PLACE PPN_OBJECT to the ROOM
195 """
196 
197 
202 
203 grammar += """
204 V_SAY -> tell | say
205 V_SAY_UNDEFINED -> speak | say something
206 
207 VPS[{"action": "say"}] -> V_SAY_UNDEFINED
208 VPS[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
209 """
210 
211 grammar += '\nSAY_SENTENCE["time"] -> the time'
212 grammar += '\nSAY_SENTENCE["team_name"] -> your teams name'
213 grammar += '\nSAY_SENTENCE["country"] -> your teams country'
214 grammar += '\nSAY_SENTENCE["team_affiliation"] -> your teams affiliation'
215 grammar += '\nSAY_SENTENCE["day_of_month"] -> the day of the month'
216 grammar += '\nSAY_SENTENCE["day_of_week"] -> the day of the week'
217 grammar += '\nSAY_SENTENCE["today"] -> what day is today'
218 grammar += '\nSAY_SENTENCE["tomorrow"] -> what day is tomorrow'
219 grammar += '\nSAY_SENTENCE["joke"] -> a joke'
220 grammar += '\nSAY_SENTENCE["something_about_self"] -> something about yourself'
221 grammar += '\nSAY_SENTENCE["electric_sheep"] -> whether you dream or not on electric sheep'
222 
223 
228 
229 grammar += """
230 V_ANSWER_QUESTION -> answer a question
231 VPS[{"action": "answer-question"}] -> V_ANSWER_QUESTION
232 """
233 
234 
235 if __name__ == "__main__":
236  print("GPSR Grammar:\n\n{}\n\n".format(grammar))
237 
238  from grammar_parser.cfgparser import CFGParser
239 
240  import sys
241  grammar_parser = CFGParser.fromstring(grammar)
242 
243  if len(sys.argv) > 2:
244  sentence = " ".join(sys.argv[2:])
245  else:
246  sentence = grammar_parser.get_random_sentence("T")
247 
248  print("Parsing sentence:\n\n{}\n\n".format(sentence))
249 
250  result = grammar_parser.parse("T", sentence)
251 
252  print("Result:\n\n{}".format(result))
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156