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

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

Introduction

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

Prototype

public void setParent(TreeGraphNode parent) 

Source Link

Document

Set the parent for the current node.

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 .j ava  2 s . co  m*/
         * 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;
}