You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by "krickert (via GitHub)" <gi...@apache.org> on 2026/09/07 05:19:31 UTC
[PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
krickert opened a new pull request, #1275:
URL: https://github.com/apache/opennlp/pull/1275
Replaces trivial regular-expression uses with explicit character scans, keeping the exact behavior of each replaced pattern, including the `String.split` edge cases for leading and trailing separators. Sixteen sites across the POS, lemmatizer, name finder, tokenizer, feature generator, CoNLL-U, AD, parser CLI, download, and emoji normalizer code; each replacement is covered by a test. The non-trivial AD metadata and SGML tag patterns stay for the next part. No new regex use and no JDK whitespace predicate is introduced.
| Site | Pattern removed |
|---|---|
| `DefaultPOSContextGenerator`, `DefaultLemmatizerContextGenerator` | `[A-Z]`, `[0-9]` capital and digit detection |
| `FeatureGeneratorUtil` | `^[A-ZÄÖÜ]\.$` capital-period check |
| `TokenPatternFeatureGenerator` | `[^a-zA-Z]` non-letter check |
| `BioCodec`, `NameFinderME` | `(.+)-\w+` typed-outcome split |
| `BrownCluster` | tab split |
| `TokenSampleStream` | `\s+` split and `[A-Za-z0-9]` check |
| `EmojiCharSequenceNormalizer` | surrogate-range emoji pattern |
| `ConlluStream` | token-id split on `-` and `text_([a-z]{2,3})` language comment |
| `ParserTool` | the two untokenized-bracket spacing patterns |
| `DownloadUtil` | checksum-line split and the `<a href>` link pattern |
| `ADNameSampleStream` | tag, whitespace, underscore, hyphen, and alphanumeric patterns |
| `ADPOSSampleStream`, `ADSentenceSampleStream`, `ADSentenceStream` | whitespace, metadata, and punctuation patterns |
Verification: opennlp-runtime 2,614, opennlp-formats 363, opennlp-cli 40, and opennlp-tools 421 tests with checkstyle, offline, `-Dopennlp.forkCount=1`.
[OPENNLP-1928](https://issues.apache.org/jira/browse/OPENNLP-1928)
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "krickert (via GitHub)" <gi...@apache.org>.
krickert commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5678777946
So some of the "corrections" are preserving regex, not doing the intent. They would create an intentional bug in the code.
The purpose of the ticket is to "de-regex" because regex overmatches and does unpredictable behavior / is slow (haha holding off on doing a regex rant here). If the regex is bugged, we're going to cover it in this ticket. We won't preserve bugs :)
I'm going to be methodical about this one, and I am in favor of writing a ton of unit tests to ensure the behavior of our code does what it is intended to do, but not to preserve the behavior if it's buggy. This is a great opportunity to harden edge cases that have gone unnoticed. I'm going to take advantage of that.
Please feel free to point out any edge cases I may want to try and they will be covered. I'm looking forward to this because we'll have deterministic behavior. I've even seen differences on regex matching between JDK versions. It hurts my eyes :)
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5685557443
Follow-up: the pre-existing issues found during review are now filed.
- [OPENNLP-1947](https://issues.apache.org/jira/browse/OPENNLP-1947): `TokenizerME` mutates the shared `WhitespaceTokenizer.INSTANCE`. That affects the new `INSTANCE` callers here (`TokenSampleStream`, AD readers).
- [OPENNLP-1952](https://issues.apache.org/jira/browse/OPENNLP-1952): `ConlluStream` NPE for a multiword range without its word lines (the corpora.xml "a damaged treebank is reported" point).
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Regex removal (1/8): Replace trivial patterns with character scans in StringUtil (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5728530066
Closed in favor of a split, as discussed in review. The commits are regrouped (authorship kept) into:
- #1311 OPENNLP-1928, part 1: rewrites with unchanged output and the StringUtil helpers
- #1312 OPENNLP-1973, prep: CompatibilityMode
- #1313 OPENNLP-1974, part 8: EmojiCharSequenceNormalizer fix, stacked on #1312
- #1314 OPENNLP-1975, part 9: output corrections (TokenSampleStream, ParserTool, ConlluStream, DownloadUtil, FeatureGeneratorUtil), stacked on #1311
- AD reader changes: #1276
The other parts (#1276–#1282) should be rebased onto #1311.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "krickert (via GitHub)" <gi...@apache.org>.
krickert commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5681823638
The emoji change touches default langdetect features. I'll trigger the eval build before we merge. Still working on it though - almost ready to merge.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5631310724
@krickert If you think this PR is ready for review, please put it out of draft. I'll review once ready. Think we can make some progress, as M6 vote seems to pass and will be processed soon, so we can add on top of that.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "krickert (via GitHub)" <gi...@apache.org>.
krickert commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5632734074
Yes, I do think they're ready for review. Thank you! Let me know about anything you'd like to see changed.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Regex removal (1/8): Replace trivial patterns with character scans in StringUtil (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 closed pull request #1275: OPENNLP-1928: Regex removal (1/8): Replace trivial patterns with character scans in StringUtil
URL: https://github.com/apache/opennlp/pull/1275
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5678811127
Go for adding tests .
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Stop EmojiCharSequenceNormalizer from blanking hyphens and BMP characters; reject malformed CoNLL-U multiword ids (opennlp)
Posted by "mawiesne (via GitHub)" <gi...@apache.org>.
mawiesne commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5712179697
@krickert and team:
Please rebase against main, update the title of this PR and the related description to cover only what is left now.
I am confused here.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "krickert (via GitHub)" <gi...@apache.org>.
krickert commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5679425299
This is soooo regex -
Tests are finding more bugs - that existed in both regex and our code. Fixing all of the regex domain ones and improving the test coverage.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5684834920
Here are some additional comments. Def. needs an eval build for the compat changes (langdetect via `EmojiCharSequenceNormalizer`, AD readers / `ArvoresDeitadasEval`, `TokenSampleStream`) before this can be merged.
## Blocking
1. **Scope.** This PR is not "trivial". It changes behavior in 7 components, and the AD part is rewritten again by #1276 (e.g. `ADSentenceSampleStream.parseTextAndParagraph`, added here, is moved to `ADMetadata` there). Move the AD changes into #1276 and give the emoji normalizer change its own JIRA. What stays here is the StringUtil helpers and the sites that behave exactly as before.
2. **EmojiCharSequenceNormalizer.java:55-70.** This changes the output of a class in the default langdetect chain. `LanguageDetectorFactory.java:43-44` says it "stays in this chain because existing models were trained with it". Hyphens (`well-known`), fullwidth/halfwidth forms, CJK compatibility ideographs, Arabic presentation forms, PUA and U+FE0F now go into the n-grams. Checked on every code point: output differs for U+002D, U+D83C-U+FFFF and U+10FC01-U+10FFFF. Either keep the old output bug-for-bug in this deprecated class, or keep the fix, run the langdetect eval build before merge, and update the factory Javadoc.
3. **EmojiCharSequenceNormalizer.java:38.** The implementation changed and the static `EMOJI_REGEX` field was removed, but `serialVersionUID` is unchanged. Recompute it. Also add `readResolve()` returning `INSTANCE`, as `ParagraphPreservingWhitespaceCharSequenceNormalizer` does.
4. **TokenSampleStream.java:57, :123.** This is not an equivalent rewrite, and the description doesn't mention it. It changes output in four ways:
- `split("\\s+")` (ASCII) became `WhitespaceTokenizer`, so the result now depends on `WhitespaceMode`.
- A leading space no longer yields an empty first token with `Span(0,0)`.
- An empty line now resets `evenq`.
- `[A-Za-z0-9]` became `Character.isLetterOrDigit`, so non-ASCII words no longer attach as punctuation.
Keep the old semantics, or document all four and add a test for the empty-line/`evenq` case.
5. **AD readers (ADPOSSampleStream.java:165, ADSentenceStream.java:231, ADNameSampleStream.java:248/517).** The training samples change: a leading `_` no longer yields an empty token, NBSP/U+0085/U+2028 now separate POS tags, contractions and NER tags, and a line of non-ASCII letters is no longer a punctuation leaf. The output also depends on the global `opennlp.whitespace.mode`; `"PR 3S"` is joined under UNICODE and not under LEGACY. Run the `ArvoresDeitadasEval` eval build, document the mode dependency, and add LEGACY-mode tests.
6. **Only part of the AD code is converted.**
- `ADSentenceStream.java:67-72`: NODE/LEAF/BIZARRE_LEAF patterns still use ASCII `\s`, so `corpora.xml:443` ("tabs and no-break spaces are handled like ordinary spaces") is false. `getElement` with an NBSP before `F S)` falls through to the bizarre-leaf branch.
- `ADNameSampleStream.java:559-565`: `getTextID` still compiles, per paragraph, the same `^(?:[a-zA-Z\-]*(\d+)).*?p=(\d+).*` regex this PR removes from `ADSentenceSampleStream`, and `:541-547` holds dead commented-out copies.
Either drop it or align all.
7. **StringUtil.java:252, :267.** This is new frozen public API in opennlp-api without a real need. `isLineTerminator` has no caller outside StringUtil and adds a second line-break definition next to `UnicodeWhitespace.lineBreakCodePointSet()`, which also includes VT and FF. `indexOfLineTerminator` has a single caller (BioCodec, `from = 0`, only needs a yes/no) and returns `text.length()` instead of `-1` when nothing is found, unlike every JDK `indexOf`. Make both private or move them to BioCodec. If they stay public, return `-1` and link the `java.util.regex.Pattern` line-terminator definition.
8. **ConlluStream.**
- `corpora.xml:403-406` and the PR description say malformed ids were skipped before. That is wrong: on main `3-` threw `ArrayIndexOutOfBoundsException`, `-4`/`3--4` threw `NumberFormatException`, and `4-3`/`1-2-3` were silently accepted. Fix both texts.
- `ConlluStream.java:145`: `postProcessContractions` now throws `InvalidFormatException`. Add Javadoc with `@throws`.
- `ConlluStream.java:179/187`: a range whose word line is missing (`1-2` with no line `2`) still NPEs when `index.get(id)` is unboxed. That was already the case on main, but the doc now claims a damaged treebank "is reported". Throw `InvalidFormatException`, or drop the claim.
9. **PR description.**
- It contains chat residue and truncated sentences ("whitespacision", "row in t bracket handling", "default `Langu the eval build", and the whole "One row of the table also needs a touch…" paragraph).
- The BioCodec bullet reads like a behavior change, but there is none. Old regex vs new scan on 50M inputs: 0 differences.
- DownloadUtil "treats a blank checksum file as missing" is wrong: it fails closed with "Expected: null", as it did before.
- Emoji "also blanked unpaired surrogates" is only true for U+D83C-U+DFFF.
Rewrite it, and list the eval builds (langdetect, AD) as done before merge, not "will run".
## Minor
**StringUtil / DownloadUtil**
- StringUtil.java:156-157, :178-179: Javadoc of a generic utility names its callers ("POS tagger and lemmatizer context generators … trained models expect it"), and :198, :210 add usage advice. State only the contract.
- StringUtil.java:169: `containsAsciiUpperCase` inlines `'A'..'Z'` while `containsAsciiDigit` calls `isAsciiDigit`. Add a private `isAsciiUpperCase` and use it.
- StringUtil.java:234, :271: the `from` range check is copied, and "must not be null" is repeated 6 times. Use a private helper and a constant.
- StringUtilTest.java:194: one test checks null for two methods. Split it or parameterize it.
- DownloadUtil.java:256-273: an ASCII hex checksum does not need the mode-dependent `StringUtil.isWhitespace`. Use `StringUtil.splitOnUnicodeWhitespace(content)` and return the first token or null; this also drops the double scan (`isBlank` + loop).
- DownloadUtil.java:264/281: blank checksum file. Throw an explicit `IOException("checksum file … is blank")` and add a test in `DownloadUtilCacheIntegrityTest` that a blank sidecar rejects the model.
- DownloadUtil.java:367-369: the `"\">"` literal and magic `+ 2`. Declare `ANCHOR_VALUE_END` next to `ANCHOR_START` and use `.length()`.
- DownloadUtil.java:376: when there is no `">`/`</a>` after an anchor, `from++` rescans, which is quadratic. `break` instead (40k unclosed anchors: about 3 s). Output matches the old `LINK_PATTERN` (2M fuzz inputs, 0 differences).
- DownloadUtil.java:389-403: the hand-written `indexOfIgnoreCase` with `continue outer`. Use `regionMatches(true, …)`.
**AD readers**
- ADNameSampleStream.java:429, :433, :441: the removed regexes are kept as comments. Remove them.
- ADNameSampleStream.java:271: `lexemes[lexemes.length - 1]` throws AIOOBE for `""` and `"_"` (old `"".split("[_]+")` gave `[""]`). Guard it; the manual now promises underscore-only lexemes produce no words.
- ADNameSampleStream.java:377: allocates a list and an array for every lexeme. Return early when there is no `_`.
- ADNameSampleStream.java:427, :499: `matchHyphenatedToken` and `tagContent` now accept line terminators that the old `.` refused (U+0085 is what byte 0x85 decodes to in ISO-8859-1 input). Reject them or pin that with tests.
- ADNameSampleStream.java:503: magic `5` and a `"NER:"` literal. Declare `NER_PREFIX` and use `1 + NER_PREFIX.length()`. Please also declare `"-"` (:345) as a constant.
- ADNameSampleStream.java:377/403/427/460/480/499, ADPOSSampleStream.java:160, ADSentenceSampleStream.java:172, ADSentenceStream.java:256: no need to be static. Make them private instance methods (package-private only where tests need it).
- ADNameSampleStream.java:480: `isAllLetters` is `lettersEnd(tok, 0) == len - 1`. Drop it.
- ADSentenceStream.java:208-229: `replacement` is always `'»' + punct` and the text is scanned twice. Drop the parameter, add a guillemet constant, and do one pass.
- ADSentenceStream.java:273-275, :323: the level is put into a `String[]` and read back with `Integer.parseInt`. Return the level as an int, or use a private record.
- corpora.xml:448: "the first run of digits" is wrong; the text id must follow the leading ASCII letters and hyphens directly (see your own reject tests). :443 should say "the toolkit whitespace mode", not "Unicode whitespace".
- ADNameSampleStreamTest.java:172-183: the `{null,null,null}` sentinel puts a reject case into the accept provider. Move `"é-a"` to the reject test.
- ADSentenceStreamTest.java:37: `testPunctuationLeaf` repeats cases from the provider at :69. :104: make `testFixPunctuation` a `@ParameterizedTest`. :120: the comment "ASCII whitespace" is outdated.
- ADSentenceSampleStreamTest.java:109/116: use `ObjectStreamUtils.createObjectStream(lines)`, and assert the message rather than a bare `RuntimeException`. Add stream-level tests for the dropped leading `_` token and for NBSP in a tag.
**ConlluStream / ParserTool**
- ConlluStream.java:253: no need to be static.
- ConlluStream.java:269: `"Multiword token id runs backwards: "` should be a constant like `INVALID_MULTIWORD_ID`.
- ConlluStream.java:157 vs :254: the hyphen appears as both `"-"` and `'-'`. Declare one `MULTIWORD_SEPARATOR` constant.
- ConlluStream.java:274-281: the Javadoc is hard to parse. Say "Returns the 2-3 lowercase ASCII letters after `text_`, or an empty string."
- ConlluStream.java:287-291: magic `2`/`3`. Name them. The scan matches the old `text_([a-z]{2,3})` (500k fuzz inputs, 0 differences).
- ConlluStream.java:239: the message still formats `lang`, which is always `""` here. Put `firstPart` in it.
- ConlluStreamTest.java:136: `"01-02, 1, 2"` pins leading zeros as valid, but the expansion then looks up `"1"`/`"2"`, so ids `01`/`02` NPE. Remove the case or reject leading zeros.
- ConlluStreamTest.java: no test covers empty-node ids (`8.1`). Add a `read()` test next to a multiword range.
- ConlluStreamTest.java:126-131: use `Set.of(...).contains(...)`. :152/166/182: extract the `ByteArrayInputStream` factory.
- ParserTool.java:87: a `StringBuilder` and copy are allocated per line even without brackets, while the old `replaceAll` returned the input unchanged. Scan for a bracket first. Also magic `+ 8` and a repeated `' '` literal.
- parser.xml:74-82: "any Unicode whitespace" only holds in the default `WhitespaceMode`. Reword it and add "Since 3.0.0". The bracket fix itself is justified: old `a))b` gave `a ) )b`.
**Runtime / featuregen / emoji**
- NameFinderME.java:326-328: now a one-line delegate. `NameFinderSequenceValidator:48-49` and `BilouNameFinderSequenceValidator:48-49` still go through it, while `BilouCodec` already calls `BioCodec.extractNameType`. Point them at BioCodec, drop the delegate and `NameFinderMETest:329-334`.
- BioCodec.java:49: the rewritten method has no Javadoc. Add `@param`/`@return` (null when there is no type), and drop the inline comment at :51.
- BioCodecTest.java:270: "whatever it holds" is wrong, since line terminators are rejected. Add rows with unpaired surrogates.
- TokenSampleStream.java:115: second blank line. :117-118: the Javadoc claim "attaches to the token before it" is wrong for `` ` ``, `--`, `$`, `(`, `&`, `#`. TokenSampleStreamTest.java:99: the "ASCII" comment contradicts the code.
- DefaultPOSContextGeneratorTest.java:105-120: not parameterized, and it duplicates the lemmatizer test. Use `@CsvSource(token, capital, digit)` and add boundary rows (`@`, `[`, `/`, `:`, `A`, `0`, U+1D400, unpaired surrogate). The features themselves are identical: all 1.1M code points, 0 differences, so no eval build is needed for POS or lemmatizer.
- TokenPatternFeatureGenerator.java:102-110: `containsNonLetter` re-implements `StringUtil.isAsciiLetter`, and the name is misleading. Use the helper and rename to `containsNonAsciiLetter`. TokenPatternFeatureGeneratorTest.java:76: parameterize it and add `café-bar` and `abc-123`.
- FeatureGeneratorUtil.java:117-119: the only divergence is a trailing line terminator (`A.\n`), which is only reachable in LEGACY mode with U+0085, so no eval build is needed. Add `cp` to the `tokenFeature` Javadoc list. FeatureGeneratorUtilTest.java:85-88: assert the exact class and drop the "tokens do not contain line breaks" comment.
- BrownCluster.java:98-104: thin Javadoc. BrownClusterTest.java:47-62: add a leading tab and an empty middle field. Output matches the old tab split (2M fuzz inputs, 0 differences).
- EmojiCharSequenceNormalizer.java:19-30: the 11-line class Javadoc says "Emoji live in that range", but BMP emoji (U+2600-27BF, U+2B50) pass through. Cut it to 2-3 lines. langdetect.xml:51-57: same problem. Condense to one sentence, mention that CJK Ext B+ is blanked, and note older models.
- EmojiCharSequenceNormalizer.java:55-60: allocates even when nothing is replaced, calls `codePointAt` twice, and line 60 is 105 chars.
- EmojiCharSequenceNormalizerTest.java:62: add `U+20BB7` (CJK Ext B) so the blanking of zh/ja name characters is pinned on purpose.
**Process**
- Rename the title to what users see, e.g. "OPENNLP-1928: Stop EmojiCharSequenceNormalizer from blanking hyphens and BMP characters; reject malformed CoNLL-U multiword ids".
- The branch is 8 commits behind main (3.0.0-M6, OPENNLP-1885). Rebase, and squash the 18 commits on merge.
- Verified: no new `java.util.regex` import, no `Character.isWhitespace`/`isSpaceChar`, no data files (no LICENSE/NOTICE impact).
## Sibling PRs (#1276–#1282, all draft)
- They all carry the #1275 commits. Only #1276, #1277 and #1279 use the new StringUtil helpers; #1278, #1280 and #1281 can be rebased straight onto main and made independent. #1282 is draft correctly.
- #1279's description refers to `StringUtil.splitOnAsciiWhitespace`, which doesn't exist; the diff uses `WhitespaceTokenizer`.
- Please apply these to all open PRs likewise:
- version-history Javadoc and docs: #1280 `BasicContextGenerator` and machine-learning.xml "In releases before 3.0.0…"
- inline ASCII ranges: #1277 `JsonScan` hex check
- arrays used as tuples: #1279 `MascIdentifiers.parseIds`/`splitColumns`, #1278 `splitClassPath`, #1276 `parseTextAndParagraph`
- eval builds: #1276 (AD) and #1281 (tokenizer)
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on code in PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#discussion_r4014149766
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/namefind/BioCodec.java:
##########
@@ -47,17 +45,37 @@ public class BioCodec implements SequenceCodec<String> {
public static final String CONTINUE = "cont";
public static final String OTHER = "other";
- private static final Pattern TYPED_OUTCOME_PATTERN = Pattern.compile("(.+)-\\w+");
-
static String extractNameType(String outcome) {
- Matcher matcher = TYPED_OUTCOME_PATTERN.matcher(outcome);
- if (matcher.matches()) {
- return matcher.group(1);
+ int separator = outcome.lastIndexOf('-');
+ if (separator > 0 && isWordChars(outcome, separator + 1)) {
Review Comment:
The previous regex rejected line terminators in the type prefix. `person\u2028-start` now produces a type instead of `null`. Please preserve that rejection.
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/featuregen/FeatureGeneratorUtil.java:
##########
@@ -110,4 +106,24 @@ else if (pattern.isInitialCapitalLetter()) {
return (feat);
}
+
+ /**
+ * Tests for a single capital followed by a period.
+ *
+ * @param token The token.
+ * @return {@code true} for exactly that shape.
+ */
+ private static boolean isCapPeriod(String token) {
+ return token.length() == 2 && isCapPeriodStart(token.charAt(0)) && token.charAt(1) == '.';
Review Comment:
`A.\n` previously produced `cp`; this now produces `ic`. The original `$` anchor accepts a final line terminator. Please preserve the feature behavior.
##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/util/normalizer/EmojiCharSequenceNormalizer.java:
##########
@@ -36,15 +34,44 @@ public static EmojiCharSequenceNormalizer getInstance() {
return INSTANCE;
}
- private static final Pattern EMOJI_REGEX =
- Pattern.compile("[\\uD83C-\\uDBFF\\uDC00-\\uDFFF]+");
+ /**
+ * The lowest code point that is replaced: the first high surrogate of the emoji planes.
+ * Lone surrogates and every BMP character from here up count as well.
+ */
+ private static final int LOWER_CODE_POINT = 0xD83C;
+
+ /** The highest code point that is replaced. */
+ private static final int UPPER_CODE_POINT = 0x10FC00;
- /** {@inheritDoc} */
+ /**
+ * {@inheritDoc}
+ * Every maximal run of code points in {@code [U+D83C, U+10FC00]} becomes one space.
+ */
@Override
public CharSequence normalize (CharSequence text) {
if (text == null) {
throw new IllegalArgumentException("The text must not be null.");
}
- return EMOJI_REGEX.matcher(text).replaceAll(" ");
+ StringBuilder normalized = new StringBuilder(text.length());
+ int i = 0;
+ while (i < text.length()) {
+ int cp = Character.codePointAt(text, i);
+ if (cp >= LOWER_CODE_POINT && cp <= UPPER_CODE_POINT) {
Review Comment:
The original regex also matches literal hyphens. `a-b` previously normalized to `a b`, but now remains `a-b`. Please preserve this behavior or explicitly document and test the compatibility change.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] OPENNLP-1928: Replace trivial regular expressions with explicit scans (opennlp)
Posted by "krickert (via GitHub)" <gi...@apache.org>.
krickert commented on PR #1275:
URL: https://github.com/apache/opennlp/pull/1275#issuecomment-5680030050
Poor sol - in one of the other branches your sol review suggested a regex fallback - I'm not going to do that. Fallbacks are weaksauce and by definition cause issues that go against the purpose of these tickets (and it's also a nasty habit most LLMs do to make their code pass where it should fail loudly). Instead I'll back up the decision with heavier testing. If regex is needed for that feature, we should be explicit and make it a separate feature and call out that it's a regex feature. I found one instance where we do accept patterns, I'll include a one-sentence brief as to how it is limited to the JDK char sets.
--
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: commits-unsubscribe@opennlp.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org