You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by kr...@apache.org on 2026/09/30 23:17:41 UTC

(opennlp) 03/04: OPENNLP-1935: Test that whitespace runs in a token sample line produce no empty token

This is an automated email from the ASF dual-hosted git repository.

krickert pushed a commit to branch feat/OPENNLP-1935-regex-guard
in repository https://gitbox.apache.org/repos/asf/opennlp.git

commit da06e6abcf21c205d5ab86a8574c7d6e1e43ee2a
Author: Kristian Rickert <kr...@apache.org>
AuthorDate: Wed Sep 30 18:55:42 2026 -0400

    OPENNLP-1935: Test that whitespace runs in a token sample line produce no empty token
    
    A leading run of spaces and a tab between tokens separate the tokens like a single space.
---
 .../tools/tokenize/TokenSampleStreamTest.java      | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)

diff --git a/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java b/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java
index 22769a4c6..661ab3c4e 100644
--- a/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java
+++ b/opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/tokenize/TokenSampleStreamTest.java
@@ -54,6 +54,28 @@ public class TokenSampleStreamTest {
     Assertions.assertEquals("wage", tokenSpans[3].getCoveredText(sampleTokens));
   }
 
+  /**
+   * Tests that runs of whitespace, including a leading run and a tab, separate tokens
+   * without producing an empty token.
+   */
+  @Test
+  void testParsingWhitespaceRunsSeparateTokens() throws IOException {
+    String sampleTokens = "  Slave\tto  the wage ";
+
+    ObjectStream<TokenSample> sampleTokenStream = new TokenSampleStream(
+        ObjectStreamUtils.createObjectStream(sampleTokens));
+
+    TokenSample tokenSample = sampleTokenStream.read();
+    Span[] tokenSpans = tokenSample.getTokenSpans();
+    String text = tokenSample.getText();
+
+    Assertions.assertEquals(4, tokenSpans.length);
+    Assertions.assertEquals("Slave", tokenSpans[0].getCoveredText(text));
+    Assertions.assertEquals("to", tokenSpans[1].getCoveredText(text));
+    Assertions.assertEquals("the", tokenSpans[2].getCoveredText(text));
+    Assertions.assertEquals("wage", tokenSpans[3].getCoveredText(text));
+  }
+
   /**
    * Tests if the {@link TokenSample} correctly tokenizes tokens which
    * are separated by the split chars.