Enum Class WhitespaceMode

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

public enum WhitespaceMode extends Enum<WhitespaceMode>
Selects the whitespace definition used by StringUtil.isWhitespace(char) and StringUtil.isWhitespace(int): the Unicode White_Space property, or OpenNLP's legacy definition from 1.x/2.x.

Resolved from the "opennlp.whitespace.mode" system property when this class is initialized and shared process-wide, so a model is trained and decoded under one definition. Tests and embedders may override the mode via setActive(WhitespaceMode) and reset().

Since:
3.0.0
  • Enum Constant Details

    • LEGACY

      public static final WhitespaceMode LEGACY
      OpenNLP 1.x/2.x whitespace: the union of Character.isWhitespace(int) and the Unicode Zs category. Restores byte-identical tokenization, corpus parsing, and feature generation for models trained under this definition.
    • UNICODE

      public static final WhitespaceMode UNICODE
      The Unicode White_Space property. The default from 3.0 onward.
  • Field Details

  • Method Details

    • values

      public static WhitespaceMode[] 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 WhitespaceMode 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 WhitespaceMode current()
      Returns the active WhitespaceMode: the value resolved from the "opennlp.whitespace.mode" system property when this class was initialized, or the value most recently passed to setActive(WhitespaceMode).
      Returns:
      The active WhitespaceMode.
    • setActive

      public static void setActive(WhitespaceMode mode)
      Overrides the active WhitespaceMode for the whole process, taking precedence over the "opennlp.whitespace.mode" system property. Intended for tests and embedders; callers pinning a mode temporarily should call reset() afterward.
      Parameters:
      mode - The WhitespaceMode to activate. Must not be null.
      Throws:
      IllegalArgumentException - If mode is null.
    • reset

      public static void reset()
      Discards any override set via setActive(WhitespaceMode) and re-resolves the active mode from the "opennlp.whitespace.mode" system property.
      Throws:
      IllegalArgumentException - If the property holds a value other than LEGACY or UNICODE (case-insensitive); the previous mode is retained.