コード例 #1
0
 def user_turn(self, natural_language, debugging=False):
     """
     an entire user turn comprising one user utterance and
     one or more user transitions
     :param natural_language:
     :param debugging:
     :return: None
     """
     self.controller().vars()["__user_utterance__"] = natural_language
     try:
         self.controller().apply_update_rules(natural_language,
                                              debugging=debugging)
         next_state = self.controller().state()
     except Exception as e:
         print()
         print(e)
         print("Error in CompositeDialogueFlow. Component: {}  State: {}".
               format(self._controller_name,
                      self.controller().state()))
         traceback.print_exc(file=sys.stdout)
         next_state = self._user_error_state
     visited = {self.controller().state()}
     while self.controller().speaker() is DialogueFlow.Speaker.USER:
         try:
             next_state = self.controller().user_transition(
                 natural_language,
                 self.controller().state(),
                 debugging=debugging)
             assert next_state is not None
             self.controller().set_state(next_state)
         except Exception as e:
             print()
             print(e)
             print(
                 "Error in CompositeDialogueFlow. Component: {}  State: {}".
                 format(self._controller_name,
                        self.controller().state()))
             traceback.print_exc(file=sys.stdout)
             next_state = self._user_error_state
         next_state = module_state(next_state)
         if isinstance(next_state, tuple):
             self.set_control(*next_state)
             if self.state_settings(*self.state()).user_multi_hop:
                 self.controller().apply_update_rules(natural_language,
                                                      debugging=debugging)
         if next_state in visited or not self.state_settings(
                 *self.state()).user_multi_hop:
             self.controller().set_speaker(DialogueFlow.Speaker.SYSTEM)
         visited.add(next_state)
     next_state = module_state(next_state)
     if isinstance(next_state, tuple):
         self.set_control(*next_state)
         if self.controller().speaker() is DialogueFlow.Speaker.USER:
             self.controller().apply_update_rules(natural_language,
                                                  debugging=debugging)
コード例 #2
0
 def add_state(self, state, error_successor=None):
     state = module_state(state)
     if isinstance(state, tuple):
         ns, state = state
     else:
         ns = "SYSTEM"
     self._components[ns].add_state(state, error_successor)
コード例 #3
0
 def set_state(self, state):
     state = module_state(state)
     if isinstance(state, tuple):
         if self.component(state[0]) != self.controller():
             self.component(state[0]).set_state(self.controller().state(
             ))  # so __system_state__ is set properly
             self.set_controller(state[0])
         state = state[1]
     self.controller().set_state(state)
コード例 #4
0
 def set_control(self, namespace, state):
     state = module_state(state)
     speaker = self.controller().speaker()
     old_state = self.controller().state()
     self.component(namespace).set_state(old_state)
     self.set_controller(namespace)
     self.controller().set_speaker(speaker)
     if isinstance(state, tuple):
         umh = self.state_settings(*state).user_multi_hop
         smh = self.state_settings(*state).system_multi_hop
     else:
         umh = self.state_settings(namespace, state).user_multi_hop
         smh = self.state_settings(namespace, state).system_multi_hop
     if speaker == DialogueFlow.Speaker.USER and not umh:
         self.controller().change_speaker()
     elif speaker == DialogueFlow.Speaker.SYSTEM and not smh:
         self.controller().change_speaker()
     self.controller().set_state(state)