【问题标题】:Error In Python Part-Of-Speech Tagging In Ubuntu OSUbuntu OS 中的 Python 词性标记错误
【发布时间】:2013-05-30 05:54:08
【问题描述】:

我用于 POS 标记的 python 代码:

>>> import nltk, csv, itertools
>>> sentence = "Unigram taggers are based on a simple statistical algorithm: for each token, assign the tag that is most likely for that particular token."
>>> tokens = nltk.word_tokenize(sentence)
>>> tags = nltk.pos_tag(tokens)
and the error shown is:
>>> tags = nltk.pos_tag(tokens)
Traceback (most recent call last):
  File "<pyshell#7>", line 1, in <module>
    tags = nltk.pos_tag(tokens)
  File "/usr/local/lib/python2.7/dist-packages/nltk/tag/__init__.py", line 99, in pos_tag
    tagger = load(_POS_TAGGER)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 605, in load
    resource_val = pickle.load(_open(resource_url))
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 686, in _open
    return find(path).open()
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 455, in find
    try: return find(modified_name)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 445, in find
    try: return ZipFilePathPointer(p, zipentry)
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 311, in __init__
    zipfile = OpenOnDemandZipFile(os.path.abspath(zipfile))
  File "/usr/local/lib/python2.7/dist-packages/nltk/data.py", line 738, in __init__
    zipfile.ZipFile.__init__(self, filename)
  File "/usr/lib/python2.7/zipfile.py", line 714, in __init__
    self._GetContents()
  File "/usr/lib/python2.7/zipfile.py", line 748, in _GetContents
    self._RealGetContents()
  File "/usr/lib/python2.7/zipfile.py", line 763, in _RealGetContents
    raise BadZipfile, "File is not a zip file"
BadZipfile: File is not a zip file

有没有要包含的python模块??

解决办法是什么?

【问题讨论】:

标签: python pos-tagger


【解决方案1】:

而不是使用 pos_tag

应用这个

nltk.download("maxent_treebank_pos_tagger")
nltk.download("maxent_ne_chunker")
nltk.download("punkt")

前两个用于 pos_tag,最后一个用于 sent_tokenizer

【讨论】:

  • 欢迎来到 SO 并祝贺您的​​第一个答案。请记住以体面的方式格式化代码,并在需要时为您的答案提供解释。
猜你喜欢
  • 1970-01-01
  • 2014-07-23
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-14
  • 2016-03-29
  • 2015-08-29
相关资源
最近更新 更多