Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/334.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 许多nltk包方法/工具不起作用_Python_Nltk_Natural Language Processing - Fatal编程技术网

Python 许多nltk包方法/工具不起作用

Python 许多nltk包方法/工具不起作用,python,nltk,natural-language-processing,Python,Nltk,Natural Language Processing,1) 我尝试了nltk包官方书籍中名为/Natural Language Processing'的代码,但它给出了错误 dt = nltk.DiscourseTester(['A student dances', 'Every student is a person']) print(dt.readings()) 我得到了错误 NLTK无法找到mace4文件! 使用特定于软件的配置参数或设置PROVER9环境变量 2) 我尝试使用书中的另一个代码: from nltk import load_

1) 我尝试了nltk包官方书籍中名为/Natural Language Processing'的代码,但它给出了错误

dt = nltk.DiscourseTester(['A student dances', 'Every student is a person'])
print(dt.readings())
我得到了错误

NLTK无法找到mace4文件! 使用特定于软件的配置参数或设置PROVER9环境变量

2) 我尝试使用书中的另一个代码:

from nltk import load_parser
parser = load_parser('drt.fcfg', logic_parser=nltk.DrtParser())
trees = parser.parse('Angus owns a dog'.split())
print(trees[0].node['sem'].simplify())
我弄错了

AttributeError:模块“nltk”没有属性“DrtParser”

3) 我尝试了以下代码:

    from nltk.sem import cooper_storage as cs
sentence = 'every girl chases a dog'
trees = cs.parse_with_bindops(sentence, grammar='storage.fcfg')
semrep = trees[0].label()
cs_semrep = cs.CooperStore(semrep)
print(cs_semrep.core)

for bo in cs_semrep.store:
    print(bo)
cs_semrep.s_retrieve(trace=True)
for reading in cs_semrep.readings:
    print(reading)
它工作正常,但仍出现以下错误:

AttributeError:“CooperStore”对象没有属性“core”

4) 我尝试了本书中的另一个代码:

from nltk import load_parser
parser = load_parser('simple-sem.fcfg', trace=0)
sentence = 'Angus gives a bone to every dog'
tokens = sentence.split()
trees = parser.parse(tokens)
for tree in trees:
    print(tree.node['SEM'])
我得到以下错误:

NotImplementedError:使用label()访问节点标签


请告诉我该怎么办?因为我听说nltk的许多特性都是不推荐的,所以这些特性被弃用了吗。请为所有提到的功能建议一种解决方法。

我找到了答案,实际上我是按照书中的代码而不是更新的NLTK的在线版本。因此,遵循更新版本解决了问题。

您使用的是哪些Python和NLTK版本?Python 3.7和NLTK 3.4