简体   繁体   English

AttributeError:“ParentedTree”对象没有属性“标签”

[英]AttributeError: 'ParentedTree' object has no attribute 'label'

I am basically working on parsed tree and trying to annotate tree nodes dominating empty categories(Empty node annotation).我基本上正在研究解析树并尝试注释支配空类别的树节点(空节点注释)。

I have defined a recurvsive function as below but the error that I am getting is "AttributeError: 'ParentedTree' object has no attribute 'label'".我已经定义了一个递归函数,但我得到的错误是“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 suggests you're using NLTK, which I'm going to assume is the case. Google 建议您使用 NLTK,我假设是这种情况。

A ParentedTree does not have a method called .label() . ParentedTree没有名为.label .label()的方法。 So when you write things like this:所以当你写这样的东西时:

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

Python doesn't know what to do. Python 不知道该怎么做。

A Tree , on the other hand, does have a .label() method.另一方面, Tree确实有一个.label()方法。 Did you perhaps use a ParentedTree instead of a Tree somewhere?您是否可能在某处使用了 ParentedTree 而不是 Tree?

Could also be a versioning issue.也可能是版本问题。

Worked for me with version 3.3使用 3.3 版为我工作

pip install nltk==3.3

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM