matcher.py 文件源码

python
阅读 26 收藏 0 点赞 0 评论 0

项目:Lango 作者: ayoungprogrammer 项目源码 文件源码
def match_template(tree, template, args=None):
    """Check if match string matches Tree structure

    Args:
        tree (Tree): Parsed Tree structure of a sentence
        template (str): String template to match. Example: "( S ( NP ) )"
    Returns:
        bool: If they match or not
    """
    tokens = get_tokens(template.split())
    cur_args = {}
    if match_tokens(tree, tokens, cur_args):
        if args is not None:
            for k, v in cur_args.items():
                args[k] = v
        logger.debug('MATCHED: {0}'.format(template))
        return True
    else:
        return False
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号