Package opennlp.tools.tokenize
Class MappedText
java.lang.Object
opennlp.tools.tokenize.MappedText
The normalized text with the original-text range for each character. Characters inserted by
the pipeline (isolation spaces) use an empty range at the insertion point.
The buffers chars, starts and ends are exposed for fast,
allocation-free reads; only the first length entries of each are valid. They grow on
demand, so the capacity given to the constructor is a sizing hint, not a limit.
-
Field Summary
FieldsModifier and TypeFieldDescription(package private) char[](package private) int[](package private) intprivate static final intThe largest capacity the buffers grow to.private static final intThe smallest capacity the buffers grow to from empty.(package private) int[] -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription(package private) voidadd(char c, int originalStart, int originalEnd) Appends one UTF-16 code unit with its source range.(package private) voidAppends every UTF-16 code unit of a string, each with the same source range.(package private) voidaddCodePoint(int codePoint, int originalStart, int originalEnd) Appends one code point, as one or two UTF-16 code units that share the same source range.(package private) intcapacity()Returns the number of code units the buffers hold before they have to grow.(package private) intcodePointAt(int index) Returns the code point at an index of the mapped UTF-16 buffer.private voidgrow()Doubles the buffers, starting at 16 and capped atMAX_CAPACITY.(package private) Stringtext()Returns the mapped character content, the firstlengthcode units.
-
Field Details
-
MAX_CAPACITY
private static final int MAX_CAPACITYThe largest capacity the buffers grow to. Some JVMs reserve header words in arrays, so allocating close toInteger.MAX_VALUEelements can fail even with enough memory.- See Also:
-
MIN_GROWTH
private static final int MIN_GROWTHThe smallest capacity the buffers grow to from empty.- See Also:
-
chars
char[] chars -
starts
int[] starts -
ends
int[] ends -
length
int length
-
-
Constructor Details
-
MappedText
MappedText(int capacity) Creates an empty mapping.- Parameters:
capacity- The expected number of UTF-16 code units. Must not be negative. Zero is allowed and allocates nothing up front; the buffers grow on the firstadd. Since it is only a sizing hint, a value aboveMAX_CAPACITYis clamped to it.- Throws:
IllegalArgumentException- Thrown ifcapacityis negative.
-
-
Method Details
-
capacity
int capacity()Returns the number of code units the buffers hold before they have to grow.- Returns:
- the number of code units the buffers hold before they have to grow
-
add
void add(char c, int originalStart, int originalEnd) Appends one UTF-16 code unit with its source range. The range is not validated: the pipeline passes ranges of the original text, and an empty range (originalStart == originalEnd) marks an inserted character.- Parameters:
c- The code unit to append.originalStart- The start of the source range in the original text.originalEnd- The exclusive end of the source range in the original text.- Throws:
IllegalStateException- Thrown if the mapping already holds the maximum number of code units an array can hold.
-
add
Appends every UTF-16 code unit of a string, each with the same source range.- Parameters:
s- The string to append. Must not benull.originalStart- The start of the source range in the original text.originalEnd- The exclusive end of the source range in the original text.- See Also:
-
addCodePoint
void addCodePoint(int codePoint, int originalStart, int originalEnd) Appends one code point, as one or two UTF-16 code units that share the same source range.- Parameters:
codePoint- A valid Unicode code point.originalStart- The start of the source range in the original text.originalEnd- The exclusive end of the source range in the original text.- See Also:
-
codePointAt
int codePointAt(int index) Returns the code point at an index of the mapped UTF-16 buffer. A high surrogate followed by a low surrogate withinlengthforms one supplementary code point; an unpaired surrogate is returned as is.- Parameters:
index- The index of a code unit, in[0, length).- Returns:
- The code point that starts at
index. - Throws:
IndexOutOfBoundsException- Thrown ifindexis outside[0, length).
-
text
String text()Returns the mapped character content, the firstlengthcode units.- Returns:
- the mapped character content, the first
lengthcode units
-
grow
private void grow()Doubles the buffers, starting at 16 and capped atMAX_CAPACITY.- Throws:
IllegalStateException- Thrown if the buffers are already atMAX_CAPACITY.
-