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

opennlp.tools.doccat

## Class DocumentCategorizerEvaluator

- java.lang.Object
- - opennlp.tools.util.eval.Evaluator<DocumentSample>
  - - opennlp.tools.doccat.DocumentCategorizerEvaluator

-     public class DocumentCategorizerEvaluator
      extends Evaluator<DocumentSample>

  The `DocumentCategorizerEvaluator` measures the performance of the given `DocumentCategorizer` with the provided reference `DocumentSample`s.
  See Also:
    `DocumentCategorizer`, `DocumentSample`

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `DocumentCategorizerEvaluator(DocumentCategorizer categorizer, DoccatEvaluationMonitor... listeners)` Initializes the current instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `double` | `getAccuracy()` Retrieves the accuracy of provided `DocumentCategorizer`.
    `long` | `getDocumentCount()`
    `DocumentSample` | `processSample(DocumentSample sample)` Evaluates the given reference `DocumentSample` object.
    `String` | `toString()` Represents this objects as human readable `String`.

    - ### Methods inherited from class opennlp.tools.util.eval.Evaluator

      `evaluate, evaluateSample`

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

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

- - ### Constructor Detail

    - #### DocumentCategorizerEvaluator

          public DocumentCategorizerEvaluator(DocumentCategorizer categorizer,
                                              DoccatEvaluationMonitor... listeners)

      Initializes the current instance.
      Parameters:
        `categorizer` - the document categorizer instance

  - ### Method Detail

    - #### processSample

          public DocumentSample processSample(DocumentSample sample)

      Evaluates the given reference `DocumentSample` object. This is done by categorizing the document from the provided `DocumentSample`. The detected category is then used to calculate and update the score.
      Parameters:
        `sample` - the reference `TokenSample`.
      Returns:
        the predicted sample

    - #### getAccuracy

          public double getAccuracy()

      Retrieves the accuracy of provided `DocumentCategorizer`. accuracy = correctly categorized documents / total documents
      Returns:
        the accuracy

    - #### getDocumentCount

          public long getDocumentCount()

    - #### toString

          public String toString()

      Represents this objects as human readable `String`.
      Overrides:
        `toString` in class `Object`

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