1 from __future__
import print_function
3 from robocup_knowledge
import knowledge_loader
4 common = knowledge_loader.load_knowledge(
"common")
5 spr = knowledge_loader.load_knowledge(
"challenge_spr")
7 not_understood_sentences = [
8 "I'm so sorry! Can you please speak clearly and fluently? And wait for the ping!",
9 "I am deeply sorry. Please try again, but wait for the ping!",
10 "You and I have communication issues. Speak clearly!",
11 "All this noise is messing with my audio. Try again."
14 initial_pose =
"gpsr_meeting_point"
15 starting_pose =
"gpsr_meeting_point"
16 exit_waypoint =
"exit_1_rips"
27 T[A] -> COURTESY_PREFIX C[A] | C[A]
29 C[{"actions": <A1>}] -> VP[A1]
30 C[{"actions": <A1, A2>}] -> VP[A1] and VPT[A2]
31 C[{"actions": <A1, A2, A3>}] -> VP[A1] VP[A2] and VPT[A3]
35 COURTESY_PREFIX -> robot please | could you | could you please | please
46 PPN_PERSON -> him | her
48 OPERATOR_PROPERTY -> my
49 GEN_VERB -> may | can | will
52 NUMBER -> one | two | three
54 MANIPULATION_PP -> on | to
57 for room
in common.location_rooms:
58 grammar +=
"\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
61 grammar +=
'\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
63 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
65 for obj
in common.object_names:
66 grammar +=
"\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
69 grammar +=
'\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_PP the %s' % (loc, loc)
71 for cat
in common.object_categories:
72 grammar +=
"\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
74 for name
in common.names:
75 grammar +=
"\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
76 grammar +=
"\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_entrance', 'type': 'waypoint'}}] -> %s at the entrance" % (
79 grammar +=
"\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': %s}}] -> %s at the %s" % (name, loc, name, loc)
81 grammar +=
'\nLOCATION[{"id": "gpsr_entrance", "type": "waypoint"}] -> entrance'
91 V_FIND -> find | locate | look for | pinpoint | spot | meet
93 TYPE_OR_CATEGORY -> NAMED_OBJECT | OBJECT_CATEGORY
94 UNNAMED_PERSON -> a person | someone
96 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
97 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] MEETING_PP the ROOM_OR_LOCATION[Y]
98 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET TYPE_OR_CATEGORY[X] in the ROOM[Y]
99 VP[{"action": "find"}] -> V_FIND DET NAMED_OBJECT
114 V_FOLLOW -> come behind | come after | follow | go after | go behind
116 VP[{"action": "follow", "target": X}] -> V_FOLLOW NAMED_PERSON[X]
117 VP[{"action": "follow", "target": X, "source-location": Y, "target-location": Z}] -> V_FOLLOW NAMED_PERSON[X] from DET ROOM_OR_LOCATION[Y] to DET ROOM_OR_LOCATION[Z]
118 VP[{"action": "follow", "target-location": Y, "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON to DET ROOM_OR_LOCATION[Y]
119 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
131 V_GUIDE -> guide | escort | take | lead | accompany | conduct
133 VP[{"action": "guide", "object": X}] -> V_GUIDE NAMED_PERSON[X]
134 VP[{"action": "guide", "object": X, "target-location": Y}] -> V_GUIDE NAMED_PERSON[X] to the LOCATION[Y]
135 VP[{"action": "guide", "object": X, "source-location": Y, "target-location": Z}] -> V_GUIDE NAMED_PERSON[X] to the LOCATION[Z] you GEN_VERB find PPN_PERSON MEETING_PP the LOCATION[Y]
136 VP[{"action": "guide", "object": X, "source-location": Y, "target-location": Z}] -> V_GUIDE NAMED_PERSON[X] from the LOCATION[Y] to the LOCATION[Z]
137 VPS[{"action": "guide", "object": {"type": "reference"}}] -> V_GUIDE PPN_PERSON
138 VP[{"action": "guide", "target-location": Y, "object": {"type": "reference"}}] -> V_GUIDE PPN_PERSON to the ROOM_OR_LOCATION[Y]
149 V_GOTO -> go to | navigate to | enter to
151 VP[{"action": "navigate-to", "target-location": X}] -> V_GOTO the ROOM_OR_LOCATION[X]
162 V_PICKUP -> get | grasp | take | pick up | grab | retrieve
164 VP[{"action": "pick-up", "object": {"type": "reference"}, "source-location": Y}] -> V_PICKUP PPN_OBJECT from the LOCATION[Y]
165 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET TYPE_OR_CATEGORY[X] from the LOCATION[Y]
166 VP[{"action": "pick-up", "object": X}] -> V_PICKUP DET NAMED_OBJECT[X]
178 OPERATOR[{"type": "person", "id": "operator"}] -> me
179 BRING_NAME -> OPERATOR | NAMED_PERSON
181 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
183 V_BRING -> bring | deliver | give | hand over | hand | take
188 VP[{"action": "hand-over", "target-location": Y, "category": Z}] -> V_BRING OBJECT_CATEGORY[Z] to OPERATOR[Y]
189 VP[{"action": "hand-over", "target-location": Y, "category": Z}] -> V_BRING OPERATOR[Y] DET OBJECT_CATEGORY[Z]
192 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z]
193 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR_PROPERTY NAMED_OBJECT[Z] to the LOCATION[Y]
194 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to the LOCATION[Y]
195 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to OPERATOR[Y]
196 VPS[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to PERSON_AT_LOCATION[X]
197 VPS[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to OPERATOR[X]
223 V_PLACE -> put | place | leave | set
225 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_PLACE PPN_OBJECT on the LOCATION[X]
239 V_SAY -> tell | say | ask
240 V_SAY_UNDEFINED -> speak | say something
242 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
244 grammar +=
'\nSAY_SENTENCE["can you please leave"] -> PPN_PERSON to leave'
245 grammar +=
'\nSAY_SENTENCE["time"] -> the time'
246 grammar +=
'\nSAY_SENTENCE["team_name"] -> your teams name'
247 grammar +=
'\nSAY_SENTENCE["country"] -> your teams country'
248 grammar +=
'\nSAY_SENTENCE["team_affiliation"] -> your teams affiliation'
249 grammar +=
'\nSAY_SENTENCE["day_of_month"] -> the day of the month'
250 grammar +=
'\nSAY_SENTENCE["day_of_week"] -> the day of the week'
251 grammar +=
'\nSAY_SENTENCE["today"] -> what day is today'
252 grammar +=
'\nSAY_SENTENCE["tomorrow"] -> what day is tomorrow'
253 grammar +=
'\nSAY_SENTENCE["joke"] -> a joke'
254 grammar +=
'\nSAY_SENTENCE["something_about_self"] -> something about yourself'
266 V_ANSWER_QUESTION -> answer a question
267 VP[{"action": "answer-question"}] -> V_ANSWER_QUESTION
270 if __name__ ==
"__main__":
271 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
273 from grammar_parser.cfgparser
import CFGParser
276 grammar_parser = CFGParser.fromstring(grammar)
278 if len(sys.argv) > 2:
279 sentence =
" ".join(sys.argv[2:])
281 sentence = grammar_parser.get_random_sentence(
"T")
283 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
285 result = grammar_parser.parse(
"T", sentence)
287 print(
"Result:\n\n{}".format(result))