示例#1
0
 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)
示例#2
0
 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
示例#3
0
    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
示例#4
0
 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
示例#5
0
    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
示例#6
0
 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
示例#7
0
 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