Akansha
Akansha

Reputation: 21

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 the 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.

Upvotes: 2

Views: 4261

Answers (1)

Mark Elliot
Mark Elliot

Reputation: 77024

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);

Upvotes: 3

Related Questions