2 ## The following corresponds to a draft(?) source file from CoreLP of 2017
3 ##############################################################################
5 # Copyright (C) 2016 and later: Unicode, Inc. and others.
6 # License & terms of use: http://www.unicode.org/copyright.html
7 # Copyright (C) 2002-2016, International Business Machines Corporation
8 # and others. All Rights Reserved.
10 # file: word_urbTokTest.txt
12 # ICU Word Break Rules
13 # See Unicode Standard Annex #29.
14 # These rules are based on UAX #29 Revision 29 for Unicode Version 9.0
15 # with additions for Emoji Sequences from https://goo.gl/cluFCn
16 # Also modified with additions for testing urbtok_ functions.
19 ##############################################################################
21 # Character class definitions from TR 29
23 ##############################################################################
27 # Smart Tokenizer customization
30 $Fullstop = [\u002E\uFE52\uFF0E];
31 $Dash = [\u002D\uFE63\uFF0D];
33 $Terminators = [\u0021\u00A1\u00A1\u01C3\u01C3\u01C3\u203C\u2048\uFE15\uFF01\u003F];
34 $Parenthesis = [\u0028\u005B\u007B\u0029\u005D\u007D];
35 $Punctuation = [\u007E\u003D\u002A\u003C\u003E];
36 $OtherSingle = [\u0060\u0300\u030F];
38 $Hash = [\u0023 \uFE5F \uFF03];
39 $At = [\u0040 \uFE6B \uFF20];
42 $Semicolon = [\u003B];
46 # Character Class Definitions.
49 $CR = [\p{Word_Break = CR}];
50 $LF = [\p{Word_Break = LF}];
51 $Newline = [\p{Word_Break = Newline}];
52 $Extend = [\p{Word_Break = Extend}];
53 $ZWJ = [\p{Word_Break = ZWJ}];
54 $Regional_Indicator = [\p{Word_Break = Regional_Indicator}];
55 $Format = [\p{Word_Break = Format}];
56 $Katakana = [\p{Word_Break = Katakana}];
57 $Hebrew_Letter = [\p{Word_Break = Hebrew_Letter}];
58 $ALetter = [\p{Word_Break = ALetter}];
59 $Single_Quote = [\p{Word_Break = Single_Quote}\u2018\u2019];
60 $Double_Quote = [\p{Word_Break = Double_Quote}];
61 $MidNumLet = [\p{Word_Break = MidNumLet}-[$Fullstop $Single_Quote]];
62 $MidLetter = [\p{Word_Break = MidLetter}-[$Single_Quote]];
63 $MidNum = [\p{Word_Break = MidNum}];
64 $Numeric = [\p{Word_Break = Numeric}];
65 $ExtendNumLet = [\p{Word_Break = ExtendNumLet}];
66 $E_Base = [\p{Word_Break = EB}\U0001F3C2\U0001F3C7\U0001F3CC\U0001F46A-\U0001F46D\U0001F46F\U0001F574\U0001F6CC];
67 $E_Modifier = [\p{Word_Break = EM}];
69 # Data for Extended Pictographic scraped from CLDR common/properties/ExtendedPictographic.txt, r12773
70 $Extended_Pict = [\U0001F774-\U0001F77F\u2700-\u2701\u2703-\u2704\u270E\u2710-\u2711\u2765-\u2767\U0001F030-\U0001F093\U0001F094-\U0001F09F\U0001F10D-\U0001F10F\U0001F12F\U0001F16C-\U0001F16F\U0001F1AD-\U0001F1E5\U0001F203-\U0001F20F\U0001F23C-\U0001F23F\U0001F249-\U0001F24F\U0001F252-\U0001F2FF\U0001F7D5-\U0001F7FF\U0001F000-\U0001F003\U0001F005-\U0001F02B\U0001F02C-\U0001F02F\U0001F322-\U0001F323\U0001F394-\U0001F395\U0001F398\U0001F39C-\U0001F39D\U0001F3F1-\U0001F3F2\U0001F3F6\U0001F4FE\U0001F53E-\U0001F548\U0001F54F\U0001F568-\U0001F56E\U0001F571-\U0001F572\U0001F57B-\U0001F586\U0001F588-\U0001F589\U0001F58E-\U0001F58F\U0001F591-\U0001F594\U0001F597-\U0001F5A3\U0001F5A6-\U0001F5A7\U0001F5A9-\U0001F5B0\U0001F5B3-\U0001F5BB\U0001F5BD-\U0001F5C1\U0001F5C5-\U0001F5D0\U0001F5D4-\U0001F5DB\U0001F5DF-\U0001F5E0\U0001F5E2\U0001F5E4-\U0001F5E7\U0001F5E9-\U0001F5EE\U0001F5F0-\U0001F5F2\U0001F5F4-\U0001F5F9\u2605\u2607-\u260D\u260F-\u2610\u2612\u2616-\u2617\u2619-\u261C\u261E-\u261F\u2621\u2624-\u2625\u2627-\u2629\u262B-\u262D\u2630-\u2637\u263B-\u2647\u2654-\u265F\u2661-\u2662\u2664\u2667\u2669-\u267A\u267C-\u267E\u2680-\u2691\u2695\u2698\u269A\u269D-\u269F\u26A2-\u26A9\u26AC-\u26AF\u26B2-\u26BC\u26BF-\u26C3\u26C6-\u26C7\u26C9-\u26CD\u26D0\u26D2\u26D5-\u26E8\u26EB-\u26EF\u26F6\u26FB-\u26FC\u26FE-\u26FF\u2388\U0001FA00-\U0001FFFD\U0001F0A0-\U0001F0AE\U0001F0B1-\U0001F0BF\U0001F0C1-\U0001F0CF\U0001F0D1-\U0001F0F5\U0001F0AF-\U0001F0B0\U0001F0C0\U0001F0D0\U0001F0F6-\U0001F0FF\U0001F80C-\U0001F80F\U0001F848-\U0001F84F\U0001F85A-\U0001F85F\U0001F888-\U0001F88F\U0001F8AE-\U0001F8FF\U0001F900-\U0001F90F\U0001F91F\U0001F928-\U0001F92F\U0001F931-\U0001F932\U0001F93F\U0001F94C-\U0001F94F\U0001F95F-\U0001F97F\U0001F992-\U0001F9BF\U0001F9C1-\U0001F9FF\U0001F6C6-\U0001F6CA\U0001F6E6-\U0001F6E8\U0001F6EA\U0001F6F1-\U0001F6F2\U0001F6D3-\U0001F6DF\U0001F6ED-\U0001F6EF\U0001F6F7-\U0001F6FF];
71 $EBG = [\p{Word_Break = EBG}];
72 $EmojiNRK = [[\p{Emoji}] - [\p{Word_Break = Regional_Indicator}\u002a\u00230-9©®™〰〽]];
75 $Hiragana = [:Hiragana:];
78 # Dictionary character set, for triggering language-based break engines. Currently
79 # limited to LineBreak=Complex_Context. Note that this set only works in Unicode
80 # 5.0 or later as the definition of Complex_Context was corrected to include all
81 # characters requiring dictionary break.
83 $Control = [\p{Grapheme_Cluster_Break = Control}];
84 $HangulSyllable = [\uac00-\ud7a3];
85 $ComplexContext = [:LineBreak = Complex_Context:];
86 $KanaKanji = [$Han $Hiragana $Katakana];
87 $dictionaryCJK = [$KanaKanji $HangulSyllable];
88 $dictionary = [$ComplexContext $dictionaryCJK];
90 # leave CJK scripts out of ALetterPlus
91 $ALetterPlus = [$ALetter-$dictionaryCJK [$ComplexContext-$Extend-$Control]];
95 # Rules 4 Ignore Format and Extend characters,
96 # except when they appear at the beginning of a region of text.
98 # TODO: check if handling of katakana in dictionary makes rules incorrect/void
99 $KatakanaEx = $Katakana ($Extend | $Format | $ZWJ)*;
100 $Hebrew_LetterEx = $Hebrew_Letter ($Extend | $Format | $ZWJ)*;
101 $ALetterEx = $ALetterPlus ($Extend | $Format | $ZWJ)*;
102 $Single_QuoteEx = $Single_Quote ($Extend | $Format | $ZWJ)*;
103 $Double_QuoteEx = $Double_Quote ($Extend | $Format | $ZWJ)*;
104 $MidNumLetEx = $MidNumLet ($Extend | $Format | $ZWJ)*;
105 $MidLetterEx = $MidLetter ($Extend | $Format | $ZWJ)*;
106 $MidNumEx = $MidNum ($Extend | $Format | $ZWJ)*;
107 $NumericEx = $Numeric ($Extend | $Format | $ZWJ)*;
108 $ExtendNumLetEx = $ExtendNumLet ($Extend | $Format | $ZWJ)*;
109 $Regional_IndicatorEx = $Regional_Indicator ($Extend | $Format | $ZWJ)*;
111 $Ideographic = [\p{Ideographic}];
112 $HiraganaEx = $Hiragana ($Extend | $Format | $ZWJ)*;
113 $IdeographicEx = $Ideographic ($Extend | $Format | $ZWJ)*;
117 ## -------------------------------------------------
125 # Rule 3c ZWJ x (Extended_Pict | EmojiNRK). Precedes WB4, so no intervening Extend chars allowed.
127 $ZWJ ($Extended_Pict | $EmojiNRK);
130 # Rule 4 - ignore Format and Extend characters, except when they appear at the beginning
131 # of a region of Text. The rule here comes into play when the start of text
132 # begins with a group of Format chars, or with a "word" consisting of a single
133 # char that is not in any of the listed word break categories followed by
134 # format char(s), or is not a CJK dictionary character.
135 [^$CR $LF $Newline]? ($Extend | $Format | $ZWJ)+;
139 $HangulSyllable {200};
140 $Hebrew_LetterEx{200};
141 $KatakanaEx {400}; # note: these status values override those from rule 5
142 $HiraganaEx {400}; # by virtue of being numerically larger.
143 $IdeographicEx {400}; #
145 $E_Base ($Extend | $Format | $ZWJ)*;
146 $E_Modifier ($Extend | $Format | $ZWJ)*;
147 $Extended_Pict ($Extend | $Format | $ZWJ)*;
151 # Do not break between most letters.
153 ($ALetterEx | $Hebrew_LetterEx) ($ALetterEx | $Hebrew_LetterEx) {200};
156 ($ALetterEx | $Hebrew_LetterEx) ($MidLetterEx | $MidNumLetEx ) ($ALetterEx | $Hebrew_LetterEx) {200};
159 $Hebrew_LetterEx $Single_QuoteEx {200};
162 $Hebrew_LetterEx $Double_QuoteEx $Hebrew_LetterEx {200};
166 $NumericEx $NumericEx {100};
170 ($ALetterEx | $Hebrew_LetterEx) $NumericEx {200};
174 $NumericEx ($ALetterEx | $Hebrew_LetterEx) {200};
178 $NumericEx ($MidNumEx | $MidNumLetEx | $Single_QuoteEx) $NumericEx {100};
181 # to be consistent with $KanaKanji $KanaKanhi, changed
183 # See also TestRuleStatus in intltest/rbbiapts.cpp
184 $KatakanaEx $KatakanaEx {400};
188 $ALetterEx $ExtendNumLetEx {200}; # (13a)
189 $Hebrew_LetterEx $ExtendNumLetEx {200}; # (13a)
190 $NumericEx $ExtendNumLetEx {100}; # (13a)
191 $KatakanaEx $ExtendNumLetEx {400}; # (13a)
192 $ExtendNumLetEx $ExtendNumLetEx {200}; # (13a)
194 $ExtendNumLetEx $ALetterEx {200}; # (13b)
195 $ExtendNumLetEx $Hebrew_Letter {200}; # (13b)
196 $ExtendNumLetEx $NumericEx {100}; # (13b)
197 $ExtendNumLetEx $KatakanaEx {400}; # (13b)
200 # Do not break within emoji modifier sequences
202 ($E_Base | $EBG) ($Format | $Extend | $ZWJ)* $E_Modifier;
205 # Pairs of Regional Indicators stay together.
206 # With rule chaining disabled by ^, this rule will match exactly two of them.
207 # No other rule begins with a Regional_Indicator, so chaining cannot extend the match.
209 ^$Regional_IndicatorEx $Regional_IndicatorEx;
211 # special handling for CJK characters: chain for later dictionary segmentation
212 $HangulSyllable $HangulSyllable {200};
213 $KanaKanji $KanaKanji {400}; # different rule status if both kana and kanji found
222 $Contraction = (N | n) $Single_Quote (T | t);
223 $Contraction2 = (N | n) $Single_Quote (T | t) $Single_Quote (V | v) (E | e);
224 $Contraction3 = (Y | y) $Single_Quote (A | a) (L | l) (L | l);
226 $Time = (0 | 1 | 2)? $Numeric $Colon (0 | 1 | 2 | 3 | 4 | 5) $Numeric;
227 $IPAddress = $Numeric? $Numeric? $Numeric $Fullstop $Numeric? $Numeric? $Numeric;
229 (N | n) $Single_Quote (T | t) {202};
230 (Y | y) $Single_Quote (A | a) (L | l)* {202};
232 $Fullstop $Fullstop ($Fullstop*) {40};
233 $Dash $Dash ($Dash*) {40};
234 $Terminators $Terminators ($Terminators*) {40};
235 $Punctuation $Punctuation ($Punctuation*) {40};
236 $OtherSingle $OtherSingle ($OtherSingle*) {40};
238 $Single_Quote $Single_Quote {40};
239 $Single_Quote $Single_Quote $Single_Quote* {40};
241 $Hash ($ALetter | $Numeric)* {30};
242 $At ($ALetter | $Numeric)* {31};
243 $Dollar $ALetter ($ALetter | $Numeric)* {31};
248 $ALetter / $IPAddress;
251 ($Colon | $Semicolon) $Parenthesis {32};
254 # Match a single code point if no other rule applies.
258 ## -------------------------------------------------
259 # definitions for no-longer-used reverse rules, needed by safe_reverse
261 $BackHebrew_LetterEx = ($Format | $Extend | $ZWJ)* $Hebrew_Letter;
262 $BackALetterEx = ($Format | $Extend | $ZWJ)* $ALetterPlus;
263 $BackSingle_QuoteEx = ($Format | $Extend | $ZWJ)* $Single_Quote;
264 $BackDouble_QuoteEx = ($Format | $Extend | $ZWJ)* $Double_Quote;
265 $BackMidNumLetEx = ($Format | $Extend | $ZWJ)* $MidNumLet;
266 $BackNumericEx = ($Format | $Extend | $ZWJ)* $Numeric;
267 $BackMidNumEx = ($Format | $Extend | $ZWJ)* $MidNum;
268 $BackMidLetterEx = ($Format | $Extend | $ZWJ)* $MidLetter;
269 $BackKatakanaEx = ($Format | $Extend | $ZWJ)* $Katakana;
270 $BackHiraganaEx = ($Format | $Extend | $ZWJ)* $Hiragana;
271 $BackExtendNumLetEx = ($Format | $Extend | $ZWJ)* $ExtendNumLet;
272 $BackRegional_IndicatorEx = ($Format | $Extend | $ZWJ)* $Regional_Indicator;
274 ## -------------------------------------------------
279 ($Extend | $Format | $ZWJ)+ .?;
282 ($MidLetter | $MidNumLet | $Single_Quote) ($BackALetterEx | $BackHebrew_LetterEx);
285 $Double_Quote $BackHebrew_LetterEx;
289 ($MidNum | $MidNumLet | $Single_Quote) $BackNumericEx;
292 $BackRegional_IndicatorEx*;
294 # For dictionary-based break
295 $dictionary $dictionary;