Class WordBreakProperty

java.lang.Object
opennlp.tools.tokenize.uax29.WordBreakProperty

public final class WordBreakProperty extends Object
Looks up the Unicode Word_Break property of a code point.

The data is loaded on first use from the WordBreakProperty.txt resource of the Unicode Character Database. Lookup is O(1) for the Basic Multilingual Plane (a direct array index) and O(log n) for supplementary code points (a binary search over a small sorted range table), so it imposes no per-character allocation on the word boundary algorithm.

  • Field Details

  • Constructor Details

    • WordBreakProperty

      private WordBreakProperty()
  • Method Details

    • data

      static WordBreakProperty.Data data()
      Returns the resolved lookup table. Package-visible so a per-pass caller can resolve the table once (see the ordinalOf/of overloads that take a resolved WordBreakProperty.Data) rather than once per code point.
      Returns:
      the resolved lookup table
      Throws:
      IllegalStateException - Thrown if the bundled data resource is missing.
      UncheckedIOException - Thrown if the bundled data resource cannot be read.
      IllegalArgumentException - Thrown if the bundled data is malformed.
    • load

      private static WordBreakProperty.Data load()
      Returns the lookup table built from the bundled WordBreakProperty.txt resource.
      Returns:
      the lookup table built from the bundled WordBreakProperty.txt resource
      Throws:
      IllegalStateException - Thrown if the resource is missing.
      UncheckedIOException - Thrown if the resource cannot be read.
      IllegalArgumentException - Thrown if the data is malformed.
    • build

      private static WordBreakProperty.Data build(InputStream in) throws IOException
      Builds the lookup table from Word_Break definition lines.
      Parameters:
      in - The definition lines to read.
      Returns:
      The lookup table.
      Throws:
      IOException - Thrown if reading in fails.
      IllegalArgumentException - Thrown if a definition line is malformed.
    • parse

      static void parse(InputStream in, byte[] bmp, List<int[]> supplementary) throws IOException
      Parses Word_Break definition lines into the BMP table and the supplementary range list. Package-visible so the malformed-data handling can be exercised without the bundled resource.
      Parameters:
      in - The definition lines to read.
      bmp - The per-code-point ordinal table for the Basic Multilingual Plane.
      supplementary - The receiving list of {start, end, ordinal} supplementary ranges.
      Throws:
      IOException - Thrown if reading in fails.
      IllegalArgumentException - Thrown if a definition line is malformed.
    • assign

      private static void assign(int start, int end, byte ordinal, byte[] bmp, List<int[]> supplementary)
      Assigns ordinal to the code point range [start, end], filling the BMP portion directly and recording the rest as a supplementary range.
      Parameters:
      start - The first code point of the range; the parser guarantees 0 <= start <= end.
      end - The last code point of the range, at most U+10FFFF; the portion above U+FFFF lands in supplementary.
      ordinal - The WordBreak ordinal to record.
      bmp - The per-code-point ordinal table for the BMP.
      supplementary - The receiving list of supplementary ranges.
    • of

      public static WordBreak of(int codePoint)
      Returns the WordBreak value of a code point.
      Parameters:
      codePoint - The code point. Values outside [0, U+10FFFF] return WordBreak.OTHER.
      Returns:
      the WordBreak value of a code point
    • of

      static WordBreak of(WordBreakProperty.Data resolved, int codePoint)
      Like of(int) but against an already-resolved table, so it is not looked up again per code point.
      Parameters:
      resolved - The resolved table from data().
      codePoint - The code point. Values outside [0, U+10FFFF] return WordBreak.OTHER.
      Returns:
      The Word_Break value.
    • ordinalOf

      public static int ordinalOf(int codePoint)
      Returns the ordinal of a code point's WordBreak value. This is the allocation-free form of of(int) for hot loops that work with ordinals.
      Parameters:
      codePoint - The code point. Values outside [0, U+10FFFF] return the ordinal of WordBreak.OTHER.
      Returns:
      the ordinal of a code point's WordBreak value
    • ordinalOf

      static int ordinalOf(WordBreakProperty.Data resolved, int codePoint)
      Like ordinalOf(int) but against an already-resolved table, so a caller that looks up many code points in one pass (WordSegmenter) pays the volatile read behind data() once for the whole pass rather than once per code point.
      Parameters:
      resolved - The resolved table from data().
      codePoint - The code point. Values outside [0, U+10FFFF] return the ordinal of WordBreak.OTHER.
      Returns:
      The ordinal of the Word_Break value.
    • ordinalOfSupplementary

      private static int ordinalOfSupplementary(WordBreakProperty.Data d, int codePoint)