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"
22 T[{actions : <A1>}] -> C[A1]
34 V_GUIDE -> guide | escort | take | lead | accompany
36 DET -> the | a | an | some
37 NUMBER -> one | two | three
38 MANIPULATION_AREA_DESCRIPTION -> on top of | at | in | on | from
42 grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
44 for obj
in common.object_names:
45 grammar +=
'\nNAMED_OBJECT[%s] -> %s' % (obj, obj)
48 grammar +=
'\nMANIPULATION_AREA_LOCATION[%s] -> MANIPULATION_AREA_DESCRIPTION the %s' % (loc, loc)
50 for cat
in common.object_categories:
51 grammar +=
'\nOBJECT_CATEGORY[%s] -> %s' % (cat, cat)
53 for name
in common.names:
54 grammar +=
'\nNAMED_PERSON[%s] -> %s' % (name, name)
63 V_PRESENT -> introduce yourself | present yourself | perform a demonstration | give a presentation
64 ENGLISH['en'] -> english
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]
78 V_FIND -> find | locate | look for
80 VP["action": "find", "object": {"type": X}, "location": {"id": Y}] -> V_FIND DET NAMED_OBJECT[X] MANIPULATION_AREA_LOCATION[Y]
81 VP["action": "find", "object": {"type": X}] -> V_FIND DET NAMED_OBJECT[X]
91 V_GOPL -> go to | navigate to | drive to
93 VP["action": "navigate-to", "object": {"id": X}] -> V_GOPL the LOCATION[X]
104 VP["action": "inspect", "entity": {"id": X}] -> inspect the LOCATION[X]
114 OBJECT_TO_BE_BROUGHT -> NAMED_OBJECT | DET NAMED_OBJECT
116 V_BRING -> bring | deliver | take | carry | transport | give | hand | hand over
118 VP["action": "bring", "source-location": {"id": X}, "target-location": {"id": Y}, "object": {"type": Z}] -> V_BRING OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X] to the LOCATION[Y]
119 VP["action": "bring", "source-location": {"id": X}, "target-location": {"type": "person", "id": "operator"}, "object": {"type": Z}] -> V_BRING me OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X] | V_BRING OBJECT_TO_BE_BROUGHT[Z] from the LOCATION[X] to me
131 VP["action": "say", "sentence": X] -> V_SAY SAY_SENTENCE[X]
134 grammar +=
'\nSAY_SENTENCE["ROBOT_NAME"] -> your name'
135 grammar +=
'\nSAY_SENTENCE["TIME"] -> the time | what time it is | what time is it'
136 grammar +=
'\nSAY_SENTENCE["my team is tech united"] -> the name of your team'
137 grammar +=
'\nSAY_SENTENCE["DAY_OF_MONTH"] -> the day of the month'
138 grammar +=
'\nSAY_SENTENCE["DAY_OF_WEEK"] -> the day of the week'
139 grammar +=
'\nSAY_SENTENCE["TODAY"] -> what day is today | me what day it is | the date'
140 grammar +=
'\nSAY_SENTENCE["JOKE"] -> a joke'
149 VP["action": "turn-toward-sound", "duration": "30"] -> show your sound source localization | look at me when i am talking to you
158 if __name__ ==
"__main__":
159 print(
"GPSR Grammar:\n\n{}\n\n".format(grammar))
161 from grammar_parser.cfgparser
import CFGParser
164 if sys.argv[1] ==
"object":
165 grammar_parser = CFGParser.fromstring(obj_grammar)
166 elif sys.argv[1] ==
"location":
167 grammar_parser = CFGParser.fromstring(loc_grammar)
168 elif sys.argv[1] ==
"full":
169 grammar_parser = CFGParser.fromstring(grammar)
171 if len(sys.argv) > 2:
172 sentence =
" ".join(sys.argv[2:])
174 sentence = grammar_parser.get_random_sentence(
"T")
176 print(
"Parsing sentence:\n\n{}\n\n".format(sentence))
178 result = grammar_parser.parse(
"T", sentence)
180 print(
"Result:\n\n{}".format(result))