第一种:针对单个单词进行词性标注
import java.io.IOException;
import edu.stanford.nlp.tagger.maxent.MaxentTagger;
public class tagger
{
public static void main(String[] args) throws IOException,ClassNotFoundException
{
// Initialize the tagger
MaxentTagger tagger = new MaxentTagger("F:/stanford-postagger-2014-06-16/models/english-left3words-distsim.tagger");
// The sample string
String sample = "text";
// The tagged string
String tagged = tagger.tagString(sample);
// Output the result
System.out.println(tagged);
}
}
第二种:对单句话进行词性标注
class TaggerDemo {
private TaggerDemo() {}
public static void main(String[] args) throws Exception
{
if (args.length != 2)
{
System.err.println("usage: java TaggerDemo modelFile fileToTag"