Class AbstractModelReader

java.lang.Object
opennlp.tools.ml.model.AbstractModelReader
Direct Known Subclasses:
GenericModelReader, GISModelReader, NaiveBayesModelReader, PerceptronModelReader

public abstract class AbstractModelReader extends Object
An abstract, basic implementation of a model reader.
  • Field Details

    • NUM_PREDS

      protected int NUM_PREDS
      The number of predicates contained in a model.
    • dataReader

      protected DataReader dataReader
  • Constructor Details

  • Method Details

    • readInt

      public int readInt() throws IOException
      Implement as needed for the format the model is stored in.
      Returns:
      Reads in an int value from the underlying DataReader.
      Throws:
      IOException
    • readDouble

      public double readDouble() throws IOException
      Implement as needed for the format the model is stored in.
      Returns:
      Reads in a double value from the underlying DataReader.
      Throws:
      IOException
    • readUTF

      public String readUTF() throws IOException
      Implement as needed for the format the model is stored in.
      Returns:
      Reads in an UTF-encoded String value from the underlying DataReader.
      Throws:
      IOException
    • getModel

      public AbstractModel getModel() throws IOException
      Returns:
      Retrieves the read AbstractModel instance.
      Throws:
      IOException - Thrown if IO errors occurred constructing the model.
    • checkModelType

      public abstract void checkModelType() throws IOException
      Checks the model type via the the underlying DataReader.
      Throws:
      IOException - Thrown if IO errors occurred checking the model type.
    • constructModel

      public abstract AbstractModel constructModel() throws IOException
      Constructs a model.
      Returns:
      A AbstractModel reconstructed from a model's (read) attributes.
      Throws:
      IOException - Thrown if IO errors occurred during (re-)construction.
    • getOutcomes

      protected String[] getOutcomes() throws IOException
      Returns:
      Reads and retrieves the outcome labels from the model.
      Throws:
      IOException - Thrown if IO errors occurred.
      IllegalArgumentException - Thrown if the outcome count is negative or exceeds ResourceLimits.MAX_ENTRIES.
    • getOutcomePatterns

      protected int[][] getOutcomePatterns() throws IOException
      Returns:
      Reads and retrieves the outcome patterns from the model.
      Throws:
      IOException - Thrown if IO errors occurred.
      IllegalArgumentException - Thrown if the outcome pattern count is negative or exceeds ResourceLimits.MAX_ENTRIES.
    • getPredicates

      protected String[] getPredicates() throws IOException
      Returns:
      Reads and retrieves the predicates from the model.
      Throws:
      IOException - Thrown if IO errors occurred.
      IllegalArgumentException - Thrown if the predicate count is negative or exceeds ResourceLimits.MAX_ENTRIES.
    • getParameters

      protected Context[] getParameters(int[][] outcomePatterns) throws IOException
      Reads the parameters from a file and populates an array of Context objects.
      Parameters:
      outcomePatterns - The outcome patterns for the model. The first index refers to which outcome pattern (a set of outcomes that occurs with a context) is being specified. The second index specifies the number of contexts which use this pattern at index 0, and the index of each outcome which make up this pattern in indices 1-n.
      Returns:
      An array of Context objects.
      Throws:
      IOException - Thrown when the model file does not match the outcome patterns or can not be read.