gpt4 book ai didi

java - hazm 库的 ValueError : Could not find stanford-postagger. jar 文件 - python NLP

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:46:53 27 4
gpt4 key购买 nike

我想运行一段需要 stanford postagger.jar 的代码。但我有这个错误:

  File "/usr/lib/python2.7/site-packages/nltk/internals.py", line 562, in find_jar
(name, path_to_jar))
ValueError: Could not find stanford-postagger.jar jar file at resources/stanford-postagger.jar

我该如何解决这个错误?

编辑:我使用来自 hazm模块:

from hazm import POSTagger
tagger = POSTagger()
tagger.tag(word_tokenize('ما بسیار کتاب می‌خوانیم'))

和完整的结果:

Traceback (most recent call last):
File "pyt.py", line 8, in <module>
tagger = POSTagger()
File "/home/vahid/dev/hazm/hazm/POSTagger.py", line 14, in __init__
super(stanford.POSTagger, self).__init__(*args, **kwargs)
File "/usr/lib/python2.7/site-packages/nltk/tag/stanford.py", line 42, in __init__
verbose=verbose)
File "/usr/lib/python2.7/site-packages/nltk/internals.py", line 562, in find_jar
(name, path_to_jar))
ValueError: Could not find stanford-postagger.jar jar file at resources/stanford-postagger.jar

最佳答案

您首先需要来自斯坦福的 postagger.jar 文件并训练您自己的标注器。但是 hazm 开发人员已在此处上传了您需要的资源目录:http://dl.dropboxusercontent.com/u/90405495/resources.zip

您需要解压缩文件夹并将其保存到运行脚本的目录中。

例如:

$ mkdir testdir
$ wget https://github.com/sobhe/hazm/archive/master.zip
$ unzip master.zip -d testdir
$ cd testdir
$ mv hazm-master/hazm/ .
$ wget http://dl.dropboxusercontent.com/u/90405495/resources.zip
$ unzip resources.zip -d .
$ python
Python 2.7.5+ (default, Sep 19 2013, 13:48:49)
[GCC 4.8.1] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import hazm
>>> tagger = hazm.POSTagger()
>>> tagger.tag(hazm.word_tokenize(u'ما بسیار کتاب می‌خوانیم'))
[(u'\u0645\u0627', u'PR'), (u'\u0628\u0633\u06cc\u0627\u0631', u'ADV'), (u'\u06a9\u062a\u0627\u0628', u'N'), (u'\u0645\u06cc\u200c\u062e\u0648\u0627\u0646\u06cc\u0645', u'V')]

关于java - hazm 库的 ValueError : Could not find stanford-postagger. jar 文件 - python NLP,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21909165/

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