OPENNLP-1929: Regex removal (7/10): Split BasicContextGenerator features on a literal separator - #1280
OPENNLP-1929: Regex removal (7/10): Split BasicContextGenerator features on a literal separator#1280krickert wants to merge 2 commits into
Conversation
2be805f to
021a3a2
Compare
021a3a2 to
2842f53
Compare
rzo1
left a comment
There was a problem hiding this comment.
Little time, so here is a GPT 5.6-sol review instead for now
Compatibility note. No additional splitting bug found; please document the intentional constructor behavior changes.
Validation across the combined stack: 1,856 targeted tests, zero failures, one skipped.
| * Must not be {@code null} or empty. | ||
| * @throws IllegalArgumentException If {@code sep} is {@code null} or empty. | ||
| */ | ||
| public BasicContextGenerator(String sep) { |
There was a problem hiding this comment.
This intentionally changes existing constructor behavior: regex separators such as \s+ become literal, and empty separators now throw. Please include these changes in the migration notes.
2842f53 to
112638e
Compare
|
Here are some additional comments. The literal-separator change breaks existing callers silently, so it needs a deprecation path or a documented maintainer decision. Blocking
Minor
Verified: the literal path is correct (1M fuzz inputs vs |
|
Follow-up: the shared |
0a397d2 to
3db4708
Compare
e4fc275 to
63248b9
Compare
Split the default context on Unicode whitespace independently of global whitespace settings and the shared tokenizer. Treat custom separators literally, discard empty predicates, and reject null inputs and invalid separators with IllegalArgumentException. Document the 3.0 migration. Preserved red evidence from the original commits: null input produced NullPointerException instead of IllegalArgumentException; 14 of 43 intended-split cases failed before the fix; later regressions exposed unpaired-surrogate separators and shared tokenizer/mode dependence. Validation: 127 BasicContextGenerator tests passed. The affected reactor tests passed with one skipped API test. The HTML manual build passed.
ab2b246 to
8f54db1
Compare
The separator is taken as written, so one escaped for the regex engine, such as "\\|" or "\\s+", matches no input and the line is returned as a single context. The constructor now throws IllegalArgumentException for a separator that contains a backslash. Other text, "[,;]" included, is still a plain separator. Red before the fix: testEscapedSeparatorIsRejected, 6 of 6 cases failed because no exception was thrown.
|
I did a break instead of a deprecated regex constructor. We shouldn't keep a I think it's cleaner to have a separator with a backslash to throw at construction, so old escapes fails loudly. |
BasicContextGenerator.getContextsplit onString.split(separator), so the separator was compiled as a regex on each call:"|"split on each character,"."returned an empty array, and"+"or"("failed withPatternSyntaxExceptionat prediction time.Changes:
StringUtil.isUnicodeWhitespace), independent ofopennlp.whitespace.mode."a b"now gives[a, b], not[a, , b].BasicContextGenerator(String sep)takes the separator as written.IllegalArgumentException.machine-learning.xmlstates these rules.Breaking for code that passed a regex: a separator containing a backslash, such as
"\\|"or"\\s+", now throwsIllegalArgumentExceptionat construction, so the old escapes fail at startup instead of matching no input."[,;]"is a plain separator. No code in the repository uses the separator constructor; the manual has the migration table.Tests:
BasicContextGeneratorTest, 129 cases, failing on the old code.OPENNLP-1929