Package opennlp.tools.tokenize.uax29
Class WordBreakProperty
java.lang.Object
opennlp.tools.tokenize.uax29.WordBreakProperty
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.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static final BundledUnicodeData.Lazy<WordBreakProperty.Data> private static final Stringprivate static final WordBreak[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static voidAssignsordinalto the code point range[start, end], filling the BMP portion directly and recording the rest as a supplementary range.private static WordBreakProperty.Databuild(InputStream in) Builds the lookup table fromWord_Breakdefinition lines.(package private) static WordBreakProperty.Datadata()Returns the resolved lookup table.private static WordBreakProperty.Dataload()Returns the lookup table built from the bundledWordBreakProperty.txtresource.static WordBreakof(int codePoint) Returns theWordBreakvalue of a code point.(package private) static WordBreakof(WordBreakProperty.Data resolved, int codePoint) Likeof(int)but against an already-resolved table, so it is not looked up again per code point.static intordinalOf(int codePoint) (package private) static intordinalOf(WordBreakProperty.Data resolved, int codePoint) LikeordinalOf(int)but against an already-resolved table, so a caller that looks up many code points in one pass (WordSegmenter) pays the volatile read behinddata()once for the whole pass rather than once per code point.private static intordinalOfSupplementary(WordBreakProperty.Data d, int codePoint) (package private) static voidparse(InputStream in, byte[] bmp, List<int[]> supplementary) ParsesWord_Breakdefinition lines into the BMP table and the supplementary range list.
-
Field Details
-
RESOURCE
- See Also:
-
VALUES
-
DATA
-
-
Constructor Details
-
WordBreakProperty
private WordBreakProperty()
-
-
Method Details
-
data
Returns the resolved lookup table. Package-visible so a per-pass caller can resolve the table once (see theordinalOf/ofoverloads that take a resolvedWordBreakProperty.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
Returns the lookup table built from the bundledWordBreakProperty.txtresource.- Returns:
- the lookup table built from the bundled
WordBreakProperty.txtresource - Throws:
IllegalStateException- Thrown if the resource is missing.UncheckedIOException- Thrown if the resource cannot be read.IllegalArgumentException- Thrown if the data is malformed.
-
build
Builds the lookup table fromWord_Breakdefinition lines.- Parameters:
in- The definition lines to read.- Returns:
- The lookup table.
- Throws:
IOException- Thrown if readinginfails.IllegalArgumentException- Thrown if a definition line is malformed.
-
parse
ParsesWord_Breakdefinition 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 readinginfails.IllegalArgumentException- Thrown if a definition line is malformed.
-
assign
Assignsordinalto 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 guarantees0 <= start <= end.end- The last code point of the range, at mostU+10FFFF; the portion aboveU+FFFFlands insupplementary.ordinal- TheWordBreakordinal to record.bmp- The per-code-point ordinal table for the BMP.supplementary- The receiving list of supplementary ranges.
-
of
Returns theWordBreakvalue of a code point.- Parameters:
codePoint- The code point. Values outside[0, U+10FFFF]returnWordBreak.OTHER.- Returns:
- the
WordBreakvalue of a code point
-
of
Likeof(int)but against an already-resolved table, so it is not looked up again per code point.- Parameters:
resolved- The resolved table fromdata().codePoint- The code point. Values outside[0, U+10FFFF]returnWordBreak.OTHER.- Returns:
- The
Word_Breakvalue.
-
ordinalOf
public static int ordinalOf(int codePoint) Returns theordinalof a code point'sWordBreakvalue. This is the allocation-free form ofof(int)for hot loops that work with ordinals.- Parameters:
codePoint- The code point. Values outside[0, U+10FFFF]return the ordinal ofWordBreak.OTHER.- Returns:
- the
ordinalof a code point'sWordBreakvalue
-
ordinalOf
LikeordinalOf(int)but against an already-resolved table, so a caller that looks up many code points in one pass (WordSegmenter) pays the volatile read behinddata()once for the whole pass rather than once per code point.- Parameters:
resolved- The resolved table fromdata().codePoint- The code point. Values outside[0, U+10FFFF]return the ordinal ofWordBreak.OTHER.- Returns:
- The ordinal of the
Word_Breakvalue.
-
ordinalOfSupplementary
-