opennlp.tools.ml.naivebayes

## Class NaiveBayesModelReader

- java.lang.Object
- - opennlp.tools.ml.model.AbstractModelReader
  - - opennlp.tools.ml.naivebayes.NaiveBayesModelReader

- Direct Known Subclasses:
    BinaryNaiveBayesModelReader, PlainTextNaiveBayesModelReader

      public class NaiveBayesModelReader
      extends AbstractModelReader

  Abstract parent class for readers of NaiveBayes.

- - ### Field Summary

    - ### Fields inherited from class opennlp.tools.ml.model.AbstractModelReader

      `MAX_ENTRIES_PROPERTY`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `NaiveBayesModelReader(DataReader dataReader)`
    `NaiveBayesModelReader(File file)`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `void` | `checkModelType()`
    `AbstractModel` | `constructModel()` Retrieve a model from disk.

    - ### Methods inherited from class opennlp.tools.ml.model.AbstractModelReader

      `getModel, readDouble, readInt, readUTF`

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

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

- - ### Constructor Detail

    - #### NaiveBayesModelReader

          public NaiveBayesModelReader(File file)
                                throws IOException

      Throws:
        `IOException`

    - #### NaiveBayesModelReader

          public NaiveBayesModelReader(DataReader dataReader)

  - ### Method Detail

    - #### constructModel

          public AbstractModel constructModel()
                                       throws IOException

      Retrieve a model from disk. It assumes that models are saved in the following sequence:
      NaiveBayes (model type identifier)
      1. # of parameters (int)
      2. # of outcomes (int)
      * list of outcome names (String)
      3. # of different types of outcome patterns (int)
      * list of (int int[])
      [# of predicates for which outcome pattern is true] [outcome pattern]
      4. # of predicates (int)
      * list of predicate names (String)

      If you are creating a reader for a format which won't work with this (perhaps a database or xml file), override this method and ignore the other methods provided in this abstract class.

      Specified by:
        `constructModel` in class `AbstractModelReader`
      Returns:
        The NaiveBayesModel stored in the format and location specified to this NaiveBayesModelReader (usually via its the constructor).
      Throws:
        `IOException`

    - #### checkModelType

          public void checkModelType()
                              throws IOException

      Specified by:
        `checkModelType` in class `AbstractModelReader`
      Throws:
        `IOException`

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