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
评论列表
文章目录