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 =
"hero_home"
24 T[A] -> C[A] | COURTESY C[A] | C[A] COURTESY | COURTESY C[A] COURTESY
26 COURTESY -> please | robot please | could you | would you | hero | hero please
27 C[{"actions": <A1>}] -> VP[A1]
28 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
29 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VP[A3]
39 PPN_OBJECT -> it | them
40 PPN_PERSON -> him | her | them
42 DET -> the | a | an | some
43 NUMBER -> one | two | three
44 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
47 for room
in common.location_rooms:
48 grammar +=
"\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
51 grammar +=
'\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
53 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
55 for obj
in common.object_names:
56 grammar +=
"\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
59 grammar +=
'\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
61 for cat
in common.object_categories:
62 grammar +=
"\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
64 for name
in common.names:
65 grammar +=
"\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
74 VP[{"action": "demo-presentation"}] -> introduce yourself | present yourself | perform a demonstration
83 V_SEND_PICTURE -> check what is | show me what is | send me a picture of
84 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE MANIPULATION_AREA_DESCRIPTION the LOCATION[X]
85 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE the LOCATION[X]
96 V_CLEAR -> clear | clean up | clean-up | empty
98 VP[{"action": "clear", "source-location": X, "target-location": {"id":"trashbin"}}] -> V_CLEAR the ROOM_OR_LOCATION[X]
99 VP[{"action": "clear", "source-location": X, "target-location": Y}] -> V_CLEAR the ROOM_OR_LOCATION[X] to the ROOM_OR_LOCATION[Y]
109 V_RETURN -> bye | no thank you | no bye | go away
111 VP[{"action": "navigate-to", "target-location": {"type":"waypoint", "id":"hero_home"}}] -> V_RETURN
121 V_FIND -> find | locate | look for | pinpoint | spot
122 V_FIND_PERSON -> meet | V_FIND
124 DEMO_HACK -> of apartment 11 | of appartment 11
125 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
126 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man
127 UNNAMED_PERSON -> a person | someone | me
129 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
130 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y]
131 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y] DEMO_HACK
132 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM[Y]
134 VP[{"action": "find", "object": {'type': 'person'}}] -> V_FIND UNNAMED_PERSON
135 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
136 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
149 V_GOPL -> go to | navigate to
150 V_GOR -> V_GOPL | enter to
152 VP[{"action": "navigate-to", "target-location": X}] -> V_GOR the ROOM[X]
153 VP[{"action": "navigate-to", "target-location": X}] -> V_GOPL the LOCATION[X]
164 VP[{"action": "inspect", "entity": X}] -> inspect the LOCATION[X]
174 V_PICKUP -> get | grasp | take | pick up | grab
176 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
186 V_PLACE -> put | place | set
188 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
189 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
199 V_FOLLOW -> follow | go after | come after | V_GUIDE
201 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]
202 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]
204 VP[{"action": "follow", "target": {"id": "operator"}}] -> V_FOLLOW me
205 VP[{"action": "follow", "target": {"id": "operator"}, "location-to": X}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X]
207 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
208 VP[{"action": "follow", "target": {"type": "reference"}, "location-to": X}] -> V_FOLLOW PPN_PERSON to the ROOM_OR_LOCATION[X]
210 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]
211 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]
213 VP[{"action": "follow", "location-from": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X]
214 VP[{"action": "follow", "location-to": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X]
216 VP[{"action": "follow", "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
219 grammar +=
'\nFOLLOW_PERSONS[the person] -> DET person'
220 grammar +=
'\nFOLLOW_PERSONS[the woman] -> DET woman'
221 grammar +=
'\nFOLLOW_PERSONS[the man] -> DET man'
232 OPERATOR[{"id": "operator"}] -> me
233 BRING_NAME -> OPERATOR | BRING_PERSON
235 BRING_TARGET[X] -> the ROOM_OR_LOCATION[X]
237 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
239 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over | place | put
241 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]
243 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_TARGET[X]
245 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]
246 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z]
247 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]
248 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_PERSON[X]
249 VP[{"action": "hand-over", "target-location": X, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_PERSON[X]
258 V_SAY -> tell | say | speak
260 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
263 grammar +=
'\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
264 grammar +=
'\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
265 grammar +=
'\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
266 grammar +=
'\nSAY_SENTENCE["COUNTRY"] -> your teams country'
267 grammar +=
'\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
268 grammar +=
'\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
269 grammar +=
'\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
270 grammar +=
'\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
271 grammar +=
'\nSAY_SENTENCE["JOKE"] -> a joke'
272 grammar +=
'\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
275 follow_action =
"follow", {
"location-from": {
""},
"location-to": {},
"target": {}}
284 VP[{"action": "answer-question"}] -> answer a question
287 if __name__ ==
"__main__":
288 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
290 from grammar_parser.cfgparser
import CFGParser
293 if sys.argv[1] ==
"object":
294 grammar_parser = CFGParser.fromstring(obj_grammar)
295 elif sys.argv[1] ==
"location":
296 grammar_parser = CFGParser.fromstring(loc_grammar)
297 elif sys.argv[1] ==
"full":
298 grammar_parser = CFGParser.fromstring(grammar)
300 if len(sys.argv) > 2:
301 sentence =
" ".join(sys.argv[2:])
303 sentence = grammar_parser.get_random_sentence(
"T")
305 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
307 result = grammar_parser.parse(
"T", sentence)
309 print(
"Result:\n\n{}".format(result))