tree下subtree.node NotImplementedError: Use label() to access a node label.报错



import nltk, re
cp = nltk.RegexpParser('CHUNK: {<V.*><TO><V.*>}')
brown = nltk.corpus.brown
for sent in brown.tagged_sents():
	tree = cp.parse(sent)
	for subtree in tree.subtrees():
		if subtree.label() == "CHUNK":
			print(subtree)

以上为修改好的程序,在使用sbutree.node时发现该方法已经不存在,推荐使用subtree.label()


help(subtree.label)

Help on method label in module nltk.tree:

label() method of nltk.tree.Tree instance
    Return the node label of the tree.
    
        >>> t = Tree.fromstring('(S (NP (D the) (N dog)) (VP (V chased) (NP (D the) (N cat))))')
        >>> t.label()
        'S'
    
    :return: the node label (typically a string)


>>> help(subtree.node)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python3.5/dist-packages/nltk/tree.py", line 202, in _get_node
    raise NotImplementedError("Use label() to access a node label.")
NotImplementedError: Use label() to access a node label.

以下是我作出修改的证据,如果什么时候我的这个代码无效,别举报我故意糊弄人就行




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值