Error when using stanford tagger in python
Asked Answered
W

1

6

This is my code and the error message:

>>> from nltk.tag.stanford import StanfordTagger
>>> st = StanfordTagger('bidirection-distsim-wsj-0-18.tagger')

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/tag/stanford.py", line 42, in __init__
    verbose=verbose)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/nltk/internals.py", line 597, in find_jar
    raise LookupError('\n\n%s\n%s\n%s' % (div, msg, div))
LookupError: 

===========================================================================
  NLTK was unable to find ! Set the CLASSPATH environment variable.

  For more information, on , see:
    <http://nlp.stanford.edu/software>
===========================================================================

How can I fix that? I really want to use stanford tagger in Python Thank you!

Witness answered 20/11, 2012 at 17:32 Comment(0)
T
0
from nltk.tag.stanford import POSTagger

st = POSTagger( < path to tagger >, < path to stanford NLP package/stanford-postagger.jar >)

Include the complete path for both parameters.

If that works, then try a sample sentence

st.tag('What is the airspeed of an unladen swallow ?'.split())

Check if you have added the Stanford Parser path to CLASSPATH environment variable

export CLASSPATH = {CLASSPATH}: < path to stanford NLP package >

This should work.

Toolmaker answered 1/3, 2013 at 2:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.