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]
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]
40 DET -> the | a | an | some
41 NUMBER -> one | two | three
42 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
45 for room
in common.location_rooms:
46 grammar +=
"\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
49 grammar +=
'\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
51 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
53 for obj
in common.object_names:
54 grammar +=
'\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
57 grammar +=
'\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
59 for cat
in common.object_categories:
60 grammar +=
'\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)
62 for name
in common.names:
63 grammar +=
'\nNAMED_PERSON[%s] -> %s' % (name, name)
72 V_PRESENT -> introduce yourself | present yourself | perform a demonstration | give a presentation
73 ENGLISH['en'] -> english
75 LANGUAGE[X] -> ENGLISH[X] | DUTCH[X]
76 VP["action": "demo-presentation", 'language': 'en'] -> V_PRESENT
77 VP["action": "demo-presentation", "language": X] -> V_PRESENT in LANGUAGE[X]
86 V_SEND_PICTURE -> check what is on | show me what is on
87 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE the ROOM_OR_LOCATION[X]
97 V_CLEAR -> clear | clean up | clean-up | empty
99 VP[{"action": "clear", "source-location": X, "target-location": {"id":"trashbin"}}] -> V_CLEAR the ROOM_OR_LOCATION[X]
100 VP[{"action": "clear", "source-location": X, "target-location": Y}] -> V_CLEAR the ROOM_OR_LOCATION[X] to the ROOM_OR_LOCATION[Y]
110 V_RETURN -> bye | no thank you | no bye | go away
112 VP[{"action": "navigate-to", "target-location": {"type":"waypoint", "id":"hero_home"}}] -> V_RETURN
122 V_FIND -> find | locate | look for | pinpoint | spot
123 V_FIND_PERSON -> meet | V_FIND
125 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
126 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man | someone | me
128 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
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": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
132 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] in the ROOM[Y]
133 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] near the LOCATION[Y]
134 VP[{"action": "find", "object": X}] -> V_FIND DET PERSON_TO_BE_FOUND[X]
144 V_GOPL -> go to | navigate to | drive to
146 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATION[X]
157 VP["action": "inspect", "entity": {"id": X}] -> inspect the LOCATION[X]
167 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
169 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over
171 VP["action": "place", "source-location": {"id": X}, "target-location": {"id": Y}, "object": {"type": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X] to the LOCATION[Y]
172 VP["action": "hand-over", "source-location": {"id": X}, "target-location": {"id": "operator"}, "object": {"type": Z}] -> V_BRING me OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X] | V_BRING OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X] to me
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["JOKE"] -> a joke'
202 if __name__ ==
"__main__":
203 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
205 from grammar_parser.cfgparser
import CFGParser
208 if sys.argv[1] ==
"object":
209 grammar_parser = CFGParser.fromstring(obj_grammar)
210 elif sys.argv[1] ==
"location":
211 grammar_parser = CFGParser.fromstring(loc_grammar)
212 elif sys.argv[1] ==
"full":
213 grammar_parser = CFGParser.fromstring(grammar)
215 if len(sys.argv) > 2:
216 sentence =
" ".join(sys.argv[2:])
218 sentence = grammar_parser.get_random_sentence(
"T")
220 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
222 result = grammar_parser.parse(
"T", sentence)
224 print(
"Result:\n\n{}".format(result))