def find_tree_matches(tree,pat):
"""
Get all subtrees matching pattern
@type tree: DepTree
@param tree: tree in which to search for matches
@type pat: nltk.Tree
@param pat: a pattern to match against tree
@rtype: list [unification of pat]
@return: all possible unification of pat in tree
"""
ret = []
curMatch = tree.match(pat)
if curMatch:
ret.append(curMatch)
for c in tree.children:
ret.extend(find_tree_matches(c,pat))
return ret
评论列表
文章目录