1 from __future__
import print_function
3 from robocup_knowledge
import knowledge_loader
4 common = knowledge_loader.load_knowledge(
"common")
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"
13 initial_pose =
"initial_pose_2"
14 starting_pose =
"gpsr_meeting_point"
15 exit_waypoint =
"gpsr_exit_door_2"
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]
40 V_GUIDE -> guide | escort | take | lead | accompany | conduct
42 PPN_OBJECT -> it | them
43 PPN_PERSON -> him | her | them
45 DET -> the | a | an | some
46 NUMBER -> one | two | three
47 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
50 for room
in common.location_rooms:
51 grammar +=
"\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
54 grammar +=
'\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
56 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
58 for obj
in common.object_names:
59 grammar +=
"\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
62 grammar +=
'\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
64 for cat
in common.object_categories:
65 grammar +=
"\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
67 for name
in common.names:
68 grammar +=
"\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
70 grammar +=
'\nLOCATION[{"id": "gpsr_exit_door_1", "type": "waypoint"}] -> exit'
79 VP[{"action": "demo-presentation"}] -> introduce yourself | present yourself | perform a demonstration
89 V_FIND -> find | locate | look for | pinpoint | spot
90 V_FIND_PERSON -> meet | V_FIND
92 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
93 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man | NAMED_PERSON | someone
95 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
96 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
98 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] in the ROOM[Y]
99 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] near the LOCATION[Y]
101 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
102 VP[{"action": "find", "object": X}] -> V_FIND DET PERSON_TO_BE_FOUND[X]
114 V_GOPL -> go to | navigate to
115 V_GOR -> V_GOPL | enter to
117 VP[{"action": "navigate-to", "target-location": X}] -> V_GOR the ROOM[X]
118 VP[{"action": "navigate-to", "target-location": X}] -> V_GOPL the LOCATION[X]
129 VP[{"action": "inspect", "entity": X}] -> inspect the LOCATION[X]
139 V_PICKUP -> get | grasp | take | pick up | grab
141 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
151 V_PLACE -> put | place | set
153 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
154 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
164 V_FOLLOW -> follow | go after | come after | V_GUIDE
166 VP[{"action": "follow", "location-from": X, "location-to": Y, "target": {"id": "operator"}}] -> V_FOLLOW me from the ROOM_OR_LOCATION[X] to the ROOM_OR_LOCATION[Y]
167 VP[{"action": "follow", "location-to": X, "location-from": Y, "target": {"id": "operator"}}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X] from the ROOM_OR_LOCATION[Y]
169 VP[{"action": "follow", "target": {"id": "operator"}}] -> V_FOLLOW me
170 VP[{"action": "follow", "target": {"id": "operator"}, "location-to": X}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X]
172 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
173 VP[{"action": "follow", "target": {"type": "reference"}, "location-to": X}] -> V_FOLLOW PPN_PERSON to the ROOM_OR_LOCATION[X]
175 VP[{"action": "follow", "location-from": X, "location-to": Y, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X] to the ROOM_OR_LOCATION[Y]
176 VP[{"action": "follow", "location-to": X, "location-from": Y, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X] from the ROOM_OR_LOCATION[Y]
178 VP[{"action": "follow", "location-from": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X]
179 VP[{"action": "follow", "location-to": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X]
181 VP[{"action": "follow", "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
184 grammar +=
'\nFOLLOW_PERSONS[the person] -> DET person'
185 grammar +=
'\nFOLLOW_PERSONS[the woman] -> DET woman'
186 grammar +=
'\nFOLLOW_PERSONS[the man] -> DET man'
187 for name
in common.names:
188 grammar +=
'\nFOLLOW_PERSONS[%s] -> %s' % (name, name)
199 OPERATOR[{"type": "person", "id": "operator"}] -> me
200 BRING_NAME -> OPERATOR | BRING_PERSON
202 BRING_TARGET[X] -> the ROOM_OR_LOCATION[X]
204 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
206 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over | place | put
208 VP[{"action": "place", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X] to BRING_TARGET[Y] | V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_TARGET[Y] from the ROOM_OR_LOCATION[X]
210 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_TARGET[X]
212 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X] to BRING_NAME[Y] | V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_NAME[Y] from the ROOM_OR_LOCATION[X]
213 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z]
214 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X]
215 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_PERSON[X]
216 VP[{"action": "hand-over", "target-location": X, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_PERSON[X]
219 for name
in common.names:
220 grammar +=
'\nBRING_PERSON[{"type": "person", "id": "%s"}] -> %s' % (name, name)
222 grammar +=
'\nBRING_PERSON[{"type": "person", "id": "%s", "location": %s}] -> %s MANIPULATION_AREA_DESCRIPTION the %s' % (name, loc, name, loc)
231 V_SAY -> tell | say | speak
233 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
236 grammar +=
'\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
237 grammar +=
'\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
238 grammar +=
'\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
239 grammar +=
'\nSAY_SENTENCE["COUNTRY"] -> your teams country'
240 grammar +=
'\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
241 grammar +=
'\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
242 grammar +=
'\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
243 grammar +=
'\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
244 grammar +=
'\nSAY_SENTENCE["JOKE"] -> a joke'
245 grammar +=
'\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
248 follow_action =
"follow", {
"location-from": {
""},
"location-to": {},
"target": {}}
257 VP[{"action": "answer-question"}] -> answer a question
282 VP[{"action": "find", "object": {"type": "person", "id": Z}}] -> V_FIND MEET_PERSON[Z]
283 VP[{"action": "navigate-to"}] -> V_GUIDE HIM_HER
286 grammar +=
'\nMEET_PERSON[the person] -> DET person'
287 grammar +=
'\nMEET_PERSON[the woman] -> DET woman'
288 grammar +=
'\nMEET_PERSON[the man] -> DET man'
289 for name
in common.names:
290 grammar +=
'\nMEET_PERSON[%s] -> %s' % (name, name)
302 HE_SHE -> he | she | it | him | her
304 VP[{"object": {"id": X}}] -> HE_SHE is in the ROOM_OR_LOCATION[X] | in the ROOM_OR_LOCATION[X] | you could find HE_SHE in the ROOM_OR_LOCATION[X]
309 VP[{"object": {"id": Y}}] -> the NAMED_OBJECT[Z] is DET NAMED_OBJECT[Y] | the NAMED_OBJECT[Z] is NAMED_OBJECT[Y] | NAMED_OBJECT[Y] | DET NAMED_OBJECT[Y]
312 if __name__ ==
"__main__":
313 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
315 from grammar_parser.cfgparser
import CFGParser
318 if sys.argv[1] ==
"object":
319 grammar_parser = CFGParser.fromstring(obj_grammar)
320 elif sys.argv[1] ==
"location":
321 grammar_parser = CFGParser.fromstring(loc_grammar)
322 elif sys.argv[1] ==
"full":
323 grammar_parser = CFGParser.fromstring(grammar)
325 if len(sys.argv) > 2:
326 sentence =
" ".join(sys.argv[2:])
328 sentence = grammar_parser.get_random_sentence(
"T")
330 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
332 result = grammar_parser.parse(
"T", sentence)
334 print(
"Result:\n\n{}".format(result))