def getLeaves(ptree):
import nltk
rs = []
if isinstance(ptree, nltk.tree.ParentedTree):
if len(ptree)>0:
if isinstance(ptree[0], unicode):
rs.append(ptree)
for node in ptree:
if isinstance(node, nltk.tree.ParentedTree):
if len(node)>0:
if isinstance(node[0], unicode):
rs.append(node)
else:
rs.extend(getLeaves(node))
return rs
评论列表
文章目录