gpt4 book ai didi

python - 属性错误 : 'FeatureChartParser' object has no attribute 'nbest_parse'

转载 作者:太空宇宙 更新时间:2023-11-04 01:04:09 24 4
gpt4 key购买 nike

我正在尝试运行此代码,以进行自然语言处理。

import  nltk
from nltk import load_parser
cp = load_parser('grammars/book_grammars/sql0.fcfg')
query = 'What cities are located in China'
trees = cp.nbest_parse(query.split())
answer = trees[0].node['sem']
q = ' '.join(answer)
print(q)

但我收到以下编译错误:

trees = cp.nbest_parse(query.split())

AttributeError: 'FeatureChartParser' 对象没有属性 'nbest_parse'

我正在使用 python3.4 和 nltk 3.0a4 。我现在可以做什么来运行它?

最佳答案

>>> import  nltk
>>> from nltk import load_parser
>>> cp = load_parser('grammars/book_grammars/sql0.fcfg')
>>> query = 'What cities are located in China'
>>> trees = next(cp.parse(query.split()))
>>> answer = trees[0].label()
>>> answer
NP[SEM=(SELECT, City FROM city_table)]

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

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com