Package opennlp.tools.util.normalizer
Class Alignment.Builder
java.lang.Object
opennlp.tools.util.normalizer.Alignment.Builder
- Enclosing class:
Alignment
Builds an
Alignment as the normalized text is produced, by recording each edit in order.
Call equal(int) for characters copied through unchanged and replace(int, int)
for a block that was rewritten (including deletions and insertions), then build(int).-
Constructor Summary
ConstructorsConstructorDescriptionBuilder()Creates a builder with a small default capacity ofDEFAULT_CAPACITYentries.Builder(int expectedLength) Creates a builder pre-sized for a normalized text of aboutexpectedLengthcharacters, so recording the edits of a typical pass (one entry per normalized character) does not regrow the backing arrays. -
Method Summary
Modifier and TypeMethodDescriptionbuild(int originalLength) Finalizes the alignment.equal(int charCount) RecordscharCountcharacters copied through unchanged (a one to one run).replace(int originalCount, int normalizedCount) Records a rewritten block:originalCountoriginal characters that producednormalizedCountnormalized characters.
-
Constructor Details
-
Builder
public Builder()Creates a builder with a small default capacity ofDEFAULT_CAPACITYentries. -
Builder
public Builder(int expectedLength) Creates a builder pre-sized for a normalized text of aboutexpectedLengthcharacters, so recording the edits of a typical pass (one entry per normalized character) does not regrow the backing arrays. The value is a sizing hint only; it does not limit how many edits can be recorded.- Parameters:
expectedLength- The expected normalized length, typically the length of the text being normalized; must not be negative.- Throws:
IllegalArgumentException- Thrown ifexpectedLengthis negative.
-
-
Method Details
-
equal
RecordscharCountcharacters copied through unchanged (a one to one run).- Parameters:
charCount- The number of UTF-16 characters; must not be negative.- Returns:
- This builder.
- Throws:
IllegalArgumentException- Thrown ifcharCountis negative.
-
replace
Records a rewritten block:originalCountoriginal characters that producednormalizedCountnormalized characters. Each produced character is attributed to the whole original block, since a collapse or expansion cannot be subdivided.0fornormalizedCountis a deletion;0fororiginalCountis an insertion.- Parameters:
originalCount- The number of original characters consumed; must not be negative.normalizedCount- The number of normalized characters produced; must not be negative.- Returns:
- This builder.
- Throws:
IllegalArgumentException- Thrown iforiginalCountornormalizedCountis negative.
-
build
Finalizes the alignment.- Parameters:
originalLength- The full length of the original text.- Returns:
- The immutable
Alignment. - Throws:
IllegalStateException- Thrown if the recorded edits do not consume exactlyoriginalLengthoriginal characters (a sign that some input was not accounted for).
-