treeBinarizer.py 文件源码

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

项目:koalaNLP 作者: yuchenz 项目源码 文件源码
def vvBinarize(tr):
    children = []
    vvIndex = None
    for i, child in enumerate(tr):
        children.append(child)
        if child.node in vvTags: 
            vvIndex = i

    if vvIndex == None:
        print >> sys.stderr, "no vv in the children!!!",
        output(tr)
        return

    tmpNode = nltk.Tree("(X)")
    for i in xrange(vvIndex, len(tr)):
        tmpNode.append(children[i])
    leftBinarize(tmpNode)

    while len(tr) > vvIndex:
        tr.pop()
    tr.append(tmpNode)
    rightBinarize(tr)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号