Example usage for opennlp.tools.parser Parse insert

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

Introduction

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

Prototype

public void insert(final Parse constituent) 

Source Link

Document

Inserts the specified constituent into this parse based on its text span.This method assumes that the specified constituent can be inserted into this parse.

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 ww  .  j av a2 s .  com*/

    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();
        }
    }
}

From source file:util.text.OpenNLP.java

public static Parse parseLine(String text) {
    final Parse p = new Parse(text,
            // a new span covering the entire text
            new Span(0, text.length()),
            // the label for the top if an incomplete node
            AbstractBottomUpParser.INC_NODE,
            // the probability of this parse...uhhh...?
            1,/*from www.ja  v a 2  s  . c om*/
            // the token index of the head of this parse
            0);

    // make sure to initialize the _tokenizer correctly
    final Span[] spans = tokenizer_.tokenizePos(text);

    for (int idx = 0; idx < spans.length; idx++) {
        final Span span = spans[idx];
        // flesh out the parse with individual token sub-parses
        p.insert(new Parse(text, span, AbstractBottomUpParser.TOK_NODE, 0, idx));
    }
    return parser_.parse(p);
}