Example usage for edu.stanford.nlp.trees TreeGraphNode addChild

List of usage examples for edu.stanford.nlp.trees TreeGraphNode addChild

Introduction

In this page you can find the example usage for edu.stanford.nlp.trees TreeGraphNode addChild.

Prototype

public void addChild(Tree t) 

Source Link

Document

Adds the tree t at the last index position among the daughters.

Usage

From source file:edu.jhu.agiga.StanfordAgigaSentence.java

License:Open Source License

public List<TreeGraphNode> getStanfordTreeGraphNodes(DependencyForm form) {
    if (this.nodes != null)
        return this.nodes;

    this.nodes = new ArrayList<TreeGraphNode>();
    // Add an explicit root node
    nodes.add(new TreeGraphNode(ROOT_LABEL));

    List<WordLemmaTag> labels = getStanfordWordLemmaTags();
    for (WordLemmaTag curToken : labels) {
        // Create the tree node
        TreeGraphNode treeNode = new TreeGraphNode(curToken);
        treeNode.label().setTag(curToken.tag());
        /**/*from   w ww.ja v  a2  s  .c  om*/
         * Caution, the order to call is to first setWord(), then setlemma()
         * From the Stanford source code:
         *   
        public void setWord(String word) {
        set(WordAnnotation.class, word);
        // pado feb 09: if you change the word, delete the lemma.
        remove(LemmaAnnotation.class);
        }
                
        public void setLemma(String lemma) {
        set(LemmaAnnotation.class, lemma);
        }
          */
        treeNode.label().setWord(curToken.word());
        treeNode.label().setLemma(curToken.lemma());
        nodes.add(treeNode);
    }

    List<AgigaTypedDependency> agigaDeps = getAgigaDeps(form);
    for (AgigaTypedDependency agigaDep : agigaDeps) {
        // Add one, since the tokens are zero-indexed but the TreeGraphNodes are one-indexed
        TreeGraphNode gov = nodes.get(agigaDep.getGovIdx() + 1);
        TreeGraphNode dep = nodes.get(agigaDep.getDepIdx() + 1);

        // Add gov/dep to TreeGraph
        gov.addChild(dep);
        dep.setParent(gov);
        require(dep.parent() == gov);
    }

    return nodes;
}