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

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

Introduction

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

Prototype

public List<IndexedWord> getChildList(IndexedWord vertex) 

Source Link

Usage

From source file:edu.nus.comp.nlp.stanford.UtilParser.java

License:Open Source License

public static DefaultMutableTreeNode toDMTree(IndexedWord root, SemanticGraph dependencies) {

    if (root == null) {
        root = dependencies.getFirstRoot();
    }/* w  w  w .j  ava 2  s  .c o  m*/

    DefaultMutableTreeNode node = new DefaultMutableTreeNode();

    String nodeContent = root.value();

    for (SemanticGraphEdge edge : dependencies.edgeIterable()) {
        if (edge.getDependent().equals(root)) {
            nodeContent = "<-" + edge.getRelation() + "- " + nodeContent;
            break;
        }
    }

    node.setUserObject(nodeContent);
    for (IndexedWord c : dependencies.getChildList(root)) {
        DefaultMutableTreeNode n = toDMTree(c, dependencies);
        node.add(n);
    }
    return node;
}