Class ModelUtil

java.lang.Object
opennlp.tools.util.model.ModelUtil

public final class ModelUtil extends Object
Utility class for handling of models.
  • Method Details

    • writeModel

      public static void writeModel(MaxentModel model, OutputStream out) throws IOException, IllegalArgumentException
      Writes the given MaxentModel to the specified OutputStream.

      Note: The provided stream is not closed.

      Parameters:
      model - The model to be written.
      out - the stream to be used for writing.
      Throws:
      IOException - Thrown if IO errors occurred.
      IllegalArgumentException - Thrown if one of the parameters is null.
    • validateOutcomes

      public static boolean validateOutcomes(MaxentModel model, String... expectedOutcomes)
      Checks if the expectedOutcomes are all contained as outcomes in the given model.
      Parameters:
      model - A valid MaxentModel instance.
      expectedOutcomes - The outcomes to be checked for.
      Returns:
      true if all expected outcomes are the only outcomes of the model false otherwise.
    • read

      public static byte[] read(InputStream in) throws IOException
      Reads from the provided InputStream into a byte array.
      Parameters:
      in - A valid, open InputStream to read data from.
      Returns:
      A byte[] with the data read.
      Throws:
      IOException - Thrown if IO errors occurred.
    • addCutoffAndIterations

      public static void addCutoffAndIterations(Map<String,String> manifestInfoEntries, int cutoff, int iterations)
      Adds cutoff and iterations to manifestInfoEntries.
      Parameters:
      manifestInfoEntries - A Map representing a manifest.properties config.
      cutoff - The cut-off value to set. Must be greater than 0.
      iterations - The number of iterations to set. Must be greater than 0.
    • createDefaultTrainingParameters

      @Internal public static TrainingParameters createDefaultTrainingParameters()
      Creates the default TrainingParameters in case they are not provided.

      Note: Do not use this method, internal use only!

      Returns:
      The TrainingParameters instance with default configuration.