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/16 02:28:29 UTC

[PR] OPENNLP-1949: End ADSentenceStream at end of file inside an open sentence (opennlp)

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

   `ADSentenceStream.read()` reads lines until a sentence closes. When the input ends after an opening `<s>` tag with no line after it, the end-of-file branch neither returned nor left the loop, so `read()` called the line stream at end of file without end. A truncated or damaged Arvores Deitadas file therefore hung training instead of ending it.
   
   ## Change
   
   - At the end of the input with an open sentence and no content, `read()` returns `null`. Before: an endless loop.
   - A sentence cut off before its closing tag is still returned with the lines read so far, as before.
   - The Javadoc of `read()` states both rules.
   
   The ticket's example, an empty input, does not show the problem: an empty line opens no sentence, so `read()` returned `null` before this change as well. The hang needs an opening tag as the last line, for example the single line `<s>`.
   
   ## Tests
   
   New `ADSentenceStreamTest`, run with a separate-thread timeout so a regression fails instead of hanging: inputs without a sentence (empty, a blank line, paragraph and extract tags only), an opening tag at the end of the input in four shapes, an opening tag after a complete sentence, a sentence cut off before its closing tag, and a normal two-sentence input. Before the fix the five open-tag cases time out; after it all 11 cases pass. Formats module: 368 tests, checkstyle clean.
   
   Manual: the Arvores Deitadas section of `corpora.xml` gained a short section on the end-of-file rule.
   
   [OPENNLP-1949](https://issues.apache.org/jira/browse/OPENNLP-1949)
   


-- 
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-1949: End ADSentenceStream at end of file inside an open sentence (opennlp)

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


-- 
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-1949: End ADSentenceStream at end of file inside an open sentence (opennlp)

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


##########
opennlp-core/opennlp-formats/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java:
##########
@@ -518,14 +526,10 @@ public Sentence read() throws IOException {
         }
 
       } else {
-        // handle end of file
-        if (sentenceStarted) {
-          if (sentence.length() > 0) {
-            return parser.parse(sentence.toString(), paraID, isTitle, isBox);
-          }
-        } else {
-          return null;
+        if (sentenceStarted && sentence.length() > 0) {

Review Comment:
   Besides a more compact form of the touched code, I don't see any actual change here. 
   So what's the point here?
   
   The tests make sense, no question.



-- 
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-1949: End ADSentenceStream at end of file inside an open sentence (opennlp)

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


##########
opennlp-core/opennlp-formats/src/main/java/opennlp/tools/formats/ad/ADSentenceStream.java:
##########
@@ -518,14 +526,10 @@ public Sentence read() throws IOException {
         }
 
       } else {
-        // handle end of file
-        if (sentenceStarted) {
-          if (sentence.length() > 0) {
-            return parser.parse(sentence.toString(), paraID, isTitle, isBox);
-          }
-        } else {
-          return null;
+        if (sentenceStarted && sentence.length() > 0) {

Review Comment:
   Besides a more compact form of the touched code, I don't see any actual change here. 
   So what's the point here?
   
   The tests make sense, no question.



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