2011-02-23 3 views
4

는 다음 코드를 시도누구나 nltk에서 hunpos 래퍼 클래스를 구성하는 방법을 알고 있습니까?

http://code.google.com/p/hunpos/downloads/list에서 설치 한 영어 WSJ -1.0 난 '상으로 파일을 압축 해제 한

hunpos-1.0 linux.tgz ~/'디렉토리

그리고 내가 다음과 같은 파이썬 코드를 시도 :

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 

은 내가 어떻게 파이썬에서 hunpos를 구성 할 다음과 같은 오류가? 어떤 파이썬 명령을 입력해야합니까?

답변

4

당신은 솔루션에 매우 가깝습니다. hunpos-tag 실행 파일을/home/ubi/bin으로 옮기면 찾아 낼 수 있습니다. 이것은 내가 처음으로 hunpos를 사용할 때 약간의 문제를 일으켰습니다.

+0

옙 hunpos는 그 dir 중 하나로 이동해야합니다. 감사! – alvas

관련 문제