Skip to content

Commit 0ec5a36

Browse files
committed
OPENNLP-1850 Clarify that Extended_Pictographic symbols are kept as emoji
WordType classifies every Extended_Pictographic code point as EMOJI, which includes symbol-like characters (copyright, trademark, double-exclamation, arrows), so the word tokenizer keeps them rather than dropping them as punctuation. State this in the WordTokenizer javadoc and add a test.
1 parent 3c57a74 commit 0ec5a36

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

opennlp-core/opennlp-runtime/src/main/java/opennlp/tools/tokenize/uax29/WordTokenizer.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,9 @@
2626
* A word tokenizer built on the Unicode Text Segmentation algorithm (UAX #29). It finds segments
2727
* with {@link WordSegmenter}, keeps the ones that are words (letters, digits, ideographs, kana,
2828
* Hangul, Southeast-Asian script, or emoji), drops whitespace and punctuation, and classifies each
29-
* kept token with a {@link WordType}.
29+
* kept token with a {@link WordType}. Emoji here means any {@code Extended_Pictographic} code point,
30+
* so symbol-like characters such as the copyright, trademark, and double-exclamation signs are kept
31+
* (typed {@link WordType#EMOJI}) rather than dropped as punctuation.
3032
*
3133
* <p>A token longer than {@code maxTokenLength} is emitted as consecutive pieces, never splitting a
3234
* surrogate pair. The tokenizer reports offset {@link Span}s, so the original text and its character

opennlp-core/opennlp-runtime/src/test/java/opennlp/tools/tokenize/uax29/WordTokenizerTest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,18 @@ void testKatakanaRunStaysTogether() {
8989
assertEquals(text, tokens.get(0).text(text));
9090
}
9191

92+
@Test
93+
void testExtendedPictographicSymbolsAreKeptAsEmoji() {
94+
// Extended_Pictographic includes symbol-like characters (copyright U+00A9, trademark U+2122,
95+
// double exclamation U+203C), which WordType classifies as EMOJI, so the tokenizer keeps them
96+
// rather than dropping them as punctuation.
97+
final String text = "a " + cp(0x00A9) + " " + cp(0x2122) + " " + cp(0x203C) + " b";
98+
final List<WordToken> tokens = TOKENIZER.tokenizeTyped(text);
99+
assertEquals(List.of(WordType.ALPHANUMERIC, WordType.EMOJI, WordType.EMOJI,
100+
WordType.EMOJI, WordType.ALPHANUMERIC),
101+
tokens.stream().map(WordToken::type).toList());
102+
}
103+
92104
@Test
93105
void testHangulSyllablesStayTogether() {
94106
final String text = cp(0xAC00) + cp(0xB098); // ga + na

0 commit comments

Comments
 (0)