calling Stanford POS Tagger maxentTagger from java program
I am new to Stanford POS tagger.
I need to call the Tagger from my java program and direct the output to a text file. I have extracted th开发者_StackOverflow中文版e source files from Stanford-postagger and tried calling the maxentTagger, but all I find is errors and warnings.
Can somebody tell me from the scratch about how to call maxentTagger in my program, setting the classpath if required and other such steps. Please help me out.
Well, when you compile or invoke your program you need to add Stanford's JAR file to your classpath, e.g.:
java -classpath stanford-postagger.jar [MyProgram]
Then in your code you'll need to import the relevant packages, most things you need seem to be in edu.stanford.nlp.tagger.maxent
.
Instantiating a new MaxentTagger
is well described in the JavaDoc, but I'll repeat some of it here:
To create a new tagger:
MaxentTagger tagger = new MaxentTagger("models/left3words-wsj-0-18.tagger");
To tag a String
with this tagger
:
String taggedString = tagger.tagString("Here's a tagged string.")
Additionally you can create and tag sentences using Stanford's NLP tools. Create a sentence by reading a file using a BufferedReader
:
Sentence sentence = Sentence.readOneSentence(in); // in is a BufferedReader
Then tag the sentence as with your tagger
:
Sentence taggedSentence = tagger.tagSentence(sentence);
精彩评论