Package opennlp.tools.util.model
Class ModelUtil
java.lang.Object
opennlp.tools.util.model.ModelUtil
Utility class for handling of
models
.-
Method Summary
Modifier and TypeMethodDescriptionstatic void
addCutoffAndIterations
(Map<String, String> manifestInfoEntries, int cutoff, int iterations) Addscutoff
anditerations
tomanifestInfoEntries
.static TrainingParameters
Creates the defaultTrainingParameters
in case they are not provided.static byte[]
read
(InputStream in) Reads from the providedInputStream
into a byte array.static boolean
validateOutcomes
(MaxentModel model, String... expectedOutcomes) Checks if theexpectedOutcomes
are all contained as outcomes in the givenmodel
.static void
writeModel
(MaxentModel model, OutputStream out) Writes the givenMaxentModel
to the specifiedOutputStream
.
-
Method Details
-
writeModel
public static void writeModel(MaxentModel model, OutputStream out) throws IOException, IllegalArgumentException Writes the givenMaxentModel
to the specifiedOutputStream
.Note: The provided stream is not closed.
- Parameters:
model
- Themodel
to be written.out
- thestream
to be used for writing.- Throws:
IOException
- Thrown if IO errors occurred.IllegalArgumentException
- Thrown if one of the parameters isnull
.
-
validateOutcomes
Checks if theexpectedOutcomes
are all contained as outcomes in the givenmodel
.- Parameters:
model
- A validMaxentModel
instance.expectedOutcomes
- The outcomes to be checked for.- Returns:
true
if all expected outcomes are the only outcomes of the modelfalse
otherwise.
-
read
Reads from the providedInputStream
into a byte array.- Parameters:
in
- A valid, openInputStream
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) Addscutoff
anditerations
tomanifestInfoEntries
.- Parameters:
manifestInfoEntries
- AMap
representing amanifest.properties
config.cutoff
- The cut-off value to set. Must be greater than0
.iterations
- The number of iterations to set. Must be greater than0
.
-
createDefaultTrainingParameters
Creates the defaultTrainingParameters
in case they are not provided.Note: Do not use this method, internal use only!
- Returns:
- The
TrainingParameters
instance with default configuration.
-