Package edu.stanford.nlp.trees

Source Code of edu.stanford.nlp.trees.TreeLeafLabelTransformer

package edu.stanford.nlp.trees;

import edu.stanford.nlp.ling.Label;
import java.util.function.Function;

/**
* Applies a Function to the labels in a tree. 
*
* @author John Bauer
*/
public class TreeLeafLabelTransformer implements TreeTransformer {
  Function<String, String> transform;

  public TreeLeafLabelTransformer(Function<String, String> transform) {
    this.transform = transform;
  }

  public Tree transformTree(Tree tree) {
    for (Tree leaf : tree.getLeaves()) {
      Label label = leaf.label();
      label.setValue(transform.apply(label.value()));
    }
    return tree;
  }
}
TOP

Related Classes of edu.stanford.nlp.trees.TreeLeafLabelTransformer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.