python - 属性错误 : 'ParentedTree' object has no attribute 'label'

标签 python tree nlp nltk corpus

我基本上是在处理已解析的树并尝试注释支配空类别的树节点(空节点注释)。

我定义了一个如下的递归函数,但我得到的错误是“AttributeError:‘ParentedTree’对象没有属性‘label’”。

def annotateTraceNodes(node):
numChildren = len(node);
numNone=0;

    for child in node:
        if isinstance(child,Tree):
            annotateTraceNodes(child);
            if(numChildren==0 or child.label().endswith("-NONE-")):
            numNone+=1;            
    if(numChildren==numNone):
        print "setting the label";
        node.set_label(node.label()+"-NONE-");

最佳答案

Google 建议您使用 NLTK,我假设是这种情况。

A ParentedTree没有名为 .label() 的方法。所以当你这样写的时候:

child.label().endswith("-NONE-")

Python 不知道该做什么。

A Tree ,另一方面,确实有一个 .label() 方法。您是否在某处使用了 ParentedTree 而不是 Tree?

关于python - 属性错误 : 'ParentedTree' object has no attribute 'label' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26622370/

相关文章:

python - Pandas 根据其他行的和/差添加新行

python - 使用 ldap 在 python 中处理错误

python - 导入错误 : 'No module named' *does* exist

C - 使用后序遍历释放二叉树的内存

python - 第 0 行 "good movies"的输出是如何计算的?

python - 如何在 Python 中使用 WordNet 获取词域?

python - 正则表达式,使用字边界进行捕获,而不在 "dot"和/或其他字符处停止

performance - 为什么红黑树比 2-3 棵树更好?

algorithm - 全组合树算法

python - 用于解析体育比赛数据的自然语言解析器