Enum Class CompatibilityMode
- All Implemented Interfaces:
Serializable, Comparable<CompatibilityMode>, Constable
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
-
Nested Class Summary
Nested classes/interfaces inherited from class Enum
Enum.EnumDesc<E> -
Enum Constant Summary
Enum Constants -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringSystem property that selects the activeCompatibilityModeat startup. -
Method Summary
Modifier and TypeMethodDescriptionstatic CompatibilityModecurrent()Returns the activeCompatibilityMode: the value resolved from the "opennlp.compat.mode" system property when this class was initialized, or the value most recently passed tosetActive(CompatibilityMode).static voidreset()Discards any override set viasetActive(CompatibilityMode)and re-resolves the active mode from the "opennlp.compat.mode" system property.static voidsetActive(CompatibilityMode mode) Overrides the activeCompatibilityModefor the whole process, taking precedence over the "opennlp.compat.mode" system property.static CompatibilityModeReturns the enum constant of this class with the specified name.static CompatibilityMode[]values()Returns an array containing the constants of this enum class, in the order they are declared.Methods inherited from class Enum
compareTo, describeConstable, equals, getDeclaringClass, hashCode, name, ordinal, toString, valueOf
-
Enum Constant Details
-
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
The corrected output. The default from 3.0 onward.
-
-
Field Details
-
MODE_PROPERTY
System property that selects the activeCompatibilityModeat startup. AcceptsLEGACYorCURRENT, case-insensitive; unset or blank resolves toCURRENT, any other value raises anIllegalArgumentExceptionwhen the mode is resolved. The property is first resolved during class initialization, so an invalid value at startup surfaces as anExceptionInInitializerErroron first use.- See Also:
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
current
Returns the activeCompatibilityMode: the value resolved from the "opennlp.compat.mode" system property when this class was initialized, or the value most recently passed tosetActive(CompatibilityMode).- Returns:
- The active
CompatibilityMode.
-
setActive
Overrides the activeCompatibilityModefor 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 callreset()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- TheCompatibilityModeto activate. Must not benull.- Throws:
IllegalArgumentException- Thrown ifmodeisnull.
-
reset
public static void reset()Discards any override set viasetActive(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 assetActive(CompatibilityMode).- Throws:
IllegalArgumentException- Thrown if the property holds a value other thanLEGACYorCURRENT(case-insensitive); the previous mode is retained.
-