Exemplo n.º 1
0
    def from_yaml(yaml_node, constants, text_utils):
        actor = ContinuationAction()

        if isinstance(yaml_node, list):
            for utterance in yaml_node:
                if isinstance(utterance, str):
                    s = replace_constant(utterance, constants, text_utils)
                    actor.phrases.append(SayingPhrase(s))
                else:
                    raise SyntaxError()
        elif isinstance(yaml_node, str):
            s = replace_constant(yaml_node, constants, text_utils)
            actor.phrases.append(SayingPhrase(s))
        else:
            raise NotImplementedError()

        return actor
Exemplo n.º 2
0
    def from_yaml(yaml_node, constants, text_utils):
        actor = ActorSay()

        # TODO: сделать расширенную диагностику ошибок описания!!!

        # Надо понять, тут расширенная форма описания актора или просто список реплик, возможно
        # из одного элемента.
        if isinstance(yaml_node, dict):
            # Расширенный формат.
            for inner_keyword in yaml_node.keys():
                if 'phrases' == inner_keyword:
                    for utterance in yaml_node['phrases']:
                        s = replace_constant(utterance, constants, text_utils)
                        actor.phrases.append(SayingPhrase(s))
                elif 'exhausted' == inner_keyword:
                    for utterance in yaml_node['exhausted']:
                        s = replace_constant(utterance, constants, text_utils)
                        actor.exhausted_phrases.append(SayingPhrase(s))
                elif 'known_answer' == inner_keyword:
                    actor.known_answer_policy = yaml_node[inner_keyword]
                    # TODO - проверить значение флага: 'skip' | 'utter'
                elif 'NP1' == inner_keyword:
                    actor.np_sources['NP1'] = yaml_node[inner_keyword]
                else:
                    raise NotImplementedError()

        elif isinstance(yaml_node, list):
            for utterance in yaml_node:
                if isinstance(utterance, str):
                    s = replace_constant(utterance, constants, text_utils)
                    actor.phrases.append(SayingPhrase(s))
                else:
                    raise SyntaxError()
        elif isinstance(yaml_node, str):
            s = replace_constant(yaml_node, constants, text_utils)
            actor.phrases.append(SayingPhrase(s))
        else:
            raise NotImplementedError()

        return actor
Exemplo n.º 3
0
 def from_yaml(yaml_node, constants, text_utils):
     actor = ActorQueryDb()
     s = replace_constant(yaml_node, constants, text_utils)
     actor.query_template = SayingPhrase(s)
     return actor