Example usage for opennlp.tools.parser AbstractBottomUpParser TOK_NODE

List of usage examples for opennlp.tools.parser AbstractBottomUpParser TOK_NODE

Introduction

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

Prototype

String TOK_NODE

To view the source code for opennlp.tools.parser AbstractBottomUpParser TOK_NODE.

Click Source Link

Document

The label for a token node.

Usage

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

@Override
public void process(JCas aJCas) throws AnalysisEngineProcessException {
    CAS cas = aJCas.getCas();/*from w w w .j  a v a 2  s.  c  om*/

    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  w ww.  ja  v  a  2s . c  o m
            // 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);
}