Can't make Stanford POS tagger working in nltk

半城伤御伤魂 提交于 2019-11-30 14:53:21

Lot has changed since this solution.Here is my solution to the code,after I too faced the error.Basically increasing JAVA heapsize solved it.

import os
java_path = "C:\\Program Files\\Java\\jdk1.8.0_102\\bin\\java.exe"
os.environ['JAVAHOME'] = java_path

from nltk.tag.stanford import StanfordPOSTagger
path_to_model = "stanford-postagger-2015-12-09/models/english-bidirectional-distsim.tagger"
path_to_jar = "stanford-postagger-2015-12-09/stanford-postagger.jar"
tagger=StanfordPOSTagger(path_to_model, path_to_jar)
tagger.java_options='-mx4096m'          ### Setting higher memory limit for long sentences
sentence = 'This is testing'
print tagger.tag(sentence.split())

The best thing to do is simply to download the latest version of the Stanford POS tagger where the dependency problem is now fixed (March 2018).

wget https://nlp.stanford.edu/software/stanford-postagger-full-2017-06-09.zip
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!