Class TrainingParameters

java.lang.Object
opennlp.tools.util.TrainingParameters
All Implemented Interfaces:
Parameters

public class TrainingParameters extends Object implements Parameters
Declares and handles default parameters used for or during training models.
  • Field Details

  • Constructor Details

  • Method Details

    • algorithm

      public String algorithm(String namespace)
      Specified by:
      algorithm in interface Parameters
      Returns:
      Retrieves the (training) algorithm name for a given name space, or null if unset.
    • algorithm

      public String algorithm()
      Specified by:
      algorithm in interface Parameters
      Returns:
      Retrieves the (training) algorithm name. or @code null} if not set.
    • getObjectSettings

      public Map<String,Object> getObjectSettings(String namespace)
      Specified by:
      getObjectSettings in interface Parameters
      Parameters:
      namespace - The name space to filter or narrow the search space. May be null.
      Returns:
      Retrieves a parameter Map which can be passed to the train and validate methods.
    • getObjectSettings

      public Map<String,Object> getObjectSettings()
      Specified by:
      getObjectSettings in interface Parameters
      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 be null.
      Returns:
      Retrieves TrainingParameters which can be passed to the train and validate methods.
    • putIfAbsent

      public void putIfAbsent(String namespace, String key, String value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before. The namespace can be used to prefix the key.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The String parameter to put into this Parameters instance.
    • putIfAbsent

      public void putIfAbsent(String key, String value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The String parameter to put into this Parameters instance.
    • putIfAbsent

      public void putIfAbsent(String namespace, String key, int value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before. The namespace can be used to prefix the key.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The Integer parameter to put into this Parameters instance.
    • putIfAbsent

      public void putIfAbsent(String key, int value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The Integer parameter to put into this Parameters instance.
    • putIfAbsent

      public void putIfAbsent(String namespace, String key, double value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before. The namespace can be used to prefix the key.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The Double parameter to put into this Parameters instance.
    • putIfAbsent

      public void putIfAbsent(String key, double value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before. The namespace can be used to prefix the key.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The Double parameter to put into this Parameters instance.
    • putIfAbsent

      public void putIfAbsent(String namespace, String key, boolean value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before. The namespace can be used to prefix the key.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The Boolean parameter to put into this Parameters instance.
    • putIfAbsent

      public void putIfAbsent(String key, boolean value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key, if the value was not present before.
      Specified by:
      putIfAbsent in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The Boolean parameter to put into this Parameters instance.
    • put

      public void put(String namespace, String key, String value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one. The namespace can be used to prefix the key.
      Specified by:
      put in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The String parameter to put into this Parameters instance.
    • put

      public void put(String key, String value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one.
      Specified by:
      put in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The String parameter to put into this Parameters instance.
    • put

      public void put(String namespace, String key, int value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one. The namespace can be used to prefix the key.
      Specified by:
      put in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The Integer parameter to put into this Parameters instance.
    • put

      public void put(String key, int value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one.
      Specified by:
      put in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The Integer parameter to put into this Parameters instance.
    • put

      public void put(String namespace, String key, double value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one. The namespace can be used to prefix the key.
      Specified by:
      put in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The Double parameter to put into this Parameters instance.
    • put

      public void put(String key, double value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one.
      Specified by:
      put in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The Double parameter to put into this Parameters instance.
    • put

      public void put(String namespace, String key, boolean value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one. The namespace can be used to prefix the key.
      Specified by:
      put in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be put. May be null.
      key - The identifying key to put or retrieve a value with.
      value - The Boolean parameter to put into this Parameters instance.
    • put

      public void put(String key, boolean value)
      Description copied from interface: Parameters
      Puts a value into the current Parameters under a certain key. If the value was present before, the previous value will be overwritten with the specified one.
      Specified by:
      put in interface Parameters
      Parameters:
      key - The identifying key to put or retrieve a value with.
      value - The Boolean parameter to put into this Parameters instance.
    • serialize

      public void serialize(OutputStream out) throws IOException
      Description copied from interface: Parameters
      Serializes a Parameters instance via a specified OutputStream.
      Specified by:
      serialize in interface Parameters
      Parameters:
      out - A valid, open OutputStream to write to.
      Throws:
      IOException - Thrown if errors occurred.
    • getStringParameter

      public String getStringParameter(String key, String defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value.
      Specified by:
      getStringParameter in interface Parameters
      Parameters:
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • getStringParameter

      public String getStringParameter(String namespace, String key, String defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value in the specified namespace.
      Specified by:
      getStringParameter in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be searched. May be null.
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • getIntParameter

      public int getIntParameter(String key, int defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value.

      Specified by:
      getIntParameter in interface Parameters
      Parameters:
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • getIntParameter

      public int getIntParameter(String namespace, String key, int defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value in the specified namespace.

      Specified by:
      getIntParameter in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be searched. May be null.
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • getDoubleParameter

      public double getDoubleParameter(String key, double defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value.

      Specified by:
      getDoubleParameter in interface Parameters
      Parameters:
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • getDoubleParameter

      public double getDoubleParameter(String namespace, String key, double defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value in the specified namespace.

      Specified by:
      getDoubleParameter in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be searched. May be null.
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • getBooleanParameter

      public boolean getBooleanParameter(String key, boolean defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value.

      Specified by:
      getBooleanParameter in interface Parameters
      Parameters:
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • getBooleanParameter

      public boolean getBooleanParameter(String namespace, String key, boolean defaultValue)
      Description copied from interface: Parameters
      Obtains a training parameter value in the specified namespace.

      Specified by:
      getBooleanParameter in interface Parameters
      Parameters:
      namespace - A prefix to declare or use a name space under which key shall be searched. May be null.
      key - The identifying key to retrieve a value with.
      defaultValue - The alternative value to use, if key was not present.
      Returns:
      The training value associated with key if present, or a defaultValue if not.
    • defaultParams

      public static TrainingParameters defaultParams()
      Returns:
      Retrieves a new instance initialized with default values.
    • setParams

      public static TrainingParameters setParams(String[] params)
      Parameters:
      params - The parameters to additionally apply into the new instance.
      Returns:
      Retrieves a new instance initialized with given parameter values.
    • getIntParameter

      private static Integer getIntParameter(String param, String[] args)
      Retrieves the specified parameter from the specified arguments.
      Parameters:
      param - parameter name
      args - arguments
      Returns:
      parameter value
    • getParameter

      private static String getParameter(String param, String[] args)
      Retrieves the specified parameter from the given arguments.
      Parameters:
      param - parameter name
      args - arguments
      Returns:
      parameter value
    • getParameterIndex

      private static int getParameterIndex(String param, String[] args)
      Returns the index of the parameter in the arguments, or -1 if the parameter is not found.
      Parameters:
      param - parameter name
      args - arguments
      Returns:
      the index of the parameter in the arguments, or -1 if the parameter is not found