Class DigitCharSequenceNormalizer

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

public class DigitCharSequenceNormalizer extends Object implements OffsetAwareNormalizer
A CharSequenceNormalizer that maps Unicode decimal digits to their ASCII equivalents, so for example Arabic-Indic, Devanagari, or fullwidth digits all become 0-9.

It maps a code point when Character.digit(int, int) reports a value of 0- 9 in radix ten, that is, when the code point is a Unicode decimal digit. Other numeric forms (Roman numerals, superscripts, circled numbers, fractions) are not decimal digits and are left unchanged.

See Also:
  • Field Details

  • Constructor Details

    • DigitCharSequenceNormalizer

      public DigitCharSequenceNormalizer()
  • Method Details

    • getInstance

      public static DigitCharSequenceNormalizer 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.
    • toAscii

      private static String toAscii(int codePoint)
      Maps a code point to its ASCII digit fold.
      Parameters:
      codePoint - The code point to fold.
      Returns:
      The ASCII digit string for a non-ASCII Unicode decimal digit, or null to copy the code point through (ASCII digits are already their own fold).
    • 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.
    • readResolve

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