1 from __future__
import print_function
3 from robocup_knowledge
import knowledge_loader
4 common = knowledge_loader.load_knowledge(
"common")
6 names = [
'josja',
'lars',
'janno',
'loy',
'rein',
'kevin',
'ramon',
'max',
'matthijs',
'raphael']
8 not_understood_sentences = [
9 "I'm so sorry! Can you please speak louder and slower? And wait for the ping!",
10 "I am deeply sorry. Please try again, but wait for the ping!",
11 "You and I have communication issues. Speak up!",
12 "All this noise is messing with my audio. Try again"
15 initial_pose =
"initial_pose_2"
16 starting_pose =
"gpsr_meeting_point"
17 exit_waypoint =
"gpsr_exit_door_2"
30 C[{"actions": <A1>}] -> VP[A1]
31 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
41 V_GUIDE -> guide | escort | take | lead
44 PPN_PERSON -> him | her
46 DET -> the | a | an | some
47 NUMBER -> one | two | three
48 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
51 for room
in common.location_rooms:
52 grammar +=
"\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
55 grammar +=
'\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
57 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
59 for obj
in common.object_names:
60 grammar +=
"\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
63 grammar +=
'\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
65 for cat
in common.object_categories:
66 grammar +=
"\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
69 grammar +=
"\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
71 grammar +=
'\nLOCATION[{"id": "exit_4_rips", "type": "waypoint"}] -> door | exit | entrance'
81 V_FIND -> find | locate | look for
82 V_FIND_PERSON -> meet | V_FIND
84 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
85 PERSON_TO_BE_FOUND -> DET person | DET woman | DET man | NAMED_PERSON | someone
87 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
88 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] MANIPULATION_AREA_LOCATION[Y]
91 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] in the ROOM[Y]
92 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND PERSON_TO_BE_FOUND[X] NEAR the LOCATION[Y]
94 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
95 VP[{"action": "find", "object": X}] -> V_FIND DET PERSON_TO_BE_FOUND[X]
97 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
110 V_GOPL -> go to | navigate to
111 V_GOR -> V_GOPL | enter
113 VP[{"action": "navigate-to", "target-location": X}] -> V_GOR the ROOM[X]
114 VP[{"action": "navigate-to", "target-location": X}] -> V_GOPL the LOCATION[X]
123 V_SEND_PICTURE -> check who is | show me who is
124 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE at the ROOM_OR_LOCATION[X]
135 V_PICKUP -> get | grasp | take | pick up | grab
137 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
147 V_PLACE -> put | place | set
149 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
150 VP[{"action": "place", "object": X, "target-location": Y}] -> V_PLACE PPN_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
159 VP[{"action": "guide", "object": {"id": "reference", "type": "person"}, "target-location": Y}] -> V_GUIDE PPN_PERSON to the ROOM_OR_LOCATION[Y]
169 V_FOLLOW -> follow | go after | come after
171 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]
172 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]
174 VP[{"action": "follow", "target": {"id": "operator"}}] -> V_FOLLOW me
175 VP[{"action": "follow", "target": {"id": "operator"}, "location-to": X}] -> V_FOLLOW me to the ROOM_OR_LOCATION[X]
177 VP[{"action": "follow", "target": {"type": "reference"}}] -> V_FOLLOW PPN_PERSON
178 VP[{"action": "follow", "target": {"type": "reference"}, "location-to": X}] -> V_FOLLOW PPN_PERSON to the ROOM_OR_LOCATION[X]
180 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]
181 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]
183 VP[{"action": "follow", "location-from": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] from the ROOM_OR_LOCATION[X]
184 VP[{"action": "follow", "location-to": X, "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z] to the ROOM_OR_LOCATION[X]
186 VP[{"action": "follow", "target": Z}] -> V_FOLLOW FOLLOW_PERSONS[Z]
189 grammar +=
'\nFOLLOW_PERSONS[the person] -> DET person'
190 grammar +=
'\nFOLLOW_PERSONS[the woman] -> DET woman'
191 grammar +=
'\nFOLLOW_PERSONS[the man] -> DET man'
193 grammar +=
'\nFOLLOW_PERSONS[%s] -> %s' % (name, name)
204 OPERATOR[{"type": "person", "id": "operator"}] -> me
205 BRING_NAME -> OPERATOR | BRING_PERSON
207 BRING_TARGET[X] -> the ROOM_OR_LOCATION[X]
209 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
211 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over | place | put
213 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]
215 VP[{"action": "place", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_TARGET[X]
217 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]
218 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z]
219 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]
220 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to BRING_PERSON[X]
221 VP[{"action": "hand-over", "target-location": X, "object": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] to BRING_PERSON[X]
225 grammar +=
'\nBRING_PERSON[{"type": "person", "id": "%s"}] -> %s' % (name, name)
227 grammar +=
'\nBRING_PERSON[{"type": "person", "id": "%s", "location": %s}] -> %s MANIPULATION_AREA_DESCRIPTION the %s' % (name, loc, name, loc)
236 V_SAY -> tell | say | speak
238 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
241 grammar +=
'\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
242 grammar +=
'\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
243 grammar +=
'\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
244 grammar +=
'\nSAY_SENTENCE["COUNTRY"] -> your teams country'
245 grammar +=
'\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
246 grammar +=
'\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
247 grammar +=
'\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
248 grammar +=
'\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
249 grammar +=
'\nSAY_SENTENCE["JOKE"] -> a joke'
250 grammar +=
'\nSAY_SENTENCE["SOMETHING_ABOUT_SELF"] -> something about yourself'
260 VP[{"action": "answer-question"}] -> answer a question
273 VP[{"action": "find", "object": {"type": "person", "id": Z}}] -> V_FIND MEET_PERSON[Z]
274 VP[{"action": "navigate-to"}] -> V_GUIDE HIM_HER
277 grammar +=
'\nMEET_PERSON[the person] -> DET person'
278 grammar +=
'\nMEET_PERSON[the woman] -> DET woman'
279 grammar +=
'\nMEET_PERSON[the man] -> DET man'
281 grammar +=
'\nMEET_PERSON[%s] -> %s' % (name, name)
293 HE_SHE -> he | she | it | him | her
295 VP[{"object": {"id": X}}] -> HE_SHE is in the ROOM_OR_LOCATION[X] | in the ROOM_OR_LOCATION[X] | you could find HE_SHE in the ROOM_OR_LOCATION[X]
300 VP[{"object": {"id": Y}}] -> the NAMED_OBJECT[Z] is DET NAMED_OBJECT[Y] | the NAMED_OBJECT[Z] is NAMED_OBJECT[Y] | NAMED_OBJECT[Y] | DET NAMED_OBJECT[Y]
303 if __name__ ==
"__main__":
304 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
306 from grammar_parser.cfgparser
import CFGParser
309 if sys.argv[1] ==
"object":
310 grammar_parser = CFGParser.fromstring(obj_grammar)
311 elif sys.argv[1] ==
"location":
312 grammar_parser = CFGParser.fromstring(loc_grammar)
313 elif sys.argv[1] ==
"full":
314 grammar_parser = CFGParser.fromstring(grammar)
316 if len(sys.argv) > 2:
317 sentence =
" ".join(sys.argv[2:])
319 sentence = grammar_parser.get_random_sentence(
"T")
321 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
323 result = grammar_parser.parse(
"T", sentence)
325 print(
"Result:\n\n{}".format(result))