def set_model(sem_input_file, sem_name, sem_input_macro = True, semantics_name='TCG_semantics_main', grammar_name='TCG_grammar_VB_main', model_params = {}): """ Sets up a TCG production model. Args: - sem_input_file (STR): Semantic input file name - sem_name (STR): Semantic input name - sem_input_macro (BOOL): True is the input is an ISRF macro - semantics_name (STR): Name of the semantic file containing the perceptual, world, and conceptualization knowledge. - grammar_name (STR): Name of the grammar file to use. - model_prams (dict): Dictionary defining the model parameters (if different than default) Returns: (model, semantic input genereator) """ SEM_INPUT_PATH = './data/sem_inputs/' model = TCG_production_system(grammar_name=grammar_name, semantics_name=semantics_name) if model_params: model.update_params(model_params) # Set up semantic input generator conceptLTM = model.schemas['Concept_LTM'] if not(sem_input_macro): sem_inputs = TCG_LOADER.load_sem_input(sem_input_file, SEM_INPUT_PATH) sem_input = {sem_name:sem_inputs[sem_name]} sem_gen = ls.SEM_GENERATOR(sem_input, conceptLTM, speed_param=1) if sem_input_macro: sem_inputs = TCG_LOADER.load_sem_macro(sem_name, sem_input_file, SEM_INPUT_PATH) sem_gen = ls.SEM_GENERATOR(sem_inputs, conceptLTM, speed_param=1) return (model, sem_gen)
def set_inputs(model, input_name, sem_input_file='diagnostic.json', sem_input_macro=False, speed_param=10): """ Sets up a TCG ISRF inputs generator for TCG production model. Args: - model (): model to which the inputs will be sent - input_name (STR): name of the input to be used. - sem_input_file (STR): Semantic input file name. For non-macro input, set to 'ALL' to load all inputs from file. - sem_input_macro (BOOL): True is the input is an ISRF macro. - speed_param (INT): multiplier of the rate defined in the ISRF input (by default the ISFR rate is 1.) Returns: - input SEM_GENERATOR object. """ SEM_INPUT_PATH = './data/sem_inputs/' conceptLTM = model.schemas['Concept_LTM'] if not(sem_input_macro): sem_inputs = TCG_LOADER.load_sem_input(sem_input_file, SEM_INPUT_PATH) if input_name == 'ALL': sem_gen = ls.SEM_GENERATOR(sem_inputs, conceptLTM, speed_param=speed_param, is_macro=sem_input_macro) sem_gen.ground_truths = TCG_LOADER.load_ground_truths(sem_input_file, SEM_INPUT_PATH) else: sem_input = {input_name:sem_inputs[input_name]} sem_gen = ls.SEM_GENERATOR(sem_input, conceptLTM, speed_param=speed_param,is_macro=sem_input_macro) ground_truths = TCG_LOADER.load_ground_truths(sem_input_file, SEM_INPUT_PATH) sem_gen.ground_truths = ground_truths.get(input_name, None) if sem_input_macro: sem_inputs = TCG_LOADER.load_sem_macro(input_name, sem_input_file, SEM_INPUT_PATH) sem_gen = ls.SEM_GENERATOR(sem_inputs, conceptLTM, speed_param=speed_param, is_macro=sem_input_macro) ground_truths = TCG_LOADER.load_ground_truths(sem_input_file, SEM_INPUT_PATH) sem_gen.ground_truths = ground_truths.get(input_name, None) return sem_gen