Example usage for opennlp.tools.parser Parse getText

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

Introduction

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

Prototype

public String getText() 

Source Link

Document

Returns the text of the sentence over which this parse was formed.

Usage

From source file:opennlp.tools.apps.relevanceVocabs.PhraseProcessor.java

public ArrayList<String> getNounPhrases(Parse p) {
    ArrayList<String> nounphrases = new ArrayList<String>();

    Parse[] subparses = p.getChildren();
    for (int pi = 0; pi < subparses.length; pi++) {

        if (subparses[pi].getType().equals("NP") && allChildNodesArePOSTags(subparses[pi])) {
            Span _span = subparses[pi].getSpan();
            nounphrases.add(p.getText().substring(_span.getStart(), _span.getEnd()));
        } else if (!((Parse) subparses[pi]).isPosTag())
            nounphrases.addAll(getNounPhrases(subparses[pi]));
    }//from w  ww .  j ava2 s.co  m

    return nounphrases;
}

From source file:opennlp.tools.apps.relevanceVocabs.PhraseProcessor.java

public ArrayList<String> getVerbPhrases(Parse p) {
    ArrayList<String> verbPhrases = new ArrayList<String>();

    Parse[] subparses = p.getChildren();
    for (int pi = 0; pi < subparses.length; pi++) {

        if (subparses[pi].getType().startsWith("VB") && allChildNodesArePOSTags(subparses[pi])) {
            Span _span = subparses[pi].getSpan();
            verbPhrases.add(p.getText().substring(_span.getStart(), _span.getEnd()));
        } else if (!((Parse) subparses[pi]).isPosTag())
            verbPhrases.addAll(getNounPhrases(subparses[pi]));
    }/*ww  w  .j ava 2s  .c  om*/

    return verbPhrases;
}

From source file:org.opentestsystem.airose.docquality.processors.PassiveSentencesQualityProcessor.java

private boolean checkPassive(AbstractDocument doc, Parse p) {

    Queue<Parse> queue = new LinkedList<Parse>();
    queue.add(p);/*w  ww  .j  av  a2  s .  co m*/

    while (queue.size() > 0) {
        p = queue.remove();
        String parseType = p.getType();
        if ((parseType.length() >= 2) && StringUtils.equalsIgnoreCase(parseType.substring(0, 2), "VB")) {

            String word = p.getText().substring(p.getSpan().getStart(),
                    p.getSpan().getStart() + p.getSpan().length());

            List<String> roots = wordnet.getBaseWords(word, EnumPOS.VERB);
            if ((roots.size() > 0) && (StringUtils.endsWithIgnoreCase(roots.get(0), "be"))) {
                return true;
            } else
                return false;

        } else {
            for (Parse child : p.getChildren())
                queue.add(child);
        }
    }
    return false;
}