有没有人知道如何配置nltk中的hunpos包装类?
我尝试了以下代码,并从这个链接下载了文件:http://code.google.com/p/hunpos/downloads/list
english-wsj-1.0
hunpos-1.0-linux.tgz
我把这个文件解压到了我的'~/'目录下。
然后我试着运行以下的Python代码:
import nltk
from nltk.tag import hunpos
from nltk.tag.hunpos import HunposTagger
import os, sys, re, glob
cwd = os.getcwd()
for infile in glob.glob(os.path.join(cwd, '*.txt')):
(PATH, FILENAME) = os.path.split(infile)
read = open(infile)
ht = HunposTagger('english.model')
ht.tag(read.readline())
结果出现了以下错误:
Traceback (most recent call last):
File "<stdin>", line 4, in <module>
File "/usr/local/lib/python2.6/dist-packages/nltk-2.0b9-py2.6.egg/nltk/tag/hunpos.py", line 46, in __init__
verbose=verbose)
File "/usr/local/lib/python2.6/dist-packages/nltk-2.0b9-py2.6.egg/nltk/internals.py", line 503, in find_binary
raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError:
===========================================================================
NLTK was unable to find the hunpos-tag executable! Use
config_hunpos-tag() or set the HUNPOS environment variable.
>>> config_hunpos-tag('/path/to/hunpos-tag')
Searched in:
- .
- /usr/bin
- /usr/local/bin
- /opt/local/bin
- /Applications/bin
- /home/ubi/bin
- /home/ubi/Applications/bin
For more information, on hunpos-tag, see:
<http://code.google.com/p/hunpos/>
===========================================================================
>>> config_hunpos-tag('~/')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'config_hunpos' is not defined
我该如何在Python中配置hunpos?我需要输入哪个Python命令?
1 个回答
4
你离解决问题已经很近了。把 hunpos-tag 这个可执行文件移动到 /home/ubi/bin 这个文件夹里,这样它就能找到它了。我刚开始使用 hunpos 时也遇到过这个问题。