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 1 commit 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
Based on #1275 until that one merges; only the commits of this change: ai-pipestream/opennlp@OPENNLP-1928-regex-removal-trivial...OPENNLP-1929-context-generator-separator
BasicContextGenerator.getContextcalledString.split(separator), which compiled the separator as a regular expression on each call. The separator is documented as a character, so"|"split on each character,"."matched each character and"a.b".split(".")gave an empty array, and"+"or"("threwPatternSyntaxExceptionat prediction time.Changes
White_Spaceproperty (StringUtil.isUnicodeWhitespace), with a fixed definition that does not followopennlp.whitespace.modeand does not go through the sharedWhitespaceTokenizer.INSTANCE(see OPENNLP-1947). Before: one U+0020 per boundary, withString.splitsemantics."a b": before[a, , b], now[a, b]" a": before[, a], now[a]"": before[""], now[]"a\tb","a\nb","a\u00A0b","a\u0085b","a\u2028b": before one predicate, now[a, b]"a\u001Cb"and"a\u200Bb": one predicate in both versions (noWhite_Spaceproperty)BasicContextGenerator(String sep): the separator is taken as written."|"splits on the bar,"."on the period,"+"and"("no longer throw.IllegalArgumentExceptionat construction; a null input togetContextthrowsIllegalArgumentExceptioninstead ofNullPointerException.ContextGenerator.getContextdocuments its return value.BasicContextGeneratorparagraph inmachine-learning.xmlstates the rules above.Incompatible change for callers that passed a pattern
Escaping was the only way to split on a regex metacharacter, and those callers now get one predicate per line:
"\\|"ona|b: before[a, b], now[a|b]"\\."ona.b: before[a, b], now[a.b]"\\s+"ona b<TAB>c: before[a, b, c], now[a b<TAB>c]"[ \t]"and"[,;]": the same wayNo caller in the repository,
opennlp-eval-testsincluded, uses the separator constructor; the risk is third-party code. A deprecation path (keeping regex semantics behind@Deprecated(forRemoval = true)and adding a literal replacement) versus a documented break in the 3.0.0 migration notes is open for a decision on dev@; the tests pin the current, literal behavior so the break is visible.Tests
BasicContextGeneratorTest, 127 cases: literal separators including multi-character and supplementary-plane ones, patterns passed as separators, whitespace characters as separators, name=value predicates, the default split over the Unicode whitespace characters and the format characters that are not whitespace, the same rows underWhitespaceMode.LEGACY, the default split withWhitespaceTokenizer.INSTANCE.setKeepNewLines(true)switched on, and the rejections. The red commits fail on the previous code.Before merge
OPENNLP-1929