Beispiel #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)
Beispiel #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
Beispiel #3
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
Beispiel #4
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
Beispiel #5
0
    def apply(self, parameters: Memory = None) -> str:
        function = parameters.get_function(parameters.variables[1].value)
        extra_arguments = [
            variable.value for variable in parameters.variables[6:]
        ]
        texts_per_slot: List[str] = []

        for slot_values_pair in parameters.variables[0].value:
            slot_texts: List[str] = []
            for value in slot_values_pair[1]:
                memory = self._build_memory(slot_values_pair[0], value,
                                            extra_arguments)
                if not function.is_applicable(memory):
                    raise BaseException(
                        f'The function {function.function_name} could not be '
                        f'called from the for_entry_list function')
                slot_texts.append(function.apply(memory))
            text = self._create_text_from_elements(
                slot_texts, parameters.variables[2].value,
                parameters.variables[3].value)
            texts_per_slot.append(text)

        return self._create_text_from_elements(texts_per_slot,
                                               parameters.variables[4].value,
                                               parameters.variables[5].value)
Beispiel #6
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
Beispiel #7
0
    def apply(self, parameters: Memory = None) -> str:
        function = parameters.get_function(parameters.variables[1].value)
        extra_arguments = [variable.value for variable in parameters.variables[4:]]
        texts: List[str] = []

        for value in parameters.variables[0].value:
            memory = self._build_memory(value, extra_arguments)
            if not function.is_applicable(memory):
                raise BaseException(f'The function {function.function_name} could not be called '
                                    f'from the for function')
            texts.append(function.apply(memory))

        return self._create_text_from_elements(texts, parameters.variables[2].value,
                                               parameters.variables[3].value)
Beispiel #8
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
Beispiel #9
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
Beispiel #10
0
 def evaluate(self, environment: Memory) -> str:
     variable_value = environment.get_variable_value(self.variable)
     return environment.get_member(variable_value, self.attribute)
Beispiel #11
0
 def evaluate(self, environment: Memory) -> str:
     return environment.get_variable_value(self.name)