Example usage for opennlp.tools.parser Parse Parse

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

Introduction

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

Prototype

public Parse(String text, Span span, String type, double p, Parse h) 

Source Link

Document

Creates a new parse node for this specified text and span of the specified type with the specified probability and the specified head and head index.

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 .  ja  v  a 2 s  .  co  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();
        }
    }
}

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,/* w  w  w.  j  a va2s.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);
}