3 from __future__
import print_function
6 from collections
import namedtuple
9 from robocup_knowledge
import knowledge_loader
11 BackupScenario = namedtuple(
"BackupScenario", [
"entity_id",
"sentence"])
14 BackupScenario(
"fridge",
"I will take you to the fridge for a cold beer"),
15 BackupScenario(
"bed",
"You look tired, I will take you to the bed"),
16 BackupScenario(
"desk",
"I'll have you sit down at the desk so you can work on my speech recognition skills"),
19 information_point_id =
"where_is_this_information_point"
20 initial_pose_id =
"initial_pose"
23 common = knowledge_loader.load_knowledge(
"common")
27 starting_point_grammar =
"""
31 for loc
in common.location_names:
32 starting_point_grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
34 location_grammar =
"""
35 T[A] -> COURTESY_PREFIX VP[A] | VP[A]
37 COURTESY_PREFIX -> robot please | could you | could you please | please
40 for loc
in common.location_rooms:
41 location_grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
43 for loc
in common.location_names:
44 location_grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
46 for loc
in common.object_names:
48 if category
not in common.category_locations:
53 location_grammar +=
'\nLOCATION[%s] -> %s' % (entity_id, loc)
55 location_grammar +=
'\nDET_LOCATION[Y] -> LOCATION[Y] | the LOCATION[Y]'
57 location_grammar +=
"""
58 V_GUIDE -> guide | bring | lead
60 VP[Y] -> DET_LOCATION[Y] | V_GUIDE me to DET_LOCATION[Y] | i want to go to DET_LOCATION[Y] | i would like to go to DET_LOCATION[Y] | i like to go to DET_LOCATION[Y] | tell me how to go to DET_LOCATION[Y] | tell me how to reach DET_LOCATION[Y]
64 if __name__ ==
"__main__":
65 print(
"Where is this Grammar:\n\n{}\n\n".format(location_grammar))
67 from grammar_parser.cfgparser
import CFGParser
69 print(
"Location Grammar")
70 grammar_parser = CFGParser.fromstring(location_grammar)
71 grammar_parser.verify()
72 grammar_parser.check_rules()
73 print(
"Random Sentence:")
74 sentence = grammar_parser.get_random_sentence(
"T")
76 print(
"Resulting Semantics:")
77 print(grammar_parser.parse(
"T", sentence))
79 print(
"\n\nStarting Point Grammar")
80 grammar_parser = CFGParser.fromstring(starting_point_grammar)
81 grammar_parser.verify()
82 grammar_parser.check_rules()
83 print(
"Random Sentence:")
84 sentence = grammar_parser.get_random_sentence(
"T")
86 print(
"Resulting Semantics:")
87 print(grammar_parser.parse(
"T", sentence))