OPENNLP-1861: Offset/alignment layer — Alignment, AlignedText, buildAligned (1b/7)#1109
Conversation
9af6d92 to
9dc7d51
Compare
69f5136 to
20226fb
Compare
9dc7d51 to
b24c9ee
Compare
|
b24c9ee to
702acc5
Compare
|
@rzo1 Both fixed (current tip Dangling forward-link. The
|
702acc5 to
2bed555
Compare
|
@krickert Can you quickly rebase - we have changes in asf.yml in main now, missing on this branch. |
b2a17a1 to
e83e0ea
Compare
45ad38b to
c73ebeb
Compare
mawiesne
left a comment
There was a problem hiding this comment.
Thx @krickert and team. There some changes required with this PR. We need to change the signature of various public API methods to handle exceptional cases differently. Moreover, we need to be better in testing new classes. Please check my comments. If those are in, we can consider this PR for merging.
| * alignments compose with {@link #andThen(Alignment)}, which is what lets a multi-stage | ||
| * normalization pipeline still map a result all the way back to the original.</p> | ||
| * | ||
| * <p>Instances are immutable and thread-safe; build one with {@link Builder}.</p> |
There was a problem hiding this comment.
Please add the annotation @ThreadSafe to the class here.
| */ | ||
| public Builder equal(int charCount) { | ||
| if (charCount < 0) { | ||
| throw new IllegalArgumentException("charCount must not be negative: " + charCount); |
There was a problem hiding this comment.
Please add IllegalArgumentException to Javadoc here.
| */ | ||
| public Builder replace(int originalCount, int normalizedCount) { | ||
| if (originalCount < 0 || normalizedCount < 0) { | ||
| throw new IllegalArgumentException("counts must not be negative: " + originalCount |
There was a problem hiding this comment.
Please add IllegalArgumentException to Javadoc here.
| * @return The normalized text and its alignment. | ||
| */ | ||
| public AlignedText normalizeAligned(CharSequence text) { | ||
| Objects.requireNonNull(text, "text"); |
There was a problem hiding this comment.
Please IllegalArgumentException instead of requireNonNull's NullPointerException.
Add proper doc for IllegalArgumentException to Javadoc here.
| * @return The collapsed text and its alignment. | ||
| */ | ||
| public AlignedText collapseAligned(CharSequence text) { | ||
| Objects.requireNonNull(text, "text"); |
There was a problem hiding this comment.
Please IllegalArgumentException instead of requireNonNull's NullPointerException.
Add proper doc for IllegalArgumentException to Javadoc here.
| * @return The trimmed text and its alignment. | ||
| */ | ||
| public AlignedText trimAligned(CharSequence text) { | ||
| Objects.requireNonNull(text, "text"); |
There was a problem hiding this comment.
Please IllegalArgumentException instead of requireNonNull's NullPointerException.
Adjust doc for IllegalArgumentException to Javadoc here.
| * @return The filtered text and its alignment. | ||
| */ | ||
| public AlignedText removeAllAligned(CharSequence text) { | ||
| Objects.requireNonNull(text, "text"); |
There was a problem hiding this comment.
Please IllegalArgumentException instead of requireNonNull's NullPointerException.
Adjust doc for IllegalArgumentException to Javadoc here.
| * @return The transformed text and its alignment. | ||
| */ | ||
| public static AlignedText substituteAligned(CharSequence text, IntFunction<String> substitution) { | ||
| Objects.requireNonNull(text, "text"); |
There was a problem hiding this comment.
Please IllegalArgumentException instead of requireNonNull's NullPointerException.
Same for second parameter substitution.
Add doc for IllegalArgumentException to Javadoc here. It should be generic for any parameter violation.
| public class DashCharSequenceNormalizer implements CharSequenceNormalizer { | ||
| public class DashCharSequenceNormalizer implements OffsetAwareNormalizer { | ||
|
|
||
| private static final long serialVersionUID = 6620885194730155303L; |
There was a problem hiding this comment.
The serialVersionUID can't be correct as the class now implements a different interface (OffsetAwareNormalizer). Hence, it should be regenerated.
Note: All other, similar classes which now implement OffsetAwareNormalizer need this recomputation of the UID value. I won't leave a comment for every single occurrence. Please adjust accordingly on your own.
| * {@link Alignment#andThen(Alignment)} so a span found in the fully normalized text maps back to the | ||
| * original input, and a non-alignable rung is rejected loudly. | ||
| */ | ||
| public class AlignedNormalizerPipelineTest { |
There was a problem hiding this comment.
Please also add new test class which tests the LineBreakPreservingWhitespaceCharSequenceNormalizer class. This is currently untested in this PR!
Be hard and always provide tests for new classes.... !
c73ebeb to
ba7e0cd
Compare
|
All points addressed in ba7e0cd:
Stack cascade-rebased bottom-up (range-diff clean), full verify green. |
|
@krickert Can you rebase this branch: it has conflicts against main. |
…gned, *Aligned (1b) The conceptually hard half of the former foundation PR, split out on review request: the bidirectional Alignment edit-sequence and AlignedText, the OffsetAwareNormalizer capability interface, TextNormalizer.buildAligned(), the *Aligned CharClass variants and the offset-aware rungs, the line-break-preserving rung, and the dense span-mapping tests (binary-search span mapping, expansion/deletion edge cases, andThen composition including the insertion-in-expansion case). Builds on the engine in 1a.
…ving opener (alignment)
OffsetAwareNormalizer no longer {@link}s OffsetMappingNameFinder (introduced in the DL layer) so the
javadoc resolves when this PR is read on its own. LineBreakPreservingWhitespaceCharSequenceNormalizer's
opener now reads 'An OffsetAwareNormalizer' to match the interface it implements.
…normalizedString() Both sides of AlignedText are now CharSequence so the record is symmetric with the caller's original input. Callers that need the materialized normalized form use normalizedString(); engine paths still build via StringBuilder.toString(), so there is no extra allocation on the hot path when normalized is already a String. Add AlignedTextTest and adjust two runtime tests to use normalizedString() where a String is required.
ba7e0cd to
01a8360
Compare
…, line-break rung test Addresses the 1b review round: - CharClass reports IllegalArgumentException for null parameters across the whole class (not requireNonNull's NullPointerException), so an invalid parameter and an invalid code point surface through the same exception type; @throws documented on every affected method, and the sweep covers the non-aligned twins too so normalize and normalizeAligned share one contract. A null-contract test pins every entry point. - Alignment carries @threadsafe; Builder.equal/replace document their IllegalArgumentException for negative counts. - serialVersionUID regenerated via serialver for the ten classes that now implement OffsetAwareNormalizer. - New dedicated LineBreakPreservingWhitespaceCharSequenceNormalizerTest: horizontal collapse, break preservation incl. CRLF and U+2028/U+2029, edge trimming, whitespace-only input, aligned mapping through the collapse-then-trim composition, and null rejection.
01a8360 to
f089424
Compare
Part 1b of the OPENNLP-1850 stack: the offset/alignment layer, split out of the former foundation PR (#1103) on review request so the conceptually hard part gets a focused read on its own. Builds on the engine in #1108.
Adds:
Alignment(bidirectional edit-sequence,andThen-composable) andAlignedTextOffsetAwareNormalizercapability interface andTextNormalizer.buildAligned()*AlignedCharClassvariants, the offset-aware rungs, and the line-break-preserving rungandThencomposition including the insertion-inside-an-expansion caseBase:
OPENNLP-1850-1a-engine(#1108). Stack: 1a → 1b (this) → 2a → 2b → 2c → DL → docs.