2011-02-23 65 views
4

我已經嘗試過下面的代碼和從http://code.google.com/p/hunpos/downloads/list有誰知道如何在nltk上配置hunpos包裝類?

安裝 英語 - 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命令?

回答

4

您非常接近解決方案。將hunpos-tag可執行文件移動到/ home/ubi/bin,然後它應該能夠找到它。當我第一次嘗試使用hunpos時,這也造成了一些麻煩。

+0

是的hunpos需要被移動到這些目錄中的任何一個。謝謝! – alvas 2011-02-26 04:17:21

相關問題