Class StopwordFilterStream

java.lang.Object
opennlp.tools.util.FilterObjectStream<String[],String[]>
opennlp.tools.stopword.StopwordFilterStream
All Implemented Interfaces:
AutoCloseable, opennlp.tools.util.ObjectStream<String[]>

public final class StopwordFilterStream extends FilterObjectStream<String[],String[]>
A FilterObjectStream which removes stopwords from each String[] sample produced by an underlying ObjectStream<String[]>.

Stopword membership is decided by the supplied StopwordFilter; filtering is delegated to StopwordFilter.filter(String[]) so the relative order of surviving tokens within a sample is preserved.

FilterObjectStream.reset() and FilterObjectStream.close() are inherited from FilterObjectStream and simply forward to the wrapped stream.

  • Constructor Details

    • StopwordFilterStream

      public StopwordFilterStream(opennlp.tools.util.ObjectStream<String[]> samples, opennlp.tools.stopword.StopwordFilter filter)
      Initializes a StopwordFilterStream.
      Parameters:
      samples - The ObjectStream of token arrays to filter. Must not be null.
      filter - The StopwordFilter used to drop stopwords. Must not be null.
      Throws:
      IllegalArgumentException - if samples or filter is null.
  • Method Details

    • read

      public String[] read() throws IOException
      Reads the next sample from the wrapped stream and returns it with stopwords removed. Returns null once the underlying stream is exhausted.
      Returns:
      The filtered sample or null at the end of the stream.
      Throws:
      IOException - If the underlying stream throws an I/O error.