DeleteNode.java :  » Natural-Language-Processing » Tregex-Tsurgeon » edu » stanford » nlp » trees » tregex » tsurgeon » Java Open Source

Java Open Source » Natural Language Processing » Tregex Tsurgeon 
Tregex Tsurgeon » edu » stanford » nlp » trees » tregex » tsurgeon » DeleteNode.java
package edu.stanford.nlp.trees.tregex.tsurgeon;

import java.util.List;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.Trees;
import edu.stanford.nlp.trees.tregex.TregexMatcher;

/**
 * @author Roger Levy (rog@stanford.edu)
 */
class DeleteNode extends TsurgeonPattern {

  public DeleteNode(TsurgeonPattern[] children) {
    super("delete", children);
  }

  public DeleteNode(List<TsurgeonPattern> children) {
    this(children.toArray(new TsurgeonPattern[children.size()]));
  }


  @Override
  public Tree evaluate(Tree t, TregexMatcher m) {
    Tree result = t;
    for (TsurgeonPattern child : children) {
      Tree nodeToDelete = child.evaluate(t, m);
      if (nodeToDelete == t) {
        result = null;
      }
      Tree parent = nodeToDelete.parent(t);
      parent.removeChild(Trees.objectEqualityIndexOf(parent,nodeToDelete));
    }
    return result;
  }

}
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.