def create_tables(parameters): ## 0. Table of states parameters = parameters if isinstance(parameters, list) else [parameters] states_list_table, path_states, xstates = create_states_table(parameters) ## 1A. Prepare table of transitions def retriever_transitions(path, state): if 'transition' not in state: return path, [] if state['transition'] is None: return path, [] if isinstance(state['transition'], list): states_transitions = [s['transition_states'] for s in state['transition']] else: states_transitions = state['transition']['transition_states'] return path, states_transitions pathgen = PathGenerator() condition_function = create_condition_parsing_chatbotquery_parameters() description_pars = condition_function, pathgen, retriever_transitions ## 1B. Table of transitions transitions = create_transitions(parameters, description_pars, path_states) return states_list_table, path_states, xstates, transitions
def create_states_table(parameters): ## 0. Parameters parsing def retriever_state_names(path, state): if 'states' in state: ifstatemachine = True initialstate = state['startState'] endstates = state['endStates'] else: ifstatemachine = False initialstate = None endstates = None return path, state['name'], ifstatemachine, initialstate, endstates parameters = parameters if isinstance(parameters, list) else [parameters] condition_function = create_condition_parsing_chatbotquery_parameters() pathgen = PathGenerator() ## 1. Finding states states = [] for p in find_descriptions_new(parameters, condition_function, pathgen, retriever_state_names): states.append(p) levels_len = list(set([len(s[0]) for s in states])) ## 2. Create tables states_list_table, path_states, xstates =\ ensemble_table_states(states, levels_len) return states_list_table, path_states, xstates
def test_find_descriptors_new(self): pars = copy.copy(self.parameters) condition_function = lambda key, value: key == 'transition' pathgenerator = PathGenerator() retriever = lambda x, y: (x, y) for t in find_descriptions_new(pars, condition_function, pathgenerator, retriever): t
def edit_functions_in_parameters(conv_pars, configuration_file): condition_function =\ create_condition_parsing_functions_chatbotquery_parameters() folder = os.path.dirname(configuration_file) f_edit = create_parsing_function_functions(parse_parameter_functions, folder) pathgen = PathGenerator() # Parsing son files # edit_in_tree(conv_pars, condition_function, f_edit, if_flatten=False) edit_in_tree_new(conv_pars, condition_function, pathgen, f_edit)
def create_testing_mode_parameters(parameters): ## 0. Parameters parsing parameters = parameters if isinstance(parameters, list) else [parameters] condition_function = create_condition_parsing_chatbotquery_parameters() pathgen = PathGenerator() ## 1. Edit states edit_in_tree_new(parameters, condition_function, pathgen, testing_mode_editing) return parameters
def edit_relative_paths_functions(parameters, configuration_file): # Edit functions condition_function =\ create_condition_parsing_functions_chatbotquery_parameters() folder = os.path.dirname(configuration_file) f_edit = create_abspath_function_functions(folder) pathgen = PathGenerator() # Parsing son files # edit_in_tree(conv_pars, condition_function, f_edit, if_flatten=False) edit_in_tree_new(parameters, condition_function, pathgen, f_edit) return parameters
def test_edit_in_tree_new(self): pars = copy.copy(self.parameters) condition_function = lambda key, value: key == 'transition' pathgenerator = PathGenerator() pars = copy.copy(self.parameters) f_edit = lambda tree: [None] pars = edit_in_tree_new(pars, condition_function, pathgenerator, f_edit, path=None)
def test_pathgen(self): pathgen = PathGenerator() self.assert_pathgen(pathgen) def increment_path_state(key, value, path): new_path = path[:] if isinstance(value, dict): if 'name' in value: if path: new_path = '.'.join([path, value['name']]) else: new_path = value['name'] return new_path def initial_path_state(): return '' def get_last_state(path): return path.split('.')[-1] pars_path = (initial_path_state, increment_path_state, get_last_state) pathgen = PathGenerator(pars_path) self.assert_pathgen(pathgen)
def edit_relative_paths(parameters, configuration_file): # Edit functions def condition_function_paths(tree): "Explorer the tree of states of parameters." logi = False if isinstance(tree, dict): logi = ('filepath' in tree) return logi condition_function =\ create_condition(lambda pathtree: True, condition_function_paths, 'and') folder = os.path.dirname(configuration_file) f_edit = create_abspath_function_functions(folder) pathgen = PathGenerator() # Parsing son files # edit_in_tree(conv_pars, condition_function, f_edit, if_flatten=False) edit_in_tree_new(parameters, condition_function, pathgen, f_edit) return parameters