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

edu.stanford.nlp.trees.FilteringTreeReader 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;

import java.io.IOException;

import java.util.function.Predicate;

/**
 * A FilteringTreeReader filters the output of another TreeReader.
 * It applies a Filter<Tree> to each returned tree and only returns trees 
 * that are accepted by the Filter.  The Filter should accept trees that it 
 * wants returned.
 *
 * @author Christopher Manning
 * @version 2006/11
 */
public class FilteringTreeReader implements TreeReader {

  private TreeReader tr;
  private Predicate f;

  public FilteringTreeReader(TreeReader tr, Predicate f) {
    this.tr = tr;
    this.f = f;
  }

  /**
   * Reads a single tree.
   *
   * @return A single tree, or null at end of file.
   */
  public Tree readTree() throws IOException {
    Tree t;
    do {
      t = tr.readTree();
    } while (t != null && ! f.test(t));
    return t;
  }

  /**
   * Close the Reader behind this TreeReader.
   */
  public void close() throws IOException {
    tr.close();
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy