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"
14 starting_pose =
"gpsr_meeting_point"
15 exit_waypoint =
"gpsr_exit_door"
26 T[{actions : <A1>}] -> C[A1]
27 T[{actions : <A1, A2>}] -> C[A1] and C[A2]
28 T[{actions : <A1, A2, A3>}] -> C[A1] C[A2] and C[A3]
29 T[{actions : <A1, A2, A3, A4>}] -> C[A1] C[A2] and C[A3] C[A4]
30 T[{actions : <A1, A2, A3, A4>}] -> C[A1] C[A2] C[A3] and C[A4]
42 PPN_OBJECT["reference"] -> it | them
43 PPN_PERSON["reference"] -> him | her | them | it
45 DET -> the | a | an | some
46 NUMBER -> one | two | three
47 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
49 ROOM["exit_area"] -> exit
52 for room
in common.location_rooms:
53 grammar +=
'\nROOM[%s] -> %s' % (room, room)
56 grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
58 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
60 for obj
in common.object_names:
61 grammar +=
'\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
64 grammar +=
'\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
66 for cat
in common.object_categories:
67 grammar +=
'\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)
69 for name
in common.names:
70 grammar +=
'\nNAMED_PERSON[%s] -> %s' % (name, name)
80 V_FIND -> find | locate | look for
82 PERSON_TO_BE_FOUND -> NAMED_PERSON
84 VP["action": "find", "object": {"type": X}] -> V_FIND DET NAMED_OBJECT[X]
85 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y] | V_FIND DET NAMED_OBJECT[X] in the ROOM_OR_LOCATION[Y]
87 VP["action": "find", "object": {"type": person, "id": X}] -> V_FIND NAMED_PERSON[X]
88 VP["action": "find", "object": {"type": "person", "id": X}, "location": {"id": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM_OR_LOCATION[Y]
99 V_GUIDE -> guide | escort | take
101 VP["action": "guide", "object": {"id": X}] -> V_GUIDE PPN_PERSON[Y] to the ROOM_OR_LOCATION[X]
103 V_GOPL -> go to | navigate to
104 V_GOR -> V_GOPL | enter to | enter
106 VP["action": "navigate-to", "object": {"id": X}] -> V_GOR the ROOM[X]
107 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATION[X]
118 V_PICKUP -> get | grasp | take | pick up | grab
120 VP["action": "pick-up", "object": {"type": X}, "location": {"id": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
131 V_PLACE -> put | place
133 VP["action": "place", "object": {"type": X}, "location": {"id": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
145 VP["action": "follow", "target": {"type": X}] -> V_FOLLOW PPN_PERSON[X]
155 for room
in common.location_rooms:
156 grammar +=
'\nBRING_ROOM[{"type": room, "id": %s}] -> %s' % (room, room)
159 grammar +=
'\nBRING_LOCATION[{"type": furniture, "id": %s}] -> %s' % (loc, loc)
161 grammar +=
'\n BRING_ROOM_OR_LOCATION[X] -> BRING_ROOM[X] | BRING_LOCATION[X]'
166 BRING_PERSON_AT_LOCATION[{"type": person, "id": X, "loc": Y}] -> NAMED_PERSON[X] INAT the ROOM_OR_LOCATION[Y]
167 BRING_OPERATOR[{"type": person, "id": operator}] -> me
168 BRING_PERSON -> BRING_OPERATOR | BRING_PERSON_AT_LOCATION
170 BRING_TARGET[X] -> BRING_PERSON[X] | the BRING_LOCATION[X]
172 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT | PPN_OBJECT
174 V_BRING -> bring | deliver | give | hand
184 VP["action": "bring", "source-location": X, "target-location": Y, "object": {"type": 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]
189 VP["action": "bring", "target-location": Y, "object": {"type": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_TARGET[Y] | V_BRING BRING_PERSON[Y] OBJECT_TO_BE_BROUGHT[Z] | V_BRING OBJECT_TO_BE_BROUGHT[Z] on BRING_TARGET[Y]
194 VP["action": "bring", "source-location": X, "target-location": Y, "object": {"type": Z}] -> V_BRING to BRING_TARGET[Y] OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X]
198 VP["action": "bring", "object": {"type": Z}, "target-location": Y] -> V_PLACE OBJECT_TO_BE_BROUGHT[Z] MANIPULATION_AREA_DESCRIPTION the BRING_LOCATION[Y]
211 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
212 VP["action": "say", "sentence": X, "target-person": Y] -> V_SAY SAY_SENTENCE[X] to BRING_PERSON_AT_LOCATION[Y]
213 VP["action": "say", "sentence": "DARK_SIDE"] -> join the dark side
216 grammar +=
'\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
217 grammar +=
'\nSAY_SENTENCE["TEAM_NAME"] -> the name of your team'
218 grammar +=
'\nSAY_SENTENCE["TEAM_COUNTRY"] -> your teams country'
219 grammar +=
'\nSAY_SENTENCE["TEAM_AFFILIATION"] -> your teams affiliation'
220 grammar +=
'\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
221 grammar +=
'\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
222 grammar +=
'\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
223 grammar +=
'\nSAY_SENTENCE["TODAY"] -> what day is today'
224 grammar +=
'\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
225 grammar +=
'\nSAY_SENTENCE["JOKE"] -> a joke'
226 grammar +=
'\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
236 VP["action": "answer-question"] -> answer a question
240 if __name__ ==
"__main__":
241 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
243 from grammar_parser.cfgparser
import CFGParser
245 grammar_parser = CFGParser.fromstring(grammar)
247 sentence = grammar_parser.get_random_sentence(
"T")
249 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
251 result = grammar_parser.parse(
"T", sentence)
253 print(
"Result:\n\n{}".format(result))
262 question_grammar_target =
"T"
264 question_grammar =
"""
265 T[{actions : <A1>}] -> C[A1]
271 question_grammar +=
'''
273 WHATWHICH -> what | which
275 BIGGEST_ADJ -> biggest | heaviest
276 SMALLEST_ADJ -> smallest | lightest
278 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ object
279 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ object
280 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ food
281 Q["action" : "answer", "solution": "onion"] -> WHATWHICH is the SMALLEST_ADJ food
282 Q["action" : "answer", "solution": "plate"] -> WHATWHICH is the BIGGEST_ADJ container
283 Q["action" : "answer", "solution": "soup_container"] -> WHATWHICH is the SMALLEST_ADJ container
284 Q["action" : "answer", "solution": "green_tea"] -> WHATWHICH is the BIGGEST_ADJ drink
285 Q["action" : "answer", "solution": "coke"] -> WHATWHICH is the SMALLEST_ADJ drink
286 Q["action" : "answer", "solution": "hair_spray"] -> WHATWHICH is the BIGGEST_ADJ cleaning stuff
287 Q["action" : "answer", "solution": "moisturizer"] -> WHATWHICH is the SMALLEST_ADJ cleaning stuff
288 Q["action" : "answer", "solution": "spoon"] -> WHATWHICH is the BIGGEST_ADJ cutlery
289 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ cutlery
291 Q["action" : "answer", "solution": "the bedroom has one door"] -> how many doors has the bedroom
292 Q["action" : "answer", "solution": "the entrance has one door"] -> how many doors has the entrance
293 Q["action" : "answer", "solution": "the living room has one door"] -> how many doors has the living_room
294 Q["action" : "answer", "solution": "the kitchen has one door"] -> how many doors has the kitchen
295 Q["action" : "answer", "solution": "the corridor has zero doors"] -> how many doors has the corridor
296 Q["action" : "answer", "solution": "the balcony has zero doors"] -> how many doors has the balcony