krickert opened a new pull request, #1196:
URL: https://github.com/apache/opennlp/pull/1196
Completes the review of OPENNLP-1876 (#1151). These notes were raised in
that review and
addressed on 2026-07-16, but the commit was never pushed and #1151 merged
later the same
day without it, so the work is missing from `main`.
No behaviour changes. This is review follow-up work: 6 files, 68 insertions,
41 deletions.
### What this adds
**Undocumented exceptions on public spellcheck API.**
`SpellCheckingCharSequenceNormalizer.normalize` throws
`IllegalArgumentException` on a
null input and `IllegalStateException` when no `SpellChecker` is attached,
and two setters
reject out of range values. None of that was declared. The `@throws` tags
are added so the
contract is visible to callers, matching the rest of the normalizer family.
**Lost explanation on `SpellCorrectingTokenStream`.**
The class javadoc no longer explained that the stream is token count
preserving in
contrast to `SpellCorrectingObjectStream` in compound mode, which is the
property callers
rely on to keep tags and spans aligned with corrected tokens. That contrast
and the cross
reference are restored.
**Reference patterns recompiled on a hot path.**
The `Number`, `Shrink`, `SocialMedia` and `Url` characterization tests each
called
`Pattern.compile` inside the test body for the former regexes they
differentially test
against. Those are the randomized tests that run 5000 generated inputs per
case, so the
patterns were recompiled per invocation. They are hoisted into named `static
final`
constants (`FORMER_DIGIT_REGEX`, `FORMER_SPACE_REGEX`,
`FORMER_REPEATED_CHAR_REGEX`,
`FORMER_HASH_USER_REGEX`, `FORMER_RT_REGEX`, `FORMER_FACE_REGEX`,
`FORMER_URL_REGEX`,
`FORMER_MAIL_REGEX`), which also names what each pattern is instead of
leaving a bare
literal inside the assertion.
**The adversarial URL test hid which input failed.**
`weirdUrlsMatchTheFormerRegexExactly` drove a hard coded `String[]` of
adversarial URL
shapes (userinfo, ports, percent escapes, IPv6 brackets, backslashes, IDN
and punycode
hosts) through one `@Test`, so a regression reported only that the test
failed. It is now
a `@ParameterizedTest` with `@MethodSource`, so the failing shape is named
in the report.
### Verification
Branch is based on current `main` (`a8642301f`) and applies cleanly.
- `./mvnw -pl
opennlp-extensions/opennlp-spellcheck,opennlp-core/opennlp-runtime -am
test-compile` succeeds
- characterization suite: 55 tests, 0 failures, 0 errors, including
`SocialMediaCharSequenceNormalizerCharacterizationTest` (9) and
`UrlCharSequenceNormalizerCharacterizationTest` (32)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]