All Downloads are FREE. Search and download functionalities are using the official Maven repository.

edu.stanford.nlp.trees.international.hebrew.HebrewTreeNormalizer Maven / Gradle / Ivy

Go to download

Stanford CoreNLP provides a set of natural language analysis tools which can take raw English language text input and give the base forms of words, their parts of speech, whether they are names of companies, people, etc., normalize dates, times, and numeric quantities, mark up the structure of sentences in terms of phrases and word dependencies, and indicate which noun phrases refer to the same entities. It provides the foundational building blocks for higher level text understanding applications.

There is a newer version: 4.5.7
Show newest version
package edu.stanford.nlp.trees.international.hebrew;

import java.io.Serializable;
import java.util.Collections;

import edu.stanford.nlp.trees.BobChrisTreeNormalizer;
import edu.stanford.nlp.trees.Tree;
import edu.stanford.nlp.trees.TreeFactory;
import java.util.function.Predicate;

/**
 * 
 * @author Spence Green
 *
 */
public class HebrewTreeNormalizer extends BobChrisTreeNormalizer {

  private static final long serialVersionUID = -3129547164200725933L;

  private final Predicate hebrewEmptyFilter;

  public HebrewTreeNormalizer() {
    super(new HebrewTreebankLanguagePack());
    hebrewEmptyFilter = new HebrewEmptyFilter();
  }

  /**
   * Remove traces and pronoun deletion markers.
   */
  public static class HebrewEmptyFilter implements Predicate, Serializable {

    private static final long serialVersionUID = -7256461296718287280L;

    public boolean test(Tree t) {
      return ! (t.isPreTerminal() && t.value().equals("-NONE-"));
    }
  }

  @Override
  public Tree normalizeWholeTree(Tree tree, TreeFactory tf) {
    tree = tree.prune(hebrewEmptyFilter, tf).spliceOut(aOverAFilter, tf);

    //Add start symbol so that the root has only one sub-state. Escape any enclosing brackets.
    //If the "tree" consists entirely of enclosing brackets e.g. ((())) then this method
    //will return null. In this case, readers e.g. PennTreeReader will try to read the next tree.
    while(tree != null && (tree.value() == null || tree.value().equals("")) && tree.numChildren() <= 1)
      tree = tree.firstChild();

    if(tree != null && !tree.value().equals(tlp.startSymbol()))
      tree = tf.newTreeNode(tlp.startSymbol(), Collections.singletonList(tree));

    return tree;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy