Package opennlp.tools.util
Class TrainingParameters
- java.lang.Object
-
- opennlp.tools.util.TrainingParameters
-
public class TrainingParameters extends Object
Declares and handles default parameters used for or during training models.
-
-
Field Summary
Fields Modifier and Type Field Description static String
ALGORITHM_PARAM
static int
CUTOFF_DEFAULT_VALUE
static String
CUTOFF_PARAM
static int
ITERATIONS_DEFAULT_VALUE
static String
ITERATIONS_PARAM
static String
THREADS_PARAM
static String
TRAINER_TYPE_PARAM
-
Constructor Summary
Constructors Constructor Description TrainingParameters()
No-arg constructor to create a defaultTrainingParameters
instance.TrainingParameters(InputStream in)
InputStream
based constructor that reads inTrainingParameters
.TrainingParameters(Map<String,Object> map)
Key-value based constructor to apply aMap
based configuration initialization.TrainingParameters(TrainingParameters trainingParameters)
Copy constructor to hand over the config of existingTrainingParameters
.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
algorithm()
String
algorithm(String namespace)
static TrainingParameters
defaultParams()
boolean
getBooleanParameter(String key, boolean defaultValue)
Obtains a training parameter value.boolean
getBooleanParameter(String namespace, String key, boolean defaultValue)
Obtains a training parameter value in the specified namespace.double
getDoubleParameter(String key, double defaultValue)
Obtains a training parameter value.double
getDoubleParameter(String namespace, String key, double defaultValue)
Obtains a training parameter value in the specified namespace.int
getIntParameter(String key, int defaultValue)
Obtains a training parameter value.int
getIntParameter(String namespace, String key, int defaultValue)
Obtains a training parameter value in the specified namespace.Map<String,Object>
getObjectSettings()
Map<String,Object>
getObjectSettings(String namespace)
TrainingParameters
getParameters(String namespace)
String
getStringParameter(String key, String defaultValue)
Obtains a training parameter value.String
getStringParameter(String namespace, String key, String defaultValue)
Obtains a training parameter value in the specified namespace.void
put(String key, boolean value)
void
put(String key, double value)
void
put(String key, int value)
void
put(String key, String value)
void
put(String namespace, String key, boolean value)
void
put(String namespace, String key, double value)
void
put(String namespace, String key, int value)
void
put(String namespace, String key, String value)
void
putIfAbsent(String key, boolean value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
putIfAbsent(String key, double value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
putIfAbsent(String key, int value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
putIfAbsent(String key, String value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
putIfAbsent(String namespace, String key, boolean value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
putIfAbsent(String namespace, String key, double value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
putIfAbsent(String namespace, String key, int value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
putIfAbsent(String namespace, String key, String value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.void
serialize(OutputStream out)
Serializes aTrainingParameters
instance via a specifiedOutputStream
.static TrainingParameters
setParams(String[] params)
-
-
-
Field Detail
-
ALGORITHM_PARAM
public static final String ALGORITHM_PARAM
- See Also:
- Constant Field Values
-
TRAINER_TYPE_PARAM
public static final String TRAINER_TYPE_PARAM
- See Also:
- Constant Field Values
-
ITERATIONS_PARAM
public static final String ITERATIONS_PARAM
- See Also:
- Constant Field Values
-
CUTOFF_PARAM
public static final String CUTOFF_PARAM
- See Also:
- Constant Field Values
-
THREADS_PARAM
public static final String THREADS_PARAM
- See Also:
- Constant Field Values
-
ITERATIONS_DEFAULT_VALUE
public static final int ITERATIONS_DEFAULT_VALUE
- See Also:
- Constant Field Values
-
CUTOFF_DEFAULT_VALUE
public static final int CUTOFF_DEFAULT_VALUE
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
TrainingParameters
public TrainingParameters()
No-arg constructor to create a defaultTrainingParameters
instance.
-
TrainingParameters
public TrainingParameters(TrainingParameters trainingParameters)
Copy constructor to hand over the config of existingTrainingParameters
.
-
TrainingParameters
public TrainingParameters(Map<String,Object> map)
Key-value based constructor to apply aMap
based configuration initialization.
-
TrainingParameters
public TrainingParameters(InputStream in) throws IOException
InputStream
based constructor that reads inTrainingParameters
.- Throws:
IOException
- Thrown if IO errors occurred.
-
-
Method Detail
-
algorithm
public String algorithm(String namespace)
- Returns:
- Retrieves the training algorithm name for a given name space, or
null
if unset.
-
algorithm
public String algorithm()
- Returns:
- Retrieves the training algorithm name. or @code null} if not set.
-
getObjectSettings
public Map<String,Object> getObjectSettings(String namespace)
- Parameters:
namespace
- The name space to filter or narrow the search space. May benull
.- Returns:
- Retrieves a parameter
Map
which can be passed to the train and validate methods.
-
getObjectSettings
public Map<String,Object> getObjectSettings()
- Returns:
- Retrieves a parameter
Map
of all parameters without narrowing.
-
getParameters
public TrainingParameters getParameters(String namespace)
- Parameters:
namespace
- The name space to filter or narrow the search space. May benull
.- Returns:
- Retrieves
TrainingParameters
which can be passed to the train and validate methods.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, String value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheString
parameter to put into thisTrainingParameters
instance.
-
putIfAbsent
public void putIfAbsent(String key, String value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheString
parameter to put into thisTrainingParameters
instance.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, int value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheInteger
parameter to put into thisTrainingParameters
instance.
-
putIfAbsent
public void putIfAbsent(String key, int value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheInteger
parameter to put into thisTrainingParameters
instance.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, double value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheDouble
parameter to put into thisTrainingParameters
instance.
-
putIfAbsent
public void putIfAbsent(String key, double value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before. Thenamespace
can be used to prefix thekey
.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheDouble
parameter to put into thisTrainingParameters
instance.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, boolean value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheBoolean
parameter to put into thisTrainingParameters
instance.
-
putIfAbsent
public void putIfAbsent(String key, boolean value)
Puts avalue
into the currentTrainingParameters
under a certainkey
, if the value was not present before.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheBoolean
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String namespace, String key, String value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheString
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String key, String value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheString
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String namespace, String key, int value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheInteger
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String key, int value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheInteger
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String namespace, String key, double value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheDouble
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String key, double value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheDouble
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String namespace, String key, boolean value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one. Thenamespace
can be used to prefix thekey
.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be put. May benull
.key
- The identifying key to put or retrieve avalue
with.value
- TheBoolean
parameter to put into thisTrainingParameters
instance.
-
put
public void put(String key, boolean value)
Puts avalue
into the currentTrainingParameters
under a certainkey
. If the value was present before, the previous value will be overwritten with the specified one.- Parameters:
key
- The identifying key to put or retrieve avalue
with.value
- TheBoolean
parameter to put into thisTrainingParameters
instance.
-
serialize
public void serialize(OutputStream out) throws IOException
Serializes aTrainingParameters
instance via a specifiedOutputStream
.- Parameters:
out
- A valid, openOutputStream
to write to.- Throws:
IOException
- Thrown if errors occurred.
-
getStringParameter
public String getStringParameter(String key, String defaultValue)
Obtains a training parameter value.Note:
ClassCastException
can be thrown if the value is notString
- Parameters:
key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
getStringParameter
public String getStringParameter(String namespace, String key, String defaultValue)
Obtains a training parameter value in the specified namespace.Note:
ClassCastException
can be thrown if the value is notString
- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be searched. May benull
.key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
getIntParameter
public int getIntParameter(String key, int defaultValue)
Obtains a training parameter value.- Parameters:
key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
getIntParameter
public int getIntParameter(String namespace, String key, int defaultValue)
Obtains a training parameter value in the specified namespace.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be searched. May benull
.key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
getDoubleParameter
public double getDoubleParameter(String key, double defaultValue)
Obtains a training parameter value.- Parameters:
key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
getDoubleParameter
public double getDoubleParameter(String namespace, String key, double defaultValue)
Obtains a training parameter value in the specified namespace.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be searched. May benull
.key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
getBooleanParameter
public boolean getBooleanParameter(String key, boolean defaultValue)
Obtains a training parameter value.- Parameters:
key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
getBooleanParameter
public boolean getBooleanParameter(String namespace, String key, boolean defaultValue)
Obtains a training parameter value in the specified namespace.- Parameters:
namespace
- A prefix to declare or use a name space under whichkey
shall be searched. May benull
.key
- The identifying key to retrieve avalue
with.defaultValue
- The alternative value to use, ifkey
was not present.- Returns:
- The
training value
associated withkey
if present, or adefaultValue
if not.
-
defaultParams
public static TrainingParameters defaultParams()
- Returns:
- Retrieves a new
instance
initialized with default values.
-
setParams
public static TrainingParameters setParams(String[] params)
-
-