Class BertNormalization

java.lang.Object
opennlp.tools.tokenize.BertNormalization

final class BertNormalization extends Object
Character classifications and text transforms of the reference BERT BasicTokenizer, shared by WordpieceEncoder and WordpieceTokenizer.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    (package private) static final String
    The wordpiece vocabulary convention: a piece with this prefix continues the current word, so it can only match after the word's first piece.
    (package private) static final int
    Default maximum word length used by BERT wordpiece tokenizers.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    (package private) static boolean
    isCjk(int codePoint)
    A CJK ideograph as defined by the reference BERT implementation: the CJK Unified Ideographs blocks and their extensions.
    (package private) static boolean
    isControl(int codePoint)
    A control character in the BERT sense: any C* category (control, format, surrogate, private use, unassigned), except the characters treated as whitespace by isWhitespace(int).
    (package private) static boolean
    Tests whether a code point is a Unicode line or paragraph separator.
    (package private) static String
    Surrounds every punctuation character with spaces, so each punctuation character becomes its own token.
    (package private) static MappedText
    Surrounds every punctuation character with spaces that map to an empty range at the character's start and end, so each punctuation character becomes its own token.
    (package private) static boolean
    isPunctuation(int codePoint)
    A punctuation character in the BERT sense: any non-alphanumeric ASCII character that is not whitespace, or any Unicode punctuation category.
    (package private) static boolean
    isWhitespace(int codePoint)
    A whitespace character in the BERT sense: space, tab, newline, carriage return, or Unicode space separators (Zs).

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • DEFAULT_MAX_WORD_CODE_POINTS

      static final int DEFAULT_MAX_WORD_CODE_POINTS
      Default maximum word length used by BERT wordpiece tokenizers.
      See Also:
    • CONTINUATION_PREFIX

      static final String CONTINUATION_PREFIX
      The wordpiece vocabulary convention: a piece with this prefix continues the current word, so it can only match after the word's first piece.
      See Also:
  • Constructor Details

    • BertNormalization

      private BertNormalization()
  • Method Details

    • isolatePunctuation

      static String isolatePunctuation(String text)
      Surrounds every punctuation character with spaces, so each punctuation character becomes its own token. Delegates to isolatePunctuation(MappedText) with an identity mapping.
      Parameters:
      text - The text to transform.
      Returns:
      The text with the isolation spaces inserted.
    • isolatePunctuation

      static MappedText isolatePunctuation(MappedText in)
      Surrounds every punctuation character with spaces that map to an empty range at the character's start and end, so each punctuation character becomes its own token.
      Parameters:
      in - The mapped text to transform.
      Returns:
      A new mapping with the isolation spaces inserted.
    • isControl

      static boolean isControl(int codePoint)
      A control character in the BERT sense: any C* category (control, format, surrogate, private use, unassigned), except the characters treated as whitespace by isWhitespace(int).
    • isWhitespace

      static boolean isWhitespace(int codePoint)
      A whitespace character in the BERT sense: space, tab, newline, carriage return, or Unicode space separators (Zs).
    • isLineOrParagraphSeparator

      static boolean isLineOrParagraphSeparator(int codePoint)
      Tests whether a code point is a Unicode line or paragraph separator.
    • isPunctuation

      static boolean isPunctuation(int codePoint)
      A punctuation character in the BERT sense: any non-alphanumeric ASCII character that is not whitespace, or any Unicode punctuation category.
    • isCjk

      static boolean isCjk(int codePoint)
      A CJK ideograph as defined by the reference BERT implementation: the CJK Unified Ideographs blocks and their extensions. This intentionally does not cover Japanese kana or Korean hangul, matching the reference.