Example usage for opennlp.tools.util Sequence getOutcomes

List of usage examples for opennlp.tools.util Sequence getOutcomes

Introduction

In this page you can find the example usage for opennlp.tools.util Sequence getOutcomes.

Prototype

public List<String> getOutcomes() 

Source Link

Document

Returns a list of outcomes for this sequence.

Usage

From source file:com.textocat.textokit.postagger.opennlp.OpenNLPPosTagger.java

private void process(JCas jCas, Sentence sent) throws AnalysisEngineProcessException {
    Collection<Token> tokens = JCasUtil.selectCovered(jCas, Token.class, sent);
    Token[] tokenArr = tokens.toArray(new Token[tokens.size()]);
    Sequence bestOutSeq = beam.bestSequence(tokenArr, new Object[] { sent });
    if (bestOutSeq == null) {
        getLogger().warn(String.format("Can't infer best sequence for sentence in %s:\n%s",
                getDocumentUri(jCas), toPrettyString(sent)));
        return;//w ww  .j  av a 2s  . com
    }
    List<String> out = bestOutSeq.getOutcomes();
    if (out.size() != tokens.size()) {
        throw new IllegalStateException("InputSeq.size != OutputSeq.size");
    }
    Iterator<Token> tokenIter = tokens.iterator();
    Iterator<String> outIter = out.iterator();
    while (tokenIter.hasNext()) {
        Token token = tokenIter.next();
        String tag = postProcessExternalTag(outIter.next());
        if (isWordTag(token, tag)) {
            Word word = new Word(jCas, token.getBegin(), token.getEnd());
            word.setToken(token);

            Wordform wf = new Wordform(jCas);
            wf.setWord(word);
            wf.setPos(tag);
            String[] gramArr = splitIntoGrammemes(tag);
            if (gramArr != null) {
                wf.setGrammems(FSUtils.toStringArray(jCas, gramArr));
            }
            word.setWordforms(FSUtils.toFSArray(jCas, wf));

            word.addToIndexes();
        }
    }
}