robocup_knowledge
rwc2019/challenge_where_is_this.py
Go to the documentation of this file.
1 from __future__ import print_function
2 
3 # System
4 from collections import namedtuple
5 
6 # TU/e Robotics
7 from robocup_knowledge import knowledge_loader
8 
9 BackupScenario = namedtuple("BackupScenario", ["entity_id", "sentence"])
10 
11 backup_scenarios = [
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"),
15 ]
16 
17 information_point_id = "where_is_this_information_point"
18 initial_pose_id = "initial_pose"
19 
20 # Common knowledge
21 common = knowledge_loader.load_knowledge("common")
22 
23 grammar_target = "T"
24 
25 starting_point_grammar = """
26 T[A] -> LOCATION[A]
27 """
28 
29 for loc in common.location_names:
30  starting_point_grammar += '\nLOCATION[%s] -> %s' % (loc, loc)
31 
32 location_grammar = """
33 T[A] -> COURTESY_PREFIX VP[A] | VP[A]
34 
35 COURTESY_PREFIX -> robot please | could you | could you please | please
36 """
37 
38 for loc in common.location_rooms:
39  location_grammar += '\nLOCATION[%s] -> %s' % (loc, loc)
40 
41 for loc in common.location_names:
42  location_grammar += '\nLOCATION[%s] -> %s' % (loc, loc)
43 
44 for loc in common.object_names:
45  category = common.get_object_category(loc)
46  if category not in common.category_locations:
47  continue
48 
49  entity_id = common.get_object_category_location(category)[0]
50 
51  location_grammar += '\nLOCATION[%s] -> %s' % (entity_id, loc)
52 
53 location_grammar += '\nDET_LOCATION[Y] -> LOCATION[Y] | the LOCATION[Y]'
54 
55 location_grammar += """
56 V_GUIDE -> guide | bring | lead
57 
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]
59 
60 """
61 
62 if __name__ == "__main__":
63  print("Where is this Grammar:\n\n{}\n\n".format(location_grammar))
64 
65  from grammar_parser.cfgparser import CFGParser
66 
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")
73  print(sentence)
74  print("Resulting Semantics:")
75  print(grammar_parser.parse("T", sentence))
76 
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")
83  print(sentence)
84  print("Resulting Semantics:")
85  print(grammar_parser.parse("T", sentence))
challenge_where_is_this.BackupScenario
BackupScenario
Definition: impuls/challenge_where_is_this.py:11
common.get_object_category_location
def get_object_category_location(obj_cat)
Definition: demo/common.py:143
common.get_object_category
def get_object_category(obj)
Definition: demo/common.py:136