def evaluate(self, environment: Memory) -> str: function = environment.get_function(self.name) parameters = Memory(environment.global_memory) for i in range(len(self.arguments)): parameters.add_variable( Variable(f'arg{i}', self.arguments[i].evaluate(environment))) return function.apply(parameters)
def _build_memory_without_free_parameter(self, argument_values: List[object], global_memory: GlobalMemory) -> Memory: assert len(self.argument_names) == len(argument_values) variables = Memory(global_memory) for i in range(len(self.argument_names)): variables.add_variable(Variable(self.argument_names[i], argument_values[i])) return variables
def _build_memory_with_free_parameter(self, argument_values: List[object]) -> Memory: variables = Memory(global_memory) for i in range(len(self.argument_names)): variables.add_variable(Variable(self.argument_names[i], argument_values[i])) variables.add_variable(Variable(self.free_parameter.variable_name, argument_values[len(self.argument_names):])) return variables
def _build_memory_without_free_parameter( self, slot_dict: Dict[str, object], global_memory: GlobalMemory) -> Memory: assert len(self.slot_names) == len(slot_dict) variables = Memory(global_memory) for slot in self.slot_names: value = self._flatten_value_list(slot_dict[slot]) variables.add_variable(Variable(slot, value)) return variables
def _build_memory_with_free_parameter( self, slot_dict: Dict[str, object], global_memory: GlobalMemory) -> Memory: variables = Memory(global_memory) for slot in self.slot_names: value = self._flatten_value_list(slot_dict[slot]) variables.add_variable(Variable(slot, value)) slot_dict.pop(slot) slot_value_pairs = [] for slot in slot_dict: value = self._flatten_value_list(slot_dict[slot]) slot_value_pairs.append((slot, value)) variables.add_variable(Variable(self.free_parameter, slot_value_pairs)) return variables
def _build_memory(self, slot: str, value: str, arguments: List[str]): memory = Memory(self.global_memory) memory.add_variable(Variable('slot', slot)) memory.add_variable(Variable('value', value)) for i, argument in enumerate(arguments): memory.add_variable(Variable(f'arg{i}', argument)) return memory
def _create_memory_from_user_act(self, user_act: UserAct) -> Memory: slots = Memory(self.global_memory) if user_act.slot is not None: slots.add_variable(Variable(user_act.slot, user_act.value)) return slots