robocup_knowledge
demo/challenge_gpsr.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 from robocup_knowledge import knowledge_loader
4 common = knowledge_loader.load_knowledge("common")
5 
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"
11  ]
12 
13 grammar_target = "T"
14 
15 
20 
21 grammar = """
22 T[{actions : <A>}] -> C[A] | amigo C[A]
23 
24 C[{A}] -> VP[A]
25 """
26 
27 
32 
33 grammar += """
34 V_GUIDE -> guide | escort | take | lead | accompany
35 
36 DET -> the | a | an | some
37 NUMBER -> one | two | three
38 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
39 """
40 
41 for loc in common.get_locations():
42  grammar += '\nLOCATION[%s] -> %s' % (loc, loc)
43 
44 for obj in common.object_names:
45  grammar += '\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
46 
47 for loc in common.get_locations(pick_location=True, place_location=True):
48  grammar += '\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
49 
50 for cat in common.object_categories:
51  grammar += '\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)
52 
53 for name in common.names:
54  grammar += '\nNAMED_PERSON[%s] -> %s' % (name, name)
55 
56 
61 
62 grammar += """
63 V_PRESENT -> introduce yourself | present yourself | perform a demonstration | give a presentation
64 ENGLISH['en'] -> english
65 DUTCH['nl'] -> dutch
66 LANGUAGE[X] -> ENGLISH[X] | DUTCH[X]
67 VP["action": "demo-presentation", 'language': 'en'] -> V_PRESENT
68 VP["action": "demo-presentation", "language": X] -> V_PRESENT in LANGUAGE[X]
69 """
70 
71 
72 
77 
78 grammar += """
79 V_GOPL -> go to | navigate to
80 V_GOR -> V_GOPL | enter
81 
82 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATION[X]
83 """
84 
85 
90 
91 grammar += """
92 
93 VP["action": "inspect", "entity": {"id": X}] -> inspect the LOCATION[X]
94 """
95 
96 
101 
102 grammar += """
103 V_PICKUP -> get | grasp | take | pick up | grab
104 
105 VP["action": "pick-up", "object": {"type": X}, "location": {"id": Y}] -> V_PICKUP DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
106 """
107 
108 
113 
114 grammar += """
115 V_PLACE -> put | place
116 
117 VP["action": "place", "object": {"type": X}, "location": {"id": Y}] -> V_PLACE DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
118 """
119 
120 
125 
126 grammar += """
127 V_FOLLOW -> follow | come after
128 
129 VP["action": "follow", "target": {"id": "operator"}] -> V_FOLLOW me
130 """
131 
132 
137 
138 grammar += """
139 OPERATOR[operator] -> me
140 BRING_NAME -> OPERATOR | BRING_PERSON
141 
142 BRING_TARGET[{"id": X, "type": person}] -> BRING_NAME[X]
143 BRING_TARGET[{"id": X}] -> the LOCATION[X]
144 
145 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
146 
147 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over
148 
149 VP["action": "bring", "source-location": {"id": X}, "target-location": Y, "object": {"type": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X] to BRING_TARGET[Y]
150 VP["action": "bring", "target-location": {"type": "person", "id": Y}, "object": {"type": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z]
151 VP["action": "bring", "source-location": {"id": X}, "target-location": {"type": "person", "id": Y}, "object": {"type": Z}] -> V_BRING BRING_NAME[Y] OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X]
152 """
153 
154 for name in common.names:
155  grammar += '\nBRING_PERSON[%s] -> %s' % (name, name)
156 
157 
162 
163 grammar += """
164 V_SAY -> tell | say | speak
165 
166 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
167 """
168 
169 grammar += '\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
170 grammar += '\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
171 grammar += '\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
172 grammar += '\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
173 grammar += '\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
174 grammar += '\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
175 grammar += '\nSAY_SENTENCE["TOMORROW"] -> what day is tomorrow'
176 grammar += '\nSAY_SENTENCE["JOKE"] -> a joke'
177 
178 
179 
184 
185 grammar += """
186 VP["action": "answer-question"] -> answer a question
187 """
188 
189 
190 if __name__ == "__main__":
191  print( "GPSR Grammar:\n\n{}\n\n".format(grammar))
192 
193  from grammar_parser.cfgparser import CFGParser
194 
195  import sys
196  if sys.argv[1] == "object":
197  grammar_parser = CFGParser.fromstring(obj_grammar)
198  elif sys.argv[1] == "location":
199  grammar_parser = CFGParser.fromstring(loc_grammar)
200  elif sys.argv[1] == "full":
201  grammar_parser = CFGParser.fromstring(grammar)
202 
203  if len(sys.argv) > 2:
204  sentence = " ".join(sys.argv[2:])
205  else:
206  sentence = grammar_parser.get_random_sentence("T")
207 
208  print("Parsing sentence:\n\n{}\n\n".format(sentence))
209 
210  result = grammar_parser.parse("T", sentence)
211 
212  print("Result:\n\n{}".format(result))
common.get_locations
def get_locations(room=None, manipulation_location=None)
Definition: rwc2023/common.py:156