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",
15 starting_pose = [
"gpsr_meeting_point_1",
16 "gpsr_meeting_point_2"]
17 exit_waypoint = [
"gpsr_exit_door_1",
30 T[{actions : <A1>}] -> C[A1]
31 T[{actions : <A1, A2>}] -> C[A1] and C[A2]
32 T[{actions : <A1, A2, A3>}] -> C[A1] C[A2] and C[A3]
44 V_GUIDE -> guide | escort | take | lead | accompany
46 DET -> the | a | an | some
47 MANIPULATION_AREA_DESCRIPTIONS -> on top of | at | in | on
50 for room
in common.location_rooms:
51 grammar +=
'\nROOMS[%s] -> %s' % (room, room)
53 grammar +=
'\nLOCATIONS[%s] -> %s' % (loc, loc)
54 grammar +=
'\n ROOMS_AND_LOCATIONS[X] -> ROOMS[X] | LOCATIONS[X]'
55 for obj
in common.object_names:
56 grammar +=
'\nOBJECT_NAMES[%s] -> %s' % (obj, obj)
58 grammar +=
'\nMANIPULATION_AREA_LOCATIONS[%s] -> MANIPULATION_AREA_DESCRIPTIONS the %s' % (loc, loc)
59 for cat
in common.object_categories:
60 grammar +=
'\nOBJECT_NAMES[%s] -> %s' % (cat, cat)
69 V_FIND -> find | locate | look for | meet
71 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_NAMES[X] in the ROOMS[Y]
72 VP["action": "find", "object": {"type": "person"}, "location": {"id": Y}] -> V_FIND FIND_PERSONS in the ROOMS[Y]
73 VP["action": "find", "object": {"type": "person"}, "location": {"id": Y}] -> V_FIND FIND_PERSONS near the LOCATIONS[Y]
74 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_NAMES[X] MANIPULATION_AREA_LOCATIONS[Y]
77 grammar +=
'\nFIND_PERSONS -> DET person'
78 grammar +=
'\nFIND_PERSONS -> DET women'
79 grammar +=
'\nFIND_PERSONS -> DET man'
80 for name
in common.names:
81 grammar +=
'\nFIND_PERSONS -> %s' % name
90 V_GOPL -> go to | navigate to
91 V_GOR -> V_GOPL | enter
93 VP["action": "navigate-to", "object": {"id": X}] -> V_GOR the ROOMS[X]
94 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATIONS[X]
104 V_PICKUP -> get | grasp | take | pick up
106 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_PICKUP DET OBJECT_NAMES[X] MANIPULATION_AREA_LOCATIONS[Y]
116 V_PLACE -> put | place
118 VP["action": "place", "object": {"type": X}, "location": {"id": Y}] -> V_PLACE DET OBJECT_NAMES[X] MANIPULATION_AREA_LOCATIONS[Y]
128 V_FOLLOW -> follow | go after | come after | V_GUIDE
130 VP["action": "follow", "location-from": {"id": X}, "location-to": {"id": Y}, "target": {"id": "operator"}] -> V_FOLLOW me from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y]
131 VP["action": "follow", "location-to": {"id": X}, "location-from": {"id": Y}, "target": {"id": "operator"}] -> V_FOLLOW me to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y]
133 VP["action": "follow", "location-to": {"id": X}, "target": {"id": "operator"}] -> V_FOLLOW me to the ROOMS_AND_LOCATIONS[X]
134 VP["action": "follow", "target": {"id": "operator"}] -> V_FOLLOW me
136 VP["action": "follow", "location-from": {"id": X}, "location-to": {"id": Y}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y]
137 VP["action": "follow", "location-to": {"id": X}, "location-from": {"id": Y}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y]
139 VP["action": "follow", "location-from": {"id": X}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOMS_AND_LOCATIONS[X]
140 VP["action": "follow", "location-to": {"id": X}, "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOMS_AND_LOCATIONS[X]
142 VP["action": "follow", "target": {"id": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
145 grammar +=
'\nFOLLOW_PERSONS[the person] -> DET person'
146 grammar +=
'\nFOLLOW_PERSONS[the woman] -> DET woman'
147 grammar +=
'\nFOLLOW_PERSONS[the man] -> DET man'
148 for name
in common.names:
149 grammar +=
'\nFOLLOW_PERSONS[%s] -> %s' % (name, name)
158 V_BRING -> bring | deliver | take | carry | transport
159 V_BRING_PERSON -> V_BRING | give | hand | hand over
161 VP["action": "bring", "source-location": {"id": X}, "target-location": {"id": Y}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y] | V_BRING OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to the ROOMS_AND_LOCATIONS[Y]
162 VP["action": "bring", "target-location": {"id": X}, "source-location": {"id": Y}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y] | V_BRING OBJECT_NAMES[Z] to the ROOMS_AND_LOCATIONS[X] from the ROOMS_AND_LOCATIONS[Y]
164 VP["action": "bring", "source-location": {"id": X}, "target-location": {"type": "person"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to BRING_PERSONS | V_BRING DET OBJECT_NAMES[Z] to BRING_PERSONS from the ROOMS_AND_LOCATIONS[X] | V_BRING OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to BRING_PERSONS | V_BRING OBJECT_NAMES[Z] to BRING_PERSONS from the ROOMS_AND_LOCATIONS[X]
165 VP["action": "bring", "target-location": {"type": "person"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] to BRING_PERSONS | V_BRING OBJECT_NAMES[Z] to BRING_PERSONS
167 VP["action": "bring", "source-location": {"id": X}, "target-location": {"type": "person", "id": "operator"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to me | V_BRING me DET OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] | V_BRING OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X] to me | V_BRING me OBJECT_NAMES[Z] from the ROOMS_AND_LOCATIONS[X]
168 VP["action": "bring", "target-location": {"type": "person", "id": "operator"}, "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] to me | V_BRING me DET OBJECT_NAMES[Z] | V_BRING OBJECT_NAMES[Z] to me | V_BRING me OBJECT_NAMES[Z]
169 VP["action": "bring", "object": {"type": Z}] -> V_BRING DET OBJECT_NAMES[Z] | V_BRING OBJECT_NAMES[Z]
172 for name
in common.names:
173 grammar +=
'\nBRING_PERSONS -> %s' % name
182 V_SAY -> tell | say | speak
184 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
187 grammar +=
'\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
188 grammar +=
'\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
189 grammar +=
'\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
190 grammar +=
'\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
191 grammar +=
'\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
192 grammar +=
'\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
193 grammar +=
'\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
196 follow_acton =
"follow", {
"location-from": {
""},
"location-to": {},
"target": {}}
208 VP["action": "find", "object": {"type": "person"}, "target": {"id": Z}] -> V_FIND MEET_PERSON[Z]
209 VP["action": "navigate-to"] -> V_GUIDE HIM_HER
212 grammar +=
'\nMEET_PERSON[the person] -> DET person'
213 grammar +=
'\nMEET_PERSON[the woman] -> DET woman'
214 grammar +=
'\nMEET_PERSON[the man] -> DET man'
215 for name
in common.names:
216 grammar +=
'\nMEET_PERSON[%s] -> %s' % (name, name)
228 HE_SHE -> he | she | it | him | her
230 VP["object": {"id": X}] -> HE_SHE is in the ROOMS_AND_LOCATIONS[X] | in the ROOMS_AND_LOCATIONS[X] | you could find HE_SHE in the ROOMS_AND_LOCATIONS[X]
235 VP["object": {"id": Y}] -> the OBJECT_NAMES[Z] is DET OBJECT_NAMES[Y] | the OBJECT_NAMES[Z] is OBJECT_NAMES[Y] | OBJECT_NAMES[Y] | DET OBJECT_NAMES[Y]
238 if __name__ ==
"__main__":
239 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
241 from grammar_parser.cfgparser
import CFGParser
244 if sys.argv[1] ==
"object":
245 grammar_parser = CFGParser.fromstring(obj_grammar)
246 elif sys.argv[1] ==
"location":
247 grammar_parser = CFGParser.fromstring(loc_grammar)
248 elif sys.argv[1] ==
"full":
249 grammar_parser = CFGParser.fromstring(grammar)
251 if len(sys.argv) > 2:
252 sentence =
" ".join(sys.argv[2:])
254 sentence = grammar_parser.get_random_sentence(
"T")
256 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
258 result = grammar_parser.parse(
"T", sentence)
260 print(
"Result:\n\n{}".format(result))