Class FullCaseFoldCharSequenceNormalizer

java.lang.Object
opennlp.tools.util.normalizer.FullCaseFoldCharSequenceNormalizer
All Implemented Interfaces:
Serializable, CharSequenceNormalizer, OffsetAwareNormalizer

public final class FullCaseFoldCharSequenceNormalizer extends Object implements OffsetAwareNormalizer
A CharSequenceNormalizer that applies Unicode full case folding for case-insensitive matching, as defined by the Default Case Algorithms in Section 3.13 of the Unicode Standard, using the bundled CaseFolding.txt data of the Unicode Character Database.

Unlike CaseFoldCharSequenceNormalizer, which lower cases with Locale.ROOT, this applies the full case foldings (the C common and F full status mappings), including the expanding folds that plain lower casing does not perform: the sharp s (U+00DF) to ss, the Latin ligatures (for example U+FB00 to ff), and the Greek and Armenian multi-character folds. It is therefore an expanding, offset-changing transform, so it is offset-aware: normalizeAligned(CharSequence) reports the Alignment from the folded text back to the input.

The S simple and T Turkic status mappings are excluded, so the Turkish and Azerbaijani dotless-i rule is not applied here. Input is expected in NFC: the fold matches precomposed code points, so decomposed sequences pass through unchanged.

The folding table is loaded on first use. If the bundled CaseFolding.txt is missing or cannot be read, every normalize call throws IllegalStateException or UncheckedIOException.

See Also:
  • Field Details

    • serialVersionUID

      private static final long serialVersionUID
      See Also:
    • RESOURCE

      private static final String RESOURCE
      See Also:
    • FIELD_SEPARATOR

      private static final char FIELD_SEPARATOR
      Field separator in CaseFolding.txt (<code>; <status>; <mapping>;).
      See Also:
    • MAPPING_CODE_POINT_SEPARATOR

      private static final char MAPPING_CODE_POINT_SEPARATOR
      Separates hex code points inside a multi-character mapping field. The Unicode CaseFolding.txt format uses ASCII space (U+0020), not a general whitespace class.
      See Also:
    • STATUS_COMMON

      private static final String STATUS_COMMON
      CaseFolding.txt status C: common mapping shared by simple and full folding.
      See Also:
    • STATUS_FULL

      private static final String STATUS_FULL
      CaseFolding.txt status F: full mapping that may expand string length.
      See Also:
    • STATUS_SIMPLE

      private static final String STATUS_SIMPLE
      CaseFolding.txt status S: simple mapping; skipped by this full fold.
      See Also:
    • STATUS_TURKIC

      private static final String STATUS_TURKIC
      CaseFolding.txt status T: Turkic mapping; skipped by this full fold.
      See Also:
    • FOLDINGS

      private static final BundledUnicodeData.Lazy<Map<Integer,String>> FOLDINGS
      Maps a source code point to its full case folding (one or more code points), for the C and F status rows of CaseFolding.txt. Loaded on first use.
    • INSTANCE

      private static final FullCaseFoldCharSequenceNormalizer INSTANCE
  • Constructor Details

    • FullCaseFoldCharSequenceNormalizer

      private FullCaseFoldCharSequenceNormalizer()
      Creates the singleton; use getInstance().
  • Method Details

    • getInstance

      public static FullCaseFoldCharSequenceNormalizer getInstance()
      Returns the shared, stateless instance.
      Returns:
      the shared, stateless instance
    • normalize

      public CharSequence normalize(CharSequence text)
      Normalizes a sequence of characters.
      Specified by:
      normalize in interface CharSequenceNormalizer
      Parameters:
      text - The CharSequence to normalize. Must not be null.
      Returns:
      The normalized CharSequence.
      Throws:
      IllegalArgumentException - Thrown if text is null.
      IllegalStateException - Thrown if the bundled CaseFolding.txt resource is missing.
      UncheckedIOException - Thrown if the bundled CaseFolding.txt resource cannot be read.
    • normalizeAligned

      public AlignedText normalizeAligned(CharSequence text)
      Normalizes text and returns the result together with the Alignment back to the input. The normalized text is identical to CharSequenceNormalizer.normalize(CharSequence): that is, normalizeAligned(text).normalized() equals normalize(text).toString().
      Specified by:
      normalizeAligned in interface OffsetAwareNormalizer
      Parameters:
      text - The CharSequence to normalize.
      Returns:
      The normalized text paired with its alignment to text.
      Throws:
      IllegalArgumentException - Thrown if text is null.
      IllegalStateException - Thrown if the bundled CaseFolding.txt resource is missing.
      UncheckedIOException - Thrown if the bundled CaseFolding.txt resource cannot be read.
    • initFoldings

      private static Map<Integer,String> initFoldings()
      Returns the folding table parsed from the bundled CaseFolding.txt resource.
      Returns:
      the folding table parsed from the bundled CaseFolding.txt resource
      Throws:
      IllegalStateException - Thrown if the resource is missing.
      UncheckedIOException - Thrown if the resource cannot be read.
    • parse

      static Map<Integer,String> parse(InputStream in) throws IOException
      Parses the full-folding mappings, the C (common) and F (full) status rows of CaseFolding.txt. The S (simple) and T (Turkic) status rows are deliberately skipped so the fold stays language-neutral and full rather than simple. Package-private so the malformed-data handling can be exercised without the bundled resource.
      Parameters:
      in - the stream to parse, in CaseFolding.txt format. Must not be null.
      Returns:
      the mapping from source code point to its full case folding.
      Throws:
      IOException - Thrown if the stream cannot be read.
      IllegalArgumentException - Thrown if the data is malformed.
    • readResolve

      private Object readResolve()
      Returns the shared instance, so deserialization keeps the singleton.
      Returns:
      the shared instance, so deserialization keeps the singleton