Example usage for edu.stanford.nlp.semgraph SemanticGraph toString

List of usage examples for edu.stanford.nlp.semgraph SemanticGraph toString

Introduction

In this page you can find the example usage for edu.stanford.nlp.semgraph SemanticGraph toString.

Prototype

public String toString(OutputFormat format) 

Source Link

Document

Returns a String representation of the result of this set of typed dependencies in a user-specified format.

Usage

From source file:edu.csupomona.nlp.util.Sentence2Clause.java

public void process(String text) {
    // create an empty Annotation just with the given text
    Annotation document = new Annotation(text);

    // run all Annotators on this text
    pipeline.annotate(document);/*from w ww  . j  av a2  s.  c om*/

    List<CoreMap> sentences = document.get(SentencesAnnotation.class);

    for (CoreMap sentence : sentences) {
        // this is the Stanford dependency graph of the current sentence
        SemanticGraph dependencies = sentence.get(BasicDependenciesAnnotation.class);
        System.out.println(dependencies.toString("plain"));

        for (SemanticGraphEdge edge : dependencies.getEdgeSet()) {
            System.out.println(edge.getRelation().getShortName() + ": " + edge.getGovernor().value() + "("
                    + edge.getGovernor().index() + ") => " + edge.getDependent().value() + "("
                    + edge.getDependent().index() + ")");

        }

    }
}

From source file:edu.csupomona.nlp.util.StanfordTools.java

/**
 * Dependency parse tree /*w  ww . j  a  v  a2  s  .com*/
 * @param text      Input string text
 */
public void parser(String text) {
    Annotation document = new Annotation(text);
    pipeline.annotate(document);

    List<CoreMap> sentences = document.get(SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);

        System.out.println(dependencies.toString("plain"));
    }
}