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