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]
40 PPN_OBJECT[reference] -> it | them
41 PPN_PERSON -> him | her | them
43 DET -> the | a | an | some
44 NUMBER -> one | two | three
45 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
48 for room
in common.location_rooms:
49 grammar +=
'\nROOM[%s] -> %s' % (room, room)
52 grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
54 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
56 for obj
in common.object_names:
57 grammar +=
'\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
60 grammar +=
'\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
62 for cat
in common.object_categories:
63 grammar +=
'\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)
65 for name
in common.names:
66 grammar +=
'\nNAMED_PERSON[%s] -> %s' % (name, name)
75 V_FIND -> find | locate | look for | meet
77 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
78 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man | NAMED_PERSON | someone
80 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
81 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
83 VP["action": "find", "object": {"type": "person", "id": X}, "location": {"id": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] in the ROOM[Y]
84 VP["action": "find", "object": {"type": "person", "id": X}, "location": {"id": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] near the LOCATION[Y]
86 VP["action": "find", "object": {"type": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
87 VP["action": "find", "object": {"type": person, "id": X}] -> V_FIND DET PERSON_TO_BE_FOUND[X]
97 V_GOPL -> go to | navigate to
98 V_GOR -> V_GOPL | enter
100 VP["action": "navigate-to", "object": {"id": X}] -> V_GOR the ROOM[X]
101 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATION[X]
111 V_PICKUP -> get | grasp | take | pick up | grab
113 VP["action": "pick-up", "object": {"type": X}, "location": {"id": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
123 V_PLACE -> put | place
125 VP["action": "place", "object": {"type": "reference"}, "location": {"id": Y}] -> V_PLACE PPN_OBJECT MANIPULATION_AREA_LOCATION[Y]
134 for room
in common.location_rooms:
135 grammar +=
'\nBRING_ROOM[{"type": room, "id": %s}] -> %s' % (room, room)
138 grammar +=
'\nBRING_LOCATION[{"type": furniture, "id": %s}] -> %s' % (loc, loc)
140 grammar +=
'\n BRING_ROOM_OR_LOCATION[X] -> BRING_ROOM[X] | BRING_LOCATION[X]'
145 BRING_PERSON_AT_LOCATION[{"type": person, "id": X, "loc": Y}] -> NAMED_PERSON[X] INAT the ROOM_OR_LOCATION[Y]
146 BRING_OPERATOR[{"type": person, "id": operator}] -> me
147 BRING_PERSON -> BRING_OPERATOR | BRING_PERSON_AT_LOCATION
149 BRING_TARGET[X] -> BRING_PERSON[X] | the BRING_LOCATION[X]
151 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT | PPN_OBJECT
153 V_BRING -> bring | deliver | take | give | get
159 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]
164 VP["action": "bring", "target-location": Y, "object": {"type": Z}] -> V_BRING to BRING_TARGET[Y] OBJECT_TO_BE_BROUGHT[Z] | V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_TARGET[Y] | V_BRING BRING_PERSON[Y] OBJECT_TO_BE_BROUGHT[Z]
169 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] | V_BRING BRING_TARGET[Y] OBJECT_TO_BE_BROUGHT[Z] from the ROOM_OR_LOCATION[X]
174 VP["action": "bring", "object": {"type": Z}, "target-location": Y] -> V_PLACE OBJECT_TO_BE_BROUGHT[Z] MANIPULATION_AREA_DESCRIPTION the BRING_LOCATION[Y]
185 V_SAY -> tell | say | speak
187 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
188 VP["action": "say", "sentence": X, "target-person": Y] -> V_SAY SAY_SENTENCE[X] to BRING_PERSON_AT_LOCATION[Y]
191 grammar +=
'\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
192 grammar +=
'\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
193 grammar +=
'\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
194 grammar +=
'\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
195 grammar +=
'\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
196 grammar +=
'\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
197 grammar +=
'\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
198 grammar +=
'\nSAY_SENTENCE["JOKE"] -> a joke'
199 grammar +=
'\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
202 follow_action =
"follow", {
"location-from": {
""},
"location-to": {},
"target": {}}
211 VP["action": "answer-question"] -> answer a question
212 VP["action": "answer-question", "target-person": X] -> answer a question to BRING_PERSON_AT_LOCATION[X]
222 PROPERTY["number"] -> number
223 PROPERTY["name"] -> name
225 INVESTIGATION_LOCATION[X] -> MANIPULATION_AREA_LOCATION[X] | in the ROOM
227 VP["action": "find-out-and-report", "property": X, "object": {"type": Y}] -> tell me the PROPERTY[X] of OBJECT_TO_BE_FOUND[Y] INVESTIGATION_LOCATION[Z]
230 if __name__ ==
"__main__":
231 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
233 from grammar_parser.cfgparser
import CFGParser
236 if sys.argv[1] ==
"object":
237 grammar_parser = CFGParser.fromstring(obj_grammar)
238 elif sys.argv[1] ==
"location":
239 grammar_parser = CFGParser.fromstring(loc_grammar)
240 elif sys.argv[1] ==
"full":
241 grammar_parser = CFGParser.fromstring(grammar)
243 if len(sys.argv) > 2:
244 sentence =
" ".join(sys.argv[2:])
246 sentence = grammar_parser.get_random_sentence(
"T")
248 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
250 result = grammar_parser.parse(
"T", sentence)
252 print(
"Result:\n\n{}".format(result))
261 question_grammar_target =
"T"
263 question_grammar =
"""
264 T[{actions : <A1>}] -> C[A1]
270 question_grammar +=
'''
272 WHATWHICH -> what | which
274 BIGGEST_ADJ -> biggest | heaviest
275 SMALLEST_ADJ -> smallest | lightest
277 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ object
278 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ object
279 Q["action" : "answer", "solution": "bread"] -> WHATWHICH is the BIGGEST_ADJ food
280 Q["action" : "answer", "solution": "onion"] -> WHATWHICH is the SMALLEST_ADJ food
281 Q["action" : "answer", "solution": "plate"] -> WHATWHICH is the BIGGEST_ADJ container
282 Q["action" : "answer", "solution": "soup_container"] -> WHATWHICH is the SMALLEST_ADJ container
283 Q["action" : "answer", "solution": "green_tea"] -> WHATWHICH is the BIGGEST_ADJ drink
284 Q["action" : "answer", "solution": "coke"] -> WHATWHICH is the SMALLEST_ADJ drink
285 Q["action" : "answer", "solution": "hair_spray"] -> WHATWHICH is the BIGGEST_ADJ cleaning stuff
286 Q["action" : "answer", "solution": "moisturizer"] -> WHATWHICH is the SMALLEST_ADJ cleaning stuff
287 Q["action" : "answer", "solution": "spoon"] -> WHATWHICH is the BIGGEST_ADJ cutlery
288 Q["action" : "answer", "solution": "chopsticks"] -> WHATWHICH is the SMALLEST_ADJ cutlery
290 Q["action" : "answer", "solution": "the bedroom has one door"] -> how many doors has the bedroom
291 Q["action" : "answer", "solution": "the entrance has one door"] -> how many doors has the entrance
292 Q["action" : "answer", "solution": "the living room has one door"] -> how many doors has the living_room
293 Q["action" : "answer", "solution": "the kitchen has one door"] -> how many doors has the kitchen
294 Q["action" : "answer", "solution": "the corridor has zero doors"] -> how many doors has the corridor
295 Q["action" : "answer", "solution": "the balcony has zero doors"] -> how many doors has the balcony