I get a NotImplementedError
when i run below code. Why?
import nltk
from nltk import *
from nltk.tag import stanford
from nltk.tag.stanford import StanfordTagger
st = StanfordTagger('C:\\Python27\\stanford-postagger\\models\\english-bidirectional-distsim.tagger',
'C:\\Python27\\stanford-postagger\\stanford-postagger.jar')
print st.tag('What is the airspeed of an unladen swallow ?'.split())
Error Message:
File "C:\Python27\lib\site-packages\nltk\tag\stanford.py", line 51, in _cmd
raise NotImplementedError
NotImplementedError
Looking at the source code here:
The _cmd
method is not implemented in StanfordTagger
- _cmd
property: A property that returns the command that will be
executed.
@property
def _cmd(self):
raise NotImplementedError
So when it is called here causes your problem:
# Run the tagger and get the output
stanpos_output, _stderr = java(self._cmd,classpath=self._stanford_jar, \
stdout=PIPE, stderr=PIPE)
In POSTagger
the method looks like:
@property
def _cmd(self):
return ['edu.stanford.nlp.tagger.maxent.MaxentTagger', \
'-model', self._stanford_model, '-textFile', \
self._input_file_path, '-tokenize', 'false']
You could edit the method in StanfordTagger
to match the POSTTagger
.