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/10/03 17:16:21 UTC

[PR] (fix) Morpheme accepts a surface that does not match its span (opennlp)

krickert opened a new pull request, #1384:
URL: https://github.com/apache/opennlp/pull/1384

   Fixes #1379
   
   The `Morpheme` constructor now rejects a surface whose length does not match the span, and a `null` feature. Both throw `IllegalArgumentException`, like the other checks. A `null` surface and an empty surface now get separate messages.
   
   `LatticeTokenizer` already builds valid morphemes, so tokenizer output does not change. The existing contract test covers the new checks.
   
   ### For all changes:
   - [x] Is there a GitHub issue associated with this PR? Is it referenced in the PR description?
   - [x] Has your PR been rebased against the latest commit within the target branch (typically main)?
   - [x] Is your initial contribution a single, squashed commit?
   
   ### For code changes:
   - [ ] Have you ensured that the full suite of tests is executed via mvn clean install at the root opennlp folder?
   - [x] Have you written or updated unit tests to verify your changes?
   - n/a: new dependencies, LICENSE, NOTICE
   
   ### For documentation related changes:
   - n/a


-- 
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] (fix) GH-1379: Morpheme accepts a surface that does not match its span (opennlp)

Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 commented on code in PR #1384:
URL: https://github.com/apache/opennlp/pull/1384#discussion_r4174736487


##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/tokenize/lattice/Morpheme.java:
##########
@@ -46,19 +48,31 @@ public record Morpheme(Span span, String surface, List<String> features,
   /**
    * Validates the morpheme.
    *
-   * @throws IllegalArgumentException Thrown if {@code span}, {@code surface}, or
-   *         {@code features} is {@code null}, or {@code surface} is empty.
+   * @throws IllegalArgumentException Thrown if {@code span}, {@code surface},
+   *         {@code features}, or a feature is {@code null}; {@code surface} is empty;
+   *         or the surface and span lengths differ.
    */
   public Morpheme {
     if (span == null) {
       throw new IllegalArgumentException("span must not be null");
     }
-    if (surface == null || surface.isEmpty()) {
-      throw new IllegalArgumentException("surface must not be null or empty");
+    if (surface == null) {

Review Comment:
   Use ArgumentsChecker



-- 
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] (fix) GH-1379: Morpheme accepts a surface that does not match its span (opennlp)

Posted by "rzo1 (via GitHub)" <gi...@apache.org>.
rzo1 merged PR #1384:
URL: https://github.com/apache/opennlp/pull/1384


-- 
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] (fix) GH-1379: Morpheme accepts a surface that does not match its span (opennlp)

Posted by "krickert (via GitHub)" <gi...@apache.org>.
krickert commented on code in PR #1384:
URL: https://github.com/apache/opennlp/pull/1384#discussion_r4174752199


##########
opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/tokenize/lattice/Morpheme.java:
##########
@@ -46,19 +48,31 @@ public record Morpheme(Span span, String surface, List<String> features,
   /**
    * Validates the morpheme.
    *
-   * @throws IllegalArgumentException Thrown if {@code span}, {@code surface}, or
-   *         {@code features} is {@code null}, or {@code surface} is empty.
+   * @throws IllegalArgumentException Thrown if {@code span}, {@code surface},
+   *         {@code features}, or a feature is {@code null}; {@code surface} is empty;
+   *         or the surface and span lengths differ.
    */
   public Morpheme {
     if (span == null) {
       throw new IllegalArgumentException("span must not be null");
     }
-    if (surface == null || surface.isEmpty()) {
-      throw new IllegalArgumentException("surface must not be null or empty");
+    if (surface == null) {

Review Comment:
   DOne



-- 
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