Example #1
0
    def test_base_transitions(self):
        transition = TransitionConversationStates.from_transition_info(None)
        transition.set_current_state(self.conversationstate)
        self.assert_transition(transition)

        pars = [self.transitions, self.function]
        transition = TransitionConversationStates.from_transition_info(pars)
        transition.set_current_state(self.conversationstate)
        self.assert_transition(transition)

        pars = {
            'name_trans_states': self.transitions,
            'condition': self.function
        }
        transition = TransitionConversationStates.from_transition_info(pars)
        transition.set_current_state(self.conversationstate)
        self.assert_transition(transition)

        pars = {
            'transition_object': 'TransitionConversationStates',
            'transition_states': self.transitions,
            'transition_function': self.function
        }
        transition = TransitionConversationStates.from_transition_info(pars)
        transition.set_current_state(self.conversationstate)
        self.assert_transition(transition)

        transition =\
            TransitionConversationStates.from_transition_info(transition)
        transition.set_current_state(self.conversationstate)
        self.assert_transition(transition)
Example #2
0
    def test_base_testing_transitions(self):
        transition = TransitionConversationStates.\
            test_from_transition_info(None)
        transition.set_current_state(self.conversationstate)
        self.assert_t_mode_transition(transition)

        pars = [self.transitions, self.function]
        transition = TransitionConversationStates.\
            test_from_transition_info(pars)
        transition.set_current_state(self.conversationstate)
        self.assert_t_mode_transition(transition)

        pars = {
            'transition_object': 'NullTransitionConversation',
            'transition_states': self.transitions
        }
        transition = TransitionConversationStates.\
            test_from_transition_info(pars)
        transition.set_current_state(self.conversationstate)
        self.assert_t_mode_transition(transition)

        transition =\
            TransitionConversationStates.test_from_transition_info(transition)
        transition.set_current_state(self.conversationstate)
        self.assert_t_mode_transition(transition)
Example #3
0
 def test_general_trastions(self):
     # Testing transition
     general_transition = TransitionConversationStates(
         self.transitions, self.function)
     general_transition.set_current_state(self.conversationstate)
     self.assert_transition(general_transition)
Example #4
0
 def test_instantiation(self):
     TransitionConversationStates('transition', lambda x: 0)
     with self.assertRaises(TypeError):
         TransitionConversationStates(8, lambda x: 0)
Example #5
0
        else:
            m = m.split(' ')
        if 1 <= len(m) <= 2:
            return 0.9, 0.1
        elif 3 <= len(m) <= 4:
            return 0.5, 0.5
        else:
            return 0.15, 0.85

    pos_types = ('name', 'notname')
    name_detector = BaseDetector(pos_types, dummy_name_detector)
    splits = [0, 0.5, 0.8, 1.]
    cond_trans = create_probsplitter_condition(splits,
                                               ('selector_types', 'name'))
    trans_states = ['Store name', 'Store tempname', 'Refocus name']
    trans_askname = TransitionConversationStates(trans_states, cond_trans)
    chooser_askname = SequentialChooser(q_username)
    state_askname = QuestioningState('Asking name',
                                     chooser_askname,
                                     name_detector,
                                     tags=['name'],
                                     transition=trans_askname)
    states.append(state_askname)

    ## Defining 'Store name' state
    cond_trans = create_fixed_condition(0)
    trans_states = ['Greetings name']
    trans_storename = TransitionConversationStates(trans_states, cond_trans)

    def storer_name(h, m):
        #        h.profile_user.profile['username'] =\
Example #6
0
    # Parse data
    args = sys.argv
    assert (len(args) == 2)
    assert (isfile(args[1]))
    datapath = args[1]

    ############################ Query conversation ###########################
    ## Defining query conversation
    states = []

    ## Defining 'Hello DB' state
    q_hello_db = [{'message': m} for m in QUESTIONS_SALUT_DB]
    cond_hellodb = create_fixed_condition(0)
    trans_states = ['Querier DB']
    trans_hellodb = TransitionConversationStates(trans_states, cond_hellodb)
    chooser_askquery = SequentialChooser(q_hello_db)
    states.append(
        TalkingState('Hello DB',
                     chooser_askquery,
                     None,
                     tags=['query'],
                     transition=trans_hellodb,
                     shadow=False))

    ## Defining 'Querier DB' state
    chooser_query = QuerierSplitterChooser(QUESTIONS_QUERY_DB,
                                           'level_query',
                                           cond_selector,
                                           query_var='query_idxs')
    trans_states = [
Example #7
0
QUESTIONS_HELLO = ["Hello! Nice to see you."]
PRESENTATION = ["My name is ChatBot."]
TALKING_LEARNING = ["I am learning to talk."]
QUESTIONS_GOODBYE = ["It's been a pleasure. See you next time!",
                     "Have a nice day!"]


if __name__ == "__main__":
    states = []

    ## Defining 'Greetings name' state
    q_hello = [{'message': m} for m in QUESTIONS_HELLO]
    chooser_hello = SequentialChooser(q_hello)
    cond_trans = create_fixed_condition(0)
    trans_states = ['Presentation']
    trans_hello = TransitionConversationStates(trans_states, cond_trans)
    hello_state = TalkingState('Hello', chooser_hello, shadow=True,)
#                               transition=trans_hello)
    states.append(hello_state)

    q_presentation = [{'message': m} for m in PRESENTATION]
    chooser_presentation = SequentialChooser(q_presentation)
    cond_trans = create_fixed_condition(0)
    trans_states = ['Learning']
    trans_press = TransitionConversationStates(trans_states, cond_trans)
    presentation_state = TalkingState('Presentation', chooser_presentation,
                                      shadow=True,)  # transition=trans_press)
    states.append(presentation_state)

    q_learning = [{'message': m} for m in TALKING_LEARNING]
    chooser_learning = SequentialChooser(q_learning)