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 StringALGORITHM_PARAMstatic intCUTOFF_DEFAULT_VALUEstatic StringCUTOFF_PARAMstatic intITERATIONS_DEFAULT_VALUEstatic StringITERATIONS_PARAMstatic StringTHREADS_PARAMstatic StringTRAINER_TYPE_PARAM
-
Constructor Summary
Constructors Constructor Description TrainingParameters()No-arg constructor to create a defaultTrainingParametersinstance.TrainingParameters(InputStream in)InputStreambased constructor that reads inTrainingParameters.TrainingParameters(Map<String,Object> map)Key-value based constructor to apply aMapbased 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 Stringalgorithm()Stringalgorithm(String namespace)static TrainingParametersdefaultParams()booleangetBooleanParameter(String key, boolean defaultValue)Obtains a training parameter value.booleangetBooleanParameter(String namespace, String key, boolean defaultValue)Obtains a training parameter value in the specified namespace.doublegetDoubleParameter(String key, double defaultValue)Obtains a training parameter value.doublegetDoubleParameter(String namespace, String key, double defaultValue)Obtains a training parameter value in the specified namespace.intgetIntParameter(String key, int defaultValue)Obtains a training parameter value.intgetIntParameter(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)TrainingParametersgetParameters(String namespace)StringgetStringParameter(String key, String defaultValue)Obtains a training parameter value.StringgetStringParameter(String namespace, String key, String defaultValue)Obtains a training parameter value in the specified namespace.voidput(String key, boolean value)voidput(String key, double value)voidput(String key, int value)voidput(String key, String value)voidput(String namespace, String key, boolean value)voidput(String namespace, String key, double value)voidput(String namespace, String key, int value)voidput(String namespace, String key, String value)voidputIfAbsent(String key, boolean value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidputIfAbsent(String key, double value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidputIfAbsent(String key, int value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidputIfAbsent(String key, String value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidputIfAbsent(String namespace, String key, boolean value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidputIfAbsent(String namespace, String key, double value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidputIfAbsent(String namespace, String key, int value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidputIfAbsent(String namespace, String key, String value)Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.voidserialize(OutputStream out)Serializes aTrainingParametersinstance via a specifiedOutputStream.static TrainingParameterssetParams(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 defaultTrainingParametersinstance.
-
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 aMapbased configuration initialization.
-
TrainingParameters
public TrainingParameters(InputStream in) throws IOException
InputStreambased 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
nullif 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
Mapwhich can be passed to the train and validate methods.
-
getObjectSettings
public Map<String,Object> getObjectSettings()
- Returns:
- Retrieves a parameter
Mapof 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
TrainingParameterswhich can be passed to the train and validate methods.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, String value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheStringparameter to put into thisTrainingParametersinstance.
-
putIfAbsent
public void putIfAbsent(String key, String value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.- Parameters:
key- The identifying key to put or retrieve avaluewith.value- TheStringparameter to put into thisTrainingParametersinstance.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, int value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheIntegerparameter to put into thisTrainingParametersinstance.
-
putIfAbsent
public void putIfAbsent(String key, int value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.- Parameters:
key- The identifying key to put or retrieve avaluewith.value- TheIntegerparameter to put into thisTrainingParametersinstance.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, double value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheDoubleparameter to put into thisTrainingParametersinstance.
-
putIfAbsent
public void putIfAbsent(String key, double value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before. Thenamespacecan be used to prefix thekey.- Parameters:
key- The identifying key to put or retrieve avaluewith.value- TheDoubleparameter to put into thisTrainingParametersinstance.
-
putIfAbsent
public void putIfAbsent(String namespace, String key, boolean value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheBooleanparameter to put into thisTrainingParametersinstance.
-
putIfAbsent
public void putIfAbsent(String key, boolean value)
Puts avalueinto the currentTrainingParametersunder a certainkey, if the value was not present before.- Parameters:
key- The identifying key to put or retrieve avaluewith.value- TheBooleanparameter to put into thisTrainingParametersinstance.
-
put
public void put(String namespace, String key, String value)
Puts avalueinto the currentTrainingParametersunder a certainkey. If the value was present before, the previous value will be overwritten with the specified one. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheStringparameter to put into thisTrainingParametersinstance.
-
put
public void put(String key, String value)
Puts avalueinto the currentTrainingParametersunder 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 avaluewith.value- TheStringparameter to put into thisTrainingParametersinstance.
-
put
public void put(String namespace, String key, int value)
Puts avalueinto the currentTrainingParametersunder a certainkey. If the value was present before, the previous value will be overwritten with the specified one. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheIntegerparameter to put into thisTrainingParametersinstance.
-
put
public void put(String key, int value)
Puts avalueinto the currentTrainingParametersunder 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 avaluewith.value- TheIntegerparameter to put into thisTrainingParametersinstance.
-
put
public void put(String namespace, String key, double value)
Puts avalueinto the currentTrainingParametersunder a certainkey. If the value was present before, the previous value will be overwritten with the specified one. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheDoubleparameter to put into thisTrainingParametersinstance.
-
put
public void put(String key, double value)
Puts avalueinto the currentTrainingParametersunder 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 avaluewith.value- TheDoubleparameter to put into thisTrainingParametersinstance.
-
put
public void put(String namespace, String key, boolean value)
Puts avalueinto the currentTrainingParametersunder a certainkey. If the value was present before, the previous value will be overwritten with the specified one. Thenamespacecan be used to prefix thekey.- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be put. May benull.key- The identifying key to put or retrieve avaluewith.value- TheBooleanparameter to put into thisTrainingParametersinstance.
-
put
public void put(String key, boolean value)
Puts avalueinto the currentTrainingParametersunder 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 avaluewith.value- TheBooleanparameter to put into thisTrainingParametersinstance.
-
serialize
public void serialize(OutputStream out) throws IOException
Serializes aTrainingParametersinstance via a specifiedOutputStream.- Parameters:
out- A valid, openOutputStreamto write to.- Throws:
IOException- Thrown if errors occurred.
-
getStringParameter
public String getStringParameter(String key, String defaultValue)
Obtains a training parameter value.Note:
ClassCastExceptioncan be thrown if the value is notString- Parameters:
key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif not.
-
getStringParameter
public String getStringParameter(String namespace, String key, String defaultValue)
Obtains a training parameter value in the specified namespace.Note:
ClassCastExceptioncan be thrown if the value is notString- Parameters:
namespace- A prefix to declare or use a name space under whichkeyshall be searched. May benull.key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif not.
-
getIntParameter
public int getIntParameter(String key, int defaultValue)
Obtains a training parameter value.- Parameters:
key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif 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 whichkeyshall be searched. May benull.key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif not.
-
getDoubleParameter
public double getDoubleParameter(String key, double defaultValue)
Obtains a training parameter value.- Parameters:
key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif 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 whichkeyshall be searched. May benull.key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif not.
-
getBooleanParameter
public boolean getBooleanParameter(String key, boolean defaultValue)
Obtains a training parameter value.- Parameters:
key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif 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 whichkeyshall be searched. May benull.key- The identifying key to retrieve avaluewith.defaultValue- The alternative value to use, ifkeywas not present.- Returns:
- The
training valueassociated withkeyif present, or adefaultValueif not.
-
defaultParams
public static TrainingParameters defaultParams()
- Returns:
- Retrieves a new
instanceinitialized with default values.
-
setParams
public static TrainingParameters setParams(String[] params)
-
-