Enum Class CompatibilityMode

java.lang.Object
java.lang.Enum<CompatibilityMode>
opennlp.tools.util.CompatibilityMode
All Implemented Interfaces:
Serializable, Comparable<CompatibilityMode>, Constable

public enum CompatibilityMode extends Enum<CompatibilityMode>
Selects, for the classes that corrected their output in 3.0.0, between the corrected output and the output of the 1.x/2.x releases. A model trained under the old output may depend on it until it is retrained. Each class that consults the mode documents what differs.

Resolved from the "opennlp.compat.mode" system property when this class is initialized and shared process-wide, so a model is trained and decoded under one mode. The mode is read on every call that consults it and is not recorded in a model, so it must be fixed before any component is used and must match the mode the loaded models were trained under. setActive(CompatibilityMode) and reset() are meant for tests and application startup only. The mode is independent of WhitespaceMode.

Since:
3.0.0
  • Enum Constant Details

    • LEGACY

      public static final CompatibilityMode LEGACY
      The output of OpenNLP 1.x/2.x. Restores byte-identical output for models trained with those releases in the classes that consult the mode.
    • CURRENT

      public static final CompatibilityMode CURRENT
      The corrected output. The default from 3.0 onward.
  • Field Details

  • Method Details

    • values

      public static CompatibilityMode[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static CompatibilityMode valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • current

      public static CompatibilityMode current()
      Returns the active CompatibilityMode: the value resolved from the "opennlp.compat.mode" system property when this class was initialized, or the value most recently passed to setActive(CompatibilityMode).
      Returns:
      The active CompatibilityMode.
    • setActive

      public static void setActive(CompatibilityMode mode)
      Overrides the active CompatibilityMode for the whole process, taking precedence over the "opennlp.compat.mode" system property. Intended for tests and application startup only; callers pinning a mode temporarily should call reset() afterward.

      The switch takes effect immediately for every thread, so a component processing text concurrently may apply the old mode to one part of that text and the new mode to the rest. Call this method before any component is created or used.

      Parameters:
      mode - The CompatibilityMode to activate. Must not be null.
      Throws:
      IllegalArgumentException - Thrown if mode is null.
    • reset

      public static void reset()
      Discards any override set via setActive(CompatibilityMode) and re-resolves the active mode from the "opennlp.compat.mode" system property. Intended for tests and application startup only, with the same process-wide effect as setActive(CompatibilityMode).
      Throws:
      IllegalArgumentException - Thrown if the property holds a value other than LEGACY or CURRENT (case-insensitive); the previous mode is retained.