1 from __future__
import print_function
3 from robocup_knowledge
import knowledge_loader
4 common = knowledge_loader.load_knowledge(
"common")
17 C[{"actions": <A1>}] -> VP[A1]
18 C[{"actions": <A1, A2>}] -> VP[A1] and VP[A2]
26 female_names = [
"josja"]
27 male_names = [
"max",
"lars",
"rein",
"rokus",
"ramon",
"loy",
"sam",
"henk",
"matthijs",
"lieve"]
28 names = female_names + male_names
37 PPN_OBJECT -> it | them
38 PPN_PERSON -> him | her | them
41 NUMBER -> one | two | three
46 for room
in common.location_rooms:
47 grammar +=
"\nROOM[{'type': 'room', 'id': '%s'}] -> %s" % (room, room)
50 grammar +=
'\nLOCATION[{"id": "%s"}] -> %s' % (loc, loc)
52 grammar +=
'\n ROOM_OR_LOCATION[X] -> ROOM[X] | LOCATION[X]'
54 for obj
in common.object_names:
55 grammar +=
"\nNAMED_OBJECT[{'type': '%s'}] -> %s" % (obj, obj)
58 grammar +=
'\nMANIPULATION_AREA_LOCATION[{"id": "%s"}] -> MANIPULATION_PP the %s' % (loc, loc)
60 for cat
in common.object_categories:
61 grammar +=
"\nOBJECT_CATEGORY[{'category': '%s'}] -> %s" % (cat, cat)
64 grammar +=
"\nNAMED_PERSON[{'type': 'person', 'id': '%s'}] -> %s" % (name, name)
65 grammar +=
"\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_entrance', 'type': 'waypoint'}}] -> %s at the entrance" % (
67 grammar +=
"\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': 'gpsr_exit_door', 'type': 'waypoint'}}] -> %s at the exit" % (
70 grammar +=
"\nPERSON_AT_LOCATION[{'type': 'person', 'id': '%s', 'location': {'id': %s}}] -> %s at the %s" % (
73 grammar +=
'\nLOCATION[{"id": "gpsr_exit_door", "type": "waypoint"}] -> exit'
74 grammar +=
'\nLOCATION[{"id": "gpsr_entrance", "type": "waypoint"}] -> entrance'
83 V_FIND -> find | locate | look for
85 OBJECT_TO_BE_FOUND -> NAMED_OBJECT | OBJECT_CATEGORY
86 UNNAMED_PERSON -> a person | someone
88 VP[{"action": "find", "object": {'type': 'person'}}] -> V_FIND UNNAMED_PERSON
89 VP[{"action": "find", "object": {'type': 'person'}, "source-location": Y}] -> V_FIND UNNAMED_PERSON in the ROOM[Y]
90 VP[{"action": "find", "object": X}] -> V_FIND NAMED_PERSON[X]
91 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND NAMED_PERSON[X] in the ROOM[Y]
93 VP[{"action": "find", "object": X, "source-location": Y}] -> V_FIND DET OBJECT_TO_BE_FOUND[X] in the ROOM[Y]
95 VP[{"action": "find", "object": X}] -> V_FIND DET OBJECT_TO_BE_FOUND[X]
107 V_GOTO -> go to | navigate to
109 VP[{"action": "navigate-to", "target-location": X}] -> V_GOTO the ROOM_OR_LOCATION[X]
119 V_SEND_PICTURE -> check who is | show me who is
121 VP[{"action": "send-picture", "target-location": X}] -> V_SEND_PICTURE at the ROOM_OR_LOCATION[X]
134 VP[{"action": "guide-final-challenge", "object": {"type": "reference"}, "target-location": X}] -> guide him to the ROOM_OR_LOCATION[X]
144 V_PICKUP -> get | grasp | take | pick up | grab
146 VP[{"action": "pick-up", "object": X, "source-location": Y}] -> V_PICKUP DET NAMED_OBJECT[X] from the LOCATION[Y]
156 V_PLACE -> put | place
158 VP[{"action": "put", "object": X, "target-location": Y}] -> V_PLACE DET NAMED_OBJECT[X] on the LOCATION[Y]
173 VP[{"action": "gripper-goal", "side": X, "goal": Y}] -> GOAL[Y] your SIDE[X] gripper
184 VP[{"action": "clear-table"}] -> clear the dining_table
195 VP[{"action": "open-door", "door-location": "cupboard"}] -> open the door of the cupboard
206 OPERATOR[{"type": "person", "id": "operator"}] -> me
207 BRING_NAME -> OPERATOR | NAMED_PERSON
209 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
221 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z]
222 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING OPERATOR[Y] DET NAMED_OBJECT[Z] from the LOCATION[X]
223 VP[{"action": "hand-over", "source-location": X, "target-location": Y, "object": Z}] -> V_BRING to PERSON_AT_LOCATION[Y] DET NAMED_OBJECT[Z] from the LOCATION[X]
225 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to PERSON_AT_LOCATION[Y]
226 VP[{"action": "hand-over", "target-location": Y, "object": Z}] -> V_BRING DET NAMED_OBJECT[Z] to OPERATOR[Y]
229 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to PERSON_AT_LOCATION[X]
230 VP[{"action": "hand-over", "target-location": X, "object": {"type": "reference"}}] -> V_BRING PPN_OBJECT to OPERATOR[X]
242 VP[{"action": "say", "sentence": X}] -> V_SAY SAY_SENTENCE[X]
243 VP[{"action": "say", "sentence": "party"}] -> lets get the party started
246 grammar +=
'\nSAY_SENTENCE["time"] -> the time'
247 grammar +=
'\nSAY_SENTENCE["team_name"] -> your teams name'
248 grammar +=
'\nSAY_SENTENCE["country"] -> your teams country'
249 grammar +=
'\nSAY_SENTENCE["team_affiliation"] -> your teams affiliation'
250 grammar +=
'\nSAY_SENTENCE["day_of_month"] -> the day of the month'
251 grammar +=
'\nSAY_SENTENCE["day_of_week"] -> the day of the week'
252 grammar +=
'\nSAY_SENTENCE["today"] -> what day is today'
253 grammar +=
'\nSAY_SENTENCE["tomorrow"] -> what day is tomorrow'
254 grammar +=
'\nSAY_SENTENCE["joke"] -> a joke'
255 grammar +=
'\nSAY_SENTENCE["something_about_self"] -> something about yourself'
256 grammar +=
'\nSAY_SENTENCE["you_shall_not_pass"] -> you shall not pass'
259 if __name__ ==
"__main__":
260 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
262 from grammar_parser.cfgparser
import CFGParser
265 grammar_parser = CFGParser.fromstring(grammar)
267 if len(sys.argv) > 2:
268 sentence =
" ".join(sys.argv[2:])
270 sentence = grammar_parser.get_random_sentence(
"T")
272 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
274 result = grammar_parser.parse(
"T", sentence)
276 print(
"Result:\n\n{}".format(result))