1 from __future__
import print_function
4 from collections
import namedtuple
7 from robocup_knowledge
import knowledge_loader
9 BackupScenario = namedtuple(
"BackupScenario", [
"entity_id",
"sentence"])
12 BackupScenario(
"fridge",
"I will take you to the fridge for a cold beer"),
13 BackupScenario(
"bed",
"You look tired, I will take you to the bed"),
14 BackupScenario(
"desk",
"I'll have you sit down at the desk so you can work on my speech recognition skills"),
17 information_point_id =
"where_is_this_information_point"
18 initial_pose_id =
"initial_pose"
21 common = knowledge_loader.load_knowledge(
"common")
25 starting_point_grammar =
"""
29 for loc
in common.location_names:
30 starting_point_grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
32 location_grammar =
"""
33 T[A] -> COURTESY_PREFIX VP[A] | VP[A]
35 COURTESY_PREFIX -> robot please | could you | could you please | please
38 for loc
in common.location_rooms:
39 location_grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
41 for loc
in common.location_names:
42 location_grammar +=
'\nLOCATION[%s] -> %s' % (loc, loc)
44 for loc
in common.object_names:
46 if category
not in common.category_locations:
51 location_grammar +=
'\nLOCATION[%s] -> %s' % (entity_id, loc)
53 location_grammar +=
'\nDET_LOCATION[Y] -> LOCATION[Y] | the LOCATION[Y]'
55 location_grammar +=
"""
56 V_GUIDE -> guide | bring | lead
58 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]
62 if __name__ ==
"__main__":
63 print(
"Where is this Grammar:\n\n{}\n\n".format(location_grammar))
65 from grammar_parser.cfgparser
import CFGParser
67 print(
"Location Grammar")
68 grammar_parser = CFGParser.fromstring(location_grammar)
69 grammar_parser.verify()
70 grammar_parser.check_rules()
71 print(
"Random Sentence:")
72 sentence = grammar_parser.get_random_sentence(
"T")
74 print(
"Resulting Semantics:")
75 print(grammar_parser.parse(
"T", sentence))
77 print(
"\n\nStarting Point Grammar")
78 grammar_parser = CFGParser.fromstring(starting_point_grammar)
79 grammar_parser.verify()
80 grammar_parser.check_rules()
81 print(
"Random Sentence:")
82 sentence = grammar_parser.get_random_sentence(
"T")
84 print(
"Resulting Semantics:")
85 print(grammar_parser.parse(
"T", sentence))