Commit d5f99e3
committed
OPENNLP-1880: Address review: narrow the contract, validate at the boundary, pin WNDB rejections
- Narrow the LexicalKnowledgeBase javadoc so the interface stops prescribing what
only an implementation can promise: lemma matching semantics and thread safety
are now stated as implementation specific and documented where they hold, on
InMemoryWordNetLexicon, which already carries @threadsafe and describes the
folding it applies.
- Reword the contains() javadoc to say plainly that the default implementation
delegates to lookup(), instead of speculating about cheaper overrides.
- Move the null-element checks in MorphyLemmatizer up to the public lemmatize()
overloads, both the array form and the list form, so validation happens once at
the boundary the caller sees; the private lemmasOf() no longer repeats them and
now documents that its arguments are validated by the caller.
- Reject a null argument in LemmaFolding.splitOnSpaces() rather than letting it
fail later as a NullPointerException, and capitalize the fold() message so it
matches the wording the other validators use.
- Document the throws clauses that the explicit validation adds, on
LemmaKey.of() and on splitOnSpaces().
- Extract the repeated WN-LMF attribute names into ID_ATTRIBUTE,
PART_OF_SPEECH_ATTRIBUTE, REL_TYPE_ATTRIBUTE, and TARGET_ATTRIBUTE, and the
shared error opening into MALFORMED_PREFIX, so the element handlers stop
repeating string literals.
- Extract the WNDB offset failure detail into MALFORMED_OFFSET, shared by the
length check and the digit check.
- Fold the duplicated WNDB message construction into malformedMessage(), so the
tokenizer builds the text directly instead of constructing an
InvalidFormatException only to read getMessage() back off it.
- Drop the redundant fileName parameter from WndbReader.readAll(), which already
names the full path it failed to open.
- Reduce the visibility of the Parser helpers in WnLmfReader: malformed() and
line() are now private instance methods like every other helper in that class.
- Make MorphyLemmatizer.rulesFor() an instance method for the same reason, so the
lemmatizer's private helpers are consistent.
- Add the missing javadoc on the RELATION_NAMES and POINTER_SYMBOLS lookup tables
and on both RawSynset holders, the last undocumented members in the readers.
- Correct two stale comments: the build() comment now points at memberLemmas(),
where the synset and member part-of-speech agreement is really checked, and the
mutate() comment in the tests states the actual constraint, that an edit which
changes a line's length is only safe when the reader is expected to fail on
that line before it reads the ones after it.
- Add a parameterized WNDB test pinning eight field-level rejections that had no
coverage: the offset length and digit checks, the synset and index part of
speech mismatches, the base-16 word count field, the minimum word count, the
pointer pos, the gloss separator, and the syntactic marker.
- Add pinning tests for the newly explicit validation: splitOnSpaces() on null,
and the list lemmatize() overload with a null token and with a null tag.
- Share the fixtures instead of duplicating them: WndbReaderTest now exposes
DOG_ID, CANID_ID, and its fixtureDirectory(), WnLmfReaderTest exposes
fixture(), and LexiconConcurrencyTest and WordNetUsageExampleTest use those
instead of their own loader copies and hardcoded ids.
- Document the package-private test fixture helpers and switch
WordNetUsageExampleTest to static assertion imports, matching the other tests
in the module.1 parent 6c37523 commit d5f99e3
13 files changed
Lines changed: 163 additions & 82 deletions
File tree
- opennlp-api/src/main/java/opennlp/tools/wordnet
- opennlp-extensions/opennlp-wordnet/src
- main/java/opennlp/wordnet
- test/java/opennlp/wordnet
Lines changed: 6 additions & 10 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
24 | 24 | | |
25 | 25 | | |
26 | 26 | | |
27 | | - | |
28 | | - | |
29 | | - | |
30 | | - | |
31 | | - | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
32 | 30 | | |
33 | | - | |
34 | | - | |
| 31 | + | |
35 | 32 | | |
36 | 33 | | |
37 | 34 | | |
| |||
74 | 71 | | |
75 | 72 | | |
76 | 73 | | |
77 | | - | |
78 | | - | |
79 | | - | |
| 74 | + | |
| 75 | + | |
80 | 76 | | |
81 | 77 | | |
82 | 78 | | |
| |||
Lines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
148 | 148 | | |
149 | 149 | | |
150 | 150 | | |
| 151 | + | |
151 | 152 | | |
152 | 153 | | |
153 | 154 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
41 | 41 | | |
42 | 42 | | |
43 | 43 | | |
44 | | - | |
| 44 | + | |
45 | 45 | | |
46 | 46 | | |
47 | 47 | | |
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
54 | 55 | | |
55 | 56 | | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
56 | 60 | | |
57 | 61 | | |
58 | 62 | | |
| |||
Lines changed: 15 additions & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
112 | 112 | | |
113 | 113 | | |
114 | 114 | | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
115 | 121 | | |
116 | 122 | | |
117 | 123 | | |
| |||
138 | 144 | | |
139 | 145 | | |
140 | 146 | | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
141 | 153 | | |
142 | 154 | | |
143 | 155 | | |
| |||
147 | 159 | | |
148 | 160 | | |
149 | 161 | | |
150 | | - | |
151 | | - | |
| 162 | + | |
| 163 | + | |
152 | 164 | | |
153 | 165 | | |
154 | 166 | | |
155 | 167 | | |
156 | | - | |
157 | | - | |
158 | | - | |
159 | 168 | | |
160 | 169 | | |
161 | 170 | | |
| |||
188 | 197 | | |
189 | 198 | | |
190 | 199 | | |
191 | | - | |
| 200 | + | |
192 | 201 | | |
193 | 202 | | |
194 | 203 | | |
| |||
Lines changed: 32 additions & 14 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
66 | 66 | | |
67 | 67 | | |
68 | 68 | | |
| 69 | + | |
69 | 70 | | |
70 | 71 | | |
71 | 72 | | |
| |||
80 | 81 | | |
81 | 82 | | |
82 | 83 | | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
83 | 99 | | |
84 | 100 | | |
85 | 101 | | |
| |||
227 | 243 | | |
228 | 244 | | |
229 | 245 | | |
230 | | - | |
| 246 | + | |
231 | 247 | | |
232 | 248 | | |
233 | 249 | | |
| |||
240 | 256 | | |
241 | 257 | | |
242 | 258 | | |
243 | | - | |
| 259 | + | |
244 | 260 | | |
245 | 261 | | |
246 | 262 | | |
| |||
250 | 266 | | |
251 | 267 | | |
252 | 268 | | |
253 | | - | |
| 269 | + | |
254 | 270 | | |
255 | 271 | | |
256 | 272 | | |
| |||
269 | 285 | | |
270 | 286 | | |
271 | 287 | | |
272 | | - | |
273 | | - | |
| 288 | + | |
| 289 | + | |
274 | 290 | | |
275 | 291 | | |
276 | | - | |
277 | | - | |
| 292 | + | |
| 293 | + | |
278 | 294 | | |
279 | 295 | | |
280 | 296 | | |
| |||
291 | 307 | | |
292 | 308 | | |
293 | 309 | | |
294 | | - | |
295 | | - | |
| 310 | + | |
| 311 | + | |
296 | 312 | | |
297 | 313 | | |
298 | 314 | | |
| |||
335 | 351 | | |
336 | 352 | | |
337 | 353 | | |
338 | | - | |
| 354 | + | |
| 355 | + | |
339 | 356 | | |
340 | 357 | | |
341 | 358 | | |
| |||
507 | 524 | | |
508 | 525 | | |
509 | 526 | | |
510 | | - | |
| 527 | + | |
511 | 528 | | |
512 | | - | |
513 | | - | |
| 529 | + | |
| 530 | + | |
514 | 531 | | |
515 | 532 | | |
516 | 533 | | |
| |||
521 | 538 | | |
522 | 539 | | |
523 | 540 | | |
524 | | - | |
| 541 | + | |
525 | 542 | | |
526 | 543 | | |
527 | 544 | | |
528 | 545 | | |
| 546 | + | |
529 | 547 | | |
530 | 548 | | |
531 | 549 | | |
| |||
Lines changed: 26 additions & 11 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
57 | 57 | | |
58 | 58 | | |
59 | 59 | | |
| 60 | + | |
60 | 61 | | |
61 | 62 | | |
62 | 63 | | |
63 | 64 | | |
64 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
65 | 69 | | |
66 | 70 | | |
67 | 71 | | |
| |||
146 | 150 | | |
147 | 151 | | |
148 | 152 | | |
149 | | - | |
| 153 | + | |
150 | 154 | | |
151 | 155 | | |
152 | 156 | | |
| |||
281 | 285 | | |
282 | 286 | | |
283 | 287 | | |
284 | | - | |
| 288 | + | |
285 | 289 | | |
286 | 290 | | |
287 | 291 | | |
| |||
399 | 403 | | |
400 | 404 | | |
401 | 405 | | |
402 | | - | |
| 406 | + | |
403 | 407 | | |
404 | 408 | | |
405 | 409 | | |
406 | 410 | | |
407 | 411 | | |
408 | | - | |
| 412 | + | |
409 | 413 | | |
410 | 414 | | |
411 | 415 | | |
| |||
433 | 437 | | |
434 | 438 | | |
435 | 439 | | |
436 | | - | |
437 | | - | |
| 440 | + | |
438 | 441 | | |
439 | 442 | | |
440 | 443 | | |
441 | 444 | | |
442 | | - | |
| 445 | + | |
443 | 446 | | |
444 | 447 | | |
445 | 448 | | |
| |||
456 | 459 | | |
457 | 460 | | |
458 | 461 | | |
459 | | - | |
460 | | - | |
| 462 | + | |
| 463 | + | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
| 468 | + | |
| 469 | + | |
| 470 | + | |
| 471 | + | |
| 472 | + | |
| 473 | + | |
| 474 | + | |
461 | 475 | | |
462 | 476 | | |
463 | 477 | | |
| |||
515 | 529 | | |
516 | 530 | | |
517 | 531 | | |
518 | | - | |
519 | | - | |
| 532 | + | |
| 533 | + | |
520 | 534 | | |
521 | 535 | | |
522 | 536 | | |
| |||
557 | 571 | | |
558 | 572 | | |
559 | 573 | | |
| 574 | + | |
560 | 575 | | |
561 | 576 | | |
562 | 577 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
63 | 63 | | |
64 | 64 | | |
65 | 65 | | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
66 | 71 | | |
Lines changed: 3 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
| 74 | + | |
75 | 75 | | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
82 | 82 | | |
83 | 83 | | |
84 | 84 | | |
| |||
Lines changed: 5 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
35 | 35 | | |
36 | 36 | | |
37 | 37 | | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
38 | 43 | | |
39 | 44 | | |
40 | 45 | | |
| |||
0 commit comments