コード例 #1
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)
コード例 #2
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)
コード例 #3
0
ファイル: builtinfunctions.py プロジェクト: zhiyin121/adviser
    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)