2012-11-20 6 views
6

Das ist mein Code ist und die Fehlermeldung:Fehler bei Verwendung von Stanford-Tagger in Python

>>> 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> 
=========================================================================== 

Wie kann ich das Problem lösen? Ich möchte wirklich Stanford Tagger in Python verwenden Vielen Dank!

Antwort

1
from nltk.tag.stanford import POSTagger 

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

Fügen Sie den vollständigen Pfad für beide Parameter ein.

Wenn das funktioniert, dann versuchen Sie einen Beispielsatz

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

Überprüfen Sie, ob Sie die Stanford Parser Pfad zu CLASSPATH Umgebung hinzugefügt haben variable

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

Diese funktionieren sollte.

Verwandte Themen