Example usage for opennlp.tools.parser Parse setType

List of usage examples for opennlp.tools.parser Parse setType

Introduction

In this page you can find the example usage for opennlp.tools.parser Parse setType.

Prototype

public void setType(String type) 

Source Link

Document

Set the type of this constituent to the specified type.

Usage

From source file:de.tudarmstadt.ukp.dkpro.core.opennlp.OpenNlpParser.java

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    CAS cas = aJCas.getCas();//  w w w.ja  va  2  s .  c o  m

    modelProvider.configure(cas);
    mappingProvider.configure(cas);

    for (Sentence sentence : select(aJCas, Sentence.class)) {
        List<Token> tokens = selectCovered(aJCas, Token.class, sentence);

        Parse parseInput = new Parse(cas.getDocumentText(), new Span(sentence.getBegin(), sentence.getEnd()),
                AbstractBottomUpParser.INC_NODE, 0, 0);
        int i = 0;
        for (Token t : tokens) {
            parseInput.insert(new Parse(cas.getDocumentText(), new Span(t.getBegin(), t.getEnd()),
                    AbstractBottomUpParser.TOK_NODE, 0, i));
            i++;
        }

        Parse parseOutput = modelProvider.getResource().parse(parseInput);

        createConstituentAnnotationFromTree(aJCas, parseOutput, null, tokens);

        if (createPennTreeString) {
            StringBuffer sb = new StringBuffer();
            parseOutput.setType("ROOT"); // in DKPro the root is ROOT, not TOP
            parseOutput.show(sb);

            PennTree pTree = new PennTree(aJCas, sentence.getBegin(), sentence.getEnd());
            pTree.setPennTree(sb.toString());
            pTree.addToIndexes();
        }
    }
}