edu.stanford.nlp.tagger.maxent
Class StaticStringTagger

java.lang.Object
  |
  +--edu.stanford.nlp.tagger.maxent.StaticStringTagger
All Implemented Interfaces:
Appliable

public class StaticStringTagger
extends Object
implements Appliable

Static version of StringTagger. Convenience class that takes a String input and outputs the tagged version of the String. The String is assumed to be untagged.

The Tagger must be initialized using a static call init that takes in a trained model, which is loaded immediately (takes a long time...); subsequent attempts to initialize the tagger will be no-ops, therefore it is safe to call init ad infinitum. Then subsequent calls to tagString can be executed, passing in an untagged String; a tagged String is returned, unless there was a serious problem in the Tagging machinery, in which case null is returned.

Example:
StaticStringTagger.init("/u/nlp/data/tagger.params/wsj0-21.holder");
String taggedString = StaticStringTagger.tagString("Here's a tagged string.");
String taggedString2 = StaticStringTagger.tagString("This is your life.");

The output is

Here's/JJ a/DT tagged/VBD string./NNP

and

This/DT is/VBZ your/PRP$ life./NN respectively.

Note that in precisely the above fashion, this tagger just splits on white space when tagging, but the tagger expects input tokenized as in the Penn Treebank. Unless a prior tokenization step is done, the tagger will perform poorly.


Method Summary
 Object apply(Object in)
          Implementing the interface Applicable
static void init(String fileModel)
          Initializer that loads the dictionary.
static void main(String[] argv)
          Command-line tagger that takes input from stdin or a file.
static String tagString(String toTag)
          Tags the input string and returns the tagged version.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

init

public static void init(String fileModel)
Initializer that loads the dictionary. This maintains a flag as to whether initialization has been done previously, and if so, running this is a no-op.

Parameters:
fileModel - Filename of the trained model, for example "/u/nlp/data/tagger.params/wsj0-21.holder"

tagString

public static String tagString(String toTag)
Tags the input string and returns the tagged version. The tagger wants input that is space separated tokens, tokenized according to the conventions of the Penn Treebank.

Parameters:
toTag - The untagged input String
Returns:
The same string with tags inserted

apply

public Object apply(Object in)
Implementing the interface Applicable

Specified by:
apply in interface Appliable

main

public static void main(String[] argv)
Command-line tagger that takes input from stdin or a file. This is mainly intended just for testing.

Parameters:
argv - There can be no arguments, or a file to read a tagger from and a file to tag can be supplied:
java edu.stanford.nlp.tagger.maxent.StaticStringTagger [modelName [fileName]]
The fileName or other input is assumed to be one sentence per line.


Stanford NLP Group