def create_handler_ui_test(configuration_file, db_configuration_file):
    ## Parser parameters
    parameters = parse_configuration_file(configuration_file)
    db_pars = parse_configuration_file_dbapi(db_configuration_file)

    ## Testing state machine
    testing_pars = create_testing_mode_parameters(parameters)
    if not isinstance(testing_pars, dict):
        testing_pars = testing_pars[0]
    statemachine = ConversationStateMachine.from_parameters(testing_pars)

    ## DB setting
    db_api = DataBaseAPI(**db_pars)
    handler_db = HandlerConvesationDB(databases=db_api)

    ## Handler
    tester_handler = TerminalUIHandler(handler_db, statemachine)
    return tester_handler
    def __init__(self, configuration_file, db_configuration_file):

        ## Parser parameters
        parameters = parse_configuration_file(configuration_file)
        db_pars = parse_configuration_file_dbapi(db_configuration_file)

        ## Obtain description
        states_list_table, path_states, xstates, transitions =\
            create_tables(parameters)
        treestates, graphs_statemachines, complete_network =\
            create_graphs(states_list_table, path_states, xstates, transitions)
        self.complete_network = complete_network

        ## Testing state machine
        testing_pars = create_testing_mode_parameters(parameters)
        if not isinstance(testing_pars, dict):
            testing_pars = testing_pars[0]
        statemachine = ConversationStateMachine.from_parameters(testing_pars)

        ## DB setting
        db_api = DataBaseAPI(**db_pars)
        handler_db = HandlerConvesationDB(databases=db_api)

        super().__init__(handler_db, statemachine)

        ## Functions
        def ifstate(pathname):
            aux = states_list_table[states_list_table['Pathname'] == pathname]
            aux = list(aux['IfStateMachine'])[0]
            return not aux

        def get_sonstate(path):
            if ifstate(path):
                return path
            path = path_builder_states(xstates[path]['StartState'], path)
            if not ifstate(path):
                return get_sonstate(path)
            return path

        ## Initial setting
        initials = states_list_table[states_list_table['level'] == 0]
        initial_state = get_sonstate(list(initials['Pathname'])[0])
        self.current_state = initial_state[:]
Beispiel #3
0
    get_name_conv = ConversationStateMachine('Ask name',
                                             states,
                                             'Asking name', ['Greetings name'],
                                             transition=trans)

    ### Say goodbye conversation
    q_goodbye = [{'message': m} for m in QUESTIONS_GOODBYE]
    say_goodbye = TalkingState('Say goodbye',
                               SequentialChooser(q_goodbye),
                               shadow=True)
    say_goodbye_conv = ConversationStateMachine('Say goodbye', [say_goodbye],
                                                'Say goodbye', 'Say goodbye')

    PoCs = [check_user_conv, say_hello_conv, get_name_conv, say_goodbye_conv]
    end_states = ['Say goodbye']
    general_conv = ConversationStateMachine('Conversation', PoCs,
                                            'if_username_conv', end_states)

    ### Conversation
    #    handler_io = HandlerConvesationIO()
    #handler_io.profile_user.profile = {'username': '******'}
    #    get_name_conv.run(handler_io)
    #    general_conv.run(handler_io)

    handler_db = HandlerConvesationDB()
    #    handler_db.profile_user.profile = {'username': '******'}
    #    handler_ui = TerminalUIHandler(handler_db, general_conv)
    handler_ui = FlaskUIHandler(handler_db, general_conv)

    handler_ui.run()
 def test_handling_db_from_file(self):
     handler_db = HandlerConvesationDB.from_file(self.example_db_hand_yaml)
     self.assert_handlerdb(handler_db)
 def test_handling_db(self):
     for p in product(*self.db_handlers):
         pars = dict(zip(self.variables, p))
         handler_db = HandlerConvesationDB(**pars)
         self.assert_handlerdb(handler_db)
Beispiel #6
0
    conversa = ConversationStateMachine('Conversation', conv_states, 'Hello',
                                        end_states)

    ###########################################################################

    ## DB information
    type_vars =\
        {'main_var': {'name': 'Product Name', 'codename': 'productname'},
         'cat_vars': {'name': ['Brand', 'Category'],
                      'codename': ['brand', 'category']},
         'label_var': {'name': 'Subscription Plan'}}
    responses_formatter =\
        {'main_var': (lambda l: ''.join(['\n'+' '*8+'* '+s for s in l]),
                      'query_productnames'),
         'cat_vars': {'Brand': joiner_brands, 'Category': joiner_categories},
         'label_var': (lambda l, p: ''.join(['\n'+' '*8+'* '+r+': '+s+"€/month"
                                             for r, s in zip(l, p)]),
                       'query_productnames'),
         'join_cats': (category_joiner, 'query_catnames')
         }
    parameter_formatter =\
        {'label': price_q_keywords}

    db_api = DataBaseAPI(datapath, type_vars, responses_formatter,
                         parameter_formatter)
    handler_db = HandlerConvesationDB(databases=db_api)

    ## Running a conversation
    handler_ui = TerminalUIHandler(handler_db, conversa)
    handler_ui.run()
Beispiel #7
0
 def from_parameters(cls, parameters_db, parameters_conv):
     handler_db = HandlerConvesationDB.from_parameters(parameters_db)
     conversation_machine = ConversationStateMachine.\
         from_parameters(parameters_conv)
     return cls(handler_db, conversation_machine)