Example usage for opennlp.tools.postag POSSample toString

List of usage examples for opennlp.tools.postag POSSample toString

Introduction

In this page you can find the example usage for opennlp.tools.postag POSSample toString.

Prototype

@Override
    public String toString() 

Source Link

Usage

From source file:os.Controller.java

public static String POSTag(String a) throws IOException {
    POSModel model = new POSModelLoader().load(new File("en-pos-maxent.bin"));
    PerformanceMonitor perfMon = new PerformanceMonitor(System.err, "sent");
    POSTaggerME tagger = new POSTaggerME(model);

    ObjectStream<String> lineStream = new PlainTextByLineStream(new StringReader(a));

    perfMon.start();//from w w w. ja v a2 s .  c o m
    String line, result = "";
    while ((line = lineStream.read()) != null) {

        String whitespaceTokenizerLine[] = WhitespaceTokenizer.INSTANCE.tokenize(line);
        String[] tags = tagger.tag(whitespaceTokenizerLine);

        POSSample sample = new POSSample(whitespaceTokenizerLine, tags);
        result = result + sample.toString();

        perfMon.incrementCounter();
    }
    perfMon.stopAndPrintFinalResult();
    textList.add(result);
    return result;
}