DocumentSampleStream (Apache OpenNLP Tools 1.9.5 API)
Date: 2026-06-18

opennlp.tools.doccat

## Class DocumentSampleStream

- java.lang.Object
- - opennlp.tools.util.FilterObjectStream<String,DocumentSample>
  - - opennlp.tools.doccat.DocumentSampleStream

- All Implemented Interfaces:
    AutoCloseable, ObjectStream<DocumentSample>

      public class DocumentSampleStream
      extends FilterObjectStream<String,DocumentSample>

  This class reads in string encoded training samples, parses them and outputs `DocumentSample` objects.

  Format:
  Each line contains one sample document.
  The category is the first string in the line followed by a tab and whitespace separated document tokens.
  Sample line: category-string tab-char whitespace-separated-tokens line-break-char(s)

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocumentSampleStream(ObjectStream<String> samples)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `DocumentSample` | `read()` Returns the next object.

    - ### Methods inherited from class opennlp.tools.util.FilterObjectStream

      `close, reset`

    - ### Methods inherited from class java.lang.Object

      `equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### DocumentSampleStream

          public DocumentSampleStream(ObjectStream<String> samples)

  - ### Method Detail

    - #### read

          public DocumentSample read()
                              throws IOException

      Description copied from interface: `ObjectStream`
      Returns the next object. Calling this method repeatedly until it returns null will return each object from the underlying source exactly once.
      Returns:
        the next object or null to signal that the stream is exhausted
      Throws:
        `IOException` - if there is an error during reading

Copyright © 2026 The Apache Software Foundation. All rights reserved.