2011-12-21 2 views
27

방금 ​​일부 품사 태그 사용을 시작했으며 많은 문제에 직면하고 있습니다. NLTK POS tagger에서 다운로드를 요청하는 것은 무엇입니까?

내가 POS는 다음과 같이 태그 시작 :

import nltk 
text=nltk.word_tokenize("We are going out.Just you and me.") 

내가 'text'를 인쇄 할 때 다음 상황이 발생합니다

print nltk.pos_tag(text) 
Traceback (most recent call last): 
File "<stdin>", line 1, in <module> 
File "F:\Python26\lib\site-packages\nltk\tag\__init__.py", line 63, in pos_tag 
tagger = nltk.data.load(_POS_TAGGER) 
File "F:\Python26\lib\site-packages\nltk\data.py", line 594, in load 
resource_val = pickle.load(_open(resource_url)) 
File "F:\Python26\lib\site-packages\nltk\data.py", line 673, in _open 
return find(path).open() 
File "F:\Python26\lib\site-packages\nltk\data.py", line 455, in find 
    raise LookupError(resource_not_found)` 
LookupError: 
Resource 'taggers/maxent_treebank_pos_tagger/english.pickle' not 
found. Please use the NLTK Downloader to obtain the resource: 

>>> nltk.download(). 

Searched in: 
    - 'C:\\Documents and Settings\\Administrator/nltk_data' 
    - 'C:\\nltk_data' 
    - 'D:\\nltk_data' 
    - 'E:\\nltk_data' 
    - 'F:\\Python26\\nltk_data' 
    - 'F:\\Python26\\lib\\nltk_data' 
    - 'C:\\Documents and Settings\\Administrator\\Application Data\\nltk_data' 

나는 nltk.download()를 사용했지만 작동하지 않았다.

+0

왜 모든 텍스트를 굵게 쓰고 있습니까? 이것은 실제로 필요하지 않습니다. 또한 오류를 나타내는 최소한이지만 완전한 예제를 게시하십시오. –

+0

거기, 나는 너를 위해 그것을 청소했다. 향후 질문의 형식을 지정하는 방법에 대한 예를 들어 보시기 바랍니다. –

+0

감사합니다 ... 문제가 해결되었습니다 ... – Pearl

답변

27

nltk.download()을 Python으로 입력하면 NLTK Downloader 인터페이스가 자동으로 표시됩니다.
모델을 클릭하고 maxent_treebank_pos_를 선택하십시오. 자동으로 설치됩니다.

import nltk 
text=nltk.word_tokenize("We are going out.Just you and me.") 
print nltk.pos_tag(text) 
[('We', 'PRP'), ('are', 'VBP'), ('going', 'VBG'), ('out.Just', 'JJ'), 
('you', 'PRP'), ('and', 'CC'), ('me', 'PRP'), ('.', '.')] 
+16

tagger 이름'nltk.download ('maxent_treebank_pos_tagger');'를 지정하면 코드에서 직접 다운로드 할 수 있습니다. 이 게시물 http : // stackoverflow를 참조하십시오.com/a/5208563/62921 – ForceMagic

1
import nltk 
text = "Obama delivers his first speech." 

sent = nltk.sent_tokenize(text) 


loftags = [] 
for s in sent: 
    d = nltk.word_tokenize(s) 

    print nltk.pos_tag(d) 

결과 : akshayy

@ 우분투 : ~/써머 $ 파이썬 nn1.py [('오바마', 'NNP가'), ('제공', 'NNS') ('자기', 'PRP $') ('제', 'JJ') ('언어', 'NN') ('.', '.')]

(방금이 코드를 사용하는 곳에서 다른 질문을했습니다)

+1

이 구문 분석은 ** 잘못된 **입니다 - POS 태거가 복수 명사로 "배송 됨"으로 표시되었음을 유의해야합니다. – simon

1
nltk.download() 

모델을 클릭하고 maxent_treebank_pos_를 선택하십시오. 자동으로 설치됩니다.

쉘/터미널에서
import nltk 
text=nltk.word_tokenize("We are going out.Just you and me.") 
print nltk.pos_tag(text) 
[('We', 'PRP'), ('are', 'VBP'), ('going', 'VBG'), ('out.Just', 'JJ'), 
('you', 'PRP'), ('and', 'CC'), ('me', 'PRP'), ('.', '.')] 
5

, 당신은 사용할 수 있습니다

python -m nltk.downloader maxent_treebank_pos_tagger 

그것은 NLTK에 maxent_treebank_pos_tagger (즉, 표준 treebank의 POS 술래를 설치합니다

(리눅스에 sudo를해야 할 수 있습니다)) 문제를 해결하십시오.

21

V3.2보다 높은 NLTK 버전에서 사용하십시오 :

>>> import nltk 
>>> nltk.__version__ 
'3.2.1' 
>>> nltk.download('averaged_perceptron_tagger') 
[nltk_data] Downloading package averaged_perceptron_tagger to 
[nltk_data]  /home/alvas/nltk_data... 
[nltk_data] Package averaged_perceptron_tagger is already up-to-date! 
True 

NLTK에 대한 버전을 아래 이전 MaxEnt 모델, 즉 3.1 등을 사용하여, 사용하십시오 :

>>> import nltk 
>>> nltk.download('maxent_treebank_pos_tagger') 
[nltk_data] Downloading package maxent_treebank_pos_tagger to 
[nltk_data]  /home/alvas/nltk_data... 
[nltk_data] Package maxent_treebank_pos_tagger is already up-to-date! 
True 

들어 기본 변경의 자세한 내용은 pos_tag입니다. https://github.com/nltk/nltk/pull/1143

관련 문제