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

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

Introduction

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

Prototype

public String toList() 

Source Link

Document

Returns a String representation of this graph as a list of typed dependencies, as exemplified by the following:
 nsubj(died-6, Sam-3) tmod(died-6, today-9) 

Usage

From source file:nlp.pipeline.SentenceUtil.java

License:Open Source License

/** ***************************************************************
 * Print all the sentences in this document
 * CoreMap is essentially a Map that uses class objects as keys and 
 * has values with custom types/*from w w w  .j  a v a  2 s  .  com*/
 */
public static void printSentences(Annotation document) {

    List<CoreMap> sentences = document.get(SentencesAnnotation.class);
    for (CoreMap sentence : sentences) {
        // traversing the words in the current sentence
        // a CoreLabel is a CoreMap with additional token-specific methods
        int count = 1;
        for (CoreLabel token : sentence.get(TokensAnnotation.class)) {
            // this is the text of the token
            String word = token.get(TextAnnotation.class);
            // this is the POS tag of the token
            String pos = token.get(PartOfSpeechAnnotation.class);
            // this is the NER label of the token
            String ne = token.get(NamedEntityTagAnnotation.class);
            List<CoreMap> entity = token.get(MentionsAnnotation.class);
            System.out.println(word + "-" + count + "/" + pos + "/" + ne + "/" + entity);
            count++;
        }

        // this is the parse tree of the current sentence
        // Tree tree = sentence.get(TreeCoreAnnotations.TreeAnnotation.class);

        // this is the Stanford dependency graph of the current sentence
        SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
        System.out.println(dependencies.toList());
        //System.out.println(dependencies.toPOSList());
        //System.out.println(getFullNamedEntities(sentence));

        /*
        List<ScoredObject<Tree>> scoredTrees = sentence.get(KBestTreesAnnotation.class);
        System.out.println("\nTree Scores:");
        for (ScoredObject<Tree> scoredTree : scoredTrees) {
        //SemanticGraph graph = SemanticGraphFactory.generateUncollapsedDependencies(scoredTree.object());
        System.out.println(scoredTree.score());
        }
        */
    }
}

From source file:nlp.pipeline.SentenceUtil.java

License:Open Source License

/** ***************************************************************
 *//*ww  w. j av a2  s  .co  m*/
public static ArrayList<String> toDependenciesList(List<CoreMap> sentences) {

    ArrayList<String> results = Lists.newArrayList();
    for (CoreMap sentence : sentences) {
        //SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
        SemanticGraph dependencies = sentence.get(CollapsedCCProcessedDependenciesAnnotation.class);
        results = Lists.newArrayList(dependencies.toList().split("\n"));
    }
    ArrayList<String> deps = new ArrayList<String>();
    for (String dep : results)
        if (!dep.startsWith("punct(")) // TODO: handle punctuations instead of just removing - AP
            deps.add(dep);
    return deps;
}