You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@opennlp.apache.org by ma...@apache.org on 2026/10/06 19:34:10 UTC
(opennlp) branch main updated: GH-1422: Clean up NumberUtil and its tests in opennlp-uima (#1432)
This is an automated email from the ASF dual-hosted git repository.
mawiesne pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/opennlp.git
The following commit(s) were added to refs/heads/main by this push:
new af742d8bd GH-1422: Clean up NumberUtil and its tests in opennlp-uima (#1432)
af742d8bd is described below
commit af742d8bdc444f4f2bba27c6d6963f712b5ef0b4
Author: Richard Zowalla <13...@users.noreply.github.com>
AuthorDate: Tue Oct 6 21:34:04 2026 +0200
GH-1422: Clean up NumberUtil and its tests in opennlp-uima (#1432)
---
.../java/opennlp/uima/normalizer/NumberUtil.java | 7 ++++--
.../opennlp/uima/normalizer/NumberUtilTest.java | 26 +++++++---------------
2 files changed, 13 insertions(+), 20 deletions(-)
diff --git a/opennlp-extensions/opennlp-uima/src/main/java/opennlp/uima/normalizer/NumberUtil.java b/opennlp-extensions/opennlp-uima/src/main/java/opennlp/uima/normalizer/NumberUtil.java
index c421b6633..a7d7d8e2a 100644
--- a/opennlp-extensions/opennlp-uima/src/main/java/opennlp/uima/normalizer/NumberUtil.java
+++ b/opennlp-extensions/opennlp-uima/src/main/java/opennlp/uima/normalizer/NumberUtil.java
@@ -53,8 +53,8 @@ public final class NumberUtil {
/**
* Parses a specified {@link String number} for a certain {@code languageCode}.
* <p>
- * Before parsing, every Unicode {@code White_Space} code point is removed from
- * {@code number}.
+ * Before parsing, every Unicode {@code White_Space} code point, as defined by
+ * {@link StringUtil#isUnicodeWhitespace(int)}, is removed from {@code number}.
*
* @param number The suspected number to parse.
* @param languageCode A ISO conform language code, e.g. "en", "pt"
@@ -79,6 +79,9 @@ public final class NumberUtil {
/**
* Removes every Unicode {@code White_Space} code point from the given string.
+ *
+ * @param s The string to strip.
+ * @return The string without any Unicode {@code White_Space} code point.
*/
private static String removeWhitespace(String s) {
final StringBuilder sb = new StringBuilder(s.length());
diff --git a/opennlp-extensions/opennlp-uima/src/test/java/opennlp/uima/normalizer/NumberUtilTest.java b/opennlp-extensions/opennlp-uima/src/test/java/opennlp/uima/normalizer/NumberUtilTest.java
index 4e6213021..b56af7358 100644
--- a/opennlp-extensions/opennlp-uima/src/test/java/opennlp/uima/normalizer/NumberUtilTest.java
+++ b/opennlp-extensions/opennlp-uima/src/test/java/opennlp/uima/normalizer/NumberUtilTest.java
@@ -20,6 +20,8 @@ import java.text.ParseException;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.ValueSource;
/**
* Tests for opennlp.uima.normalizer.NumberUtil
@@ -63,24 +65,12 @@ class NumberUtilTest {
} , "java.lang.IllegalArgumentException: Language INVALID is not supported!");
}
- @Test
- void parse_withNoBreakSpaces() throws ParseException {
- // Since 3.0 the pre-parse strip removes every Unicode White_Space code point, so the
- // no-break spaces used as digit grouping separators no longer stop the parse (the
- // previous ASCII \s strip left them in place and en parsing stopped at them).
- Assertions.assertEquals(1234L, NumberUtil.parse("1" + cp(0x00A0) + "234",
- VALID_LANGUAGE_CODE).longValue());
- Assertions.assertEquals(1234L, NumberUtil.parse("1" + cp(0x202F) + "234",
- VALID_LANGUAGE_CODE).longValue());
- }
-
- @Test
- void parse_withLineSeparatorAndNextLineControl() throws ParseException {
- // U+2028 and U+0085 carry the Unicode White_Space property, so since 3.0 they are
- // stripped as well.
- Assertions.assertEquals(1234L, NumberUtil.parse("12" + cp(0x2028) + "34",
- VALID_LANGUAGE_CODE).longValue());
- Assertions.assertEquals(1234L, NumberUtil.parse("12" + cp(0x0085) + "34",
+ @ParameterizedTest
+ @ValueSource(ints = {0x00A0, 0x202F, 0x2028, 0x0085})
+ void parse_withUnicodeWhitespace(int codePoint) throws ParseException {
+ // Every Unicode White_Space code point is stripped before parsing, also in the
+ // thousands separator position where no-break spaces appear.
+ Assertions.assertEquals(1234L, NumberUtil.parse("1" + cp(codePoint) + "234",
VALID_LANGUAGE_CODE).longValue());
}