对文本进行pos-tag

taolin2014 发布于 2014/05/28 09:54
阅读 1K+
收藏 0

我想对文本进行pos-tag

import nltk;
file_object = open('E:\\practise\\Web1T5-Easy-1.1\\3grams\\3gm-0000.txt')
try:
     for eachline in file_object:     
        print eachline,;
        text = nltk.word_tokenize(eachline)
        nltk.pos_tag(text)
     
finally:
     file_object.close( )
但是结果显示

> "D:\software\python\Python27\python.exe" -u "E:\practise\python\postagger_test.py" 
! " '' 508
Traceback (most recent call last):
  File "E:\practise\python\postagger_test.py", line 7, in <module>
    nltk.pos_tag(text)
  File "D:\software\python\Python27\lib\site-packages\nltk\tag\__init__.py", line 99, in pos_tag
    tagger = load(_POS_TAGGER)
  File "D:\software\python\Python27\lib\site-packages\nltk\data.py", line 768, in load
    opened_resource = _open(resource_url)
  File "D:\software\python\Python27\lib\site-packages\nltk\data.py", line 873, in _open
    return find(_path, path + ['']).open()
  File "D:\software\python\Python27\lib\site-packages\nltk\data.py", line 615, in find
    raise LookupError(resource_not_found)
LookupError: 
**********************************************************************
  Resource u'taggers/maxent_treebank_pos_tagger/english.pickle'
  not found.  Please use the NLTK Downloader to obtain the
  resource:  >>> nltk.download()
  Searched in:
    - 'C:\\Users\\Administrator/nltk_data'
    - 'C:\\nltk_data'
    - 'D:\\nltk_data'
    - 'E:\\nltk_data'
    - 'D:\\software\\python\\Python27\\nltk_data'
    - 'D:\\software\\python\\Python27\\lib\\nltk_data'
    - 'C:\\Users\\Administrator\\AppData\\Roaming\\nltk_data'
    - u''
**********************************************************************
我想问一下有什么问题吗?那位大神告诉我一下可以把pos-tag完了之后的结果输出到另一个文本。谢谢


加载中
0
红烧肉
你没安装NLTK吧,需要下载数据包的
返回顶部
顶部