]> git.saurik.com Git - apple/icu.git/blobdiff - icuSources/data/brkitr/word.txt
ICU-531.48.tar.gz
[apple/icu.git] / icuSources / data / brkitr / word.txt
index f8bc820c962cc7ec88337656e55cff7a9c01246b..8d37f031281131a791761feea325f6bd78536472 100644 (file)
 #
-#   Copyright (C) 2002-2003, International Business Machines Corporation and others.
-#       All Rights Reserved.
+# Copyright (C) 2002-2015, International Business Machines Corporation 
+# and others. All Rights Reserved.
 #
-#   file:  word.txt   
+# file:  word.txt
 #
-#   ICU Word Break Rules
+# ICU Word Break Rules
 #      See Unicode Standard Annex #29.
-#      These rules are based on Version 4.0.0, dated 2003-04-17
+#      These rules are based on UAX #29 Revision 22 for Unicode Version 6.3
 #
+# Note:  Updates to word.txt will usually need to be merged into
+#        word_POSIX.txt also.
 
-
-
-####################################################################################
+##############################################################################
 #
 #  Character class definitions from TR 29
 #
-####################################################################################
-$Katakana  = [[:Script = KATAKANA:] [:name = KATAKANA-HIRAGANA PROLONGED SOUND MARK:] 
-                                   [:name = HALFWIDTH KATAKANA-HIRAGANA PROLONGED SOUND MARK:]
-                                   [:name = HALFWIDTH KATAKANA VOICED SOUND MARK:]
-                                   [:name = HALFWIDTH KATAKANA SEMI-VOICED SOUND MARK:]];
-
+##############################################################################
 
-$ALetter   = [[:Alphabetic:] [:name= HEBREW PUNCTUATION GERESH:] 
-                           - [:Ideographic:]
-                           - $Katakana
-                           - [:Script = Thai:]
-                           - [:Script = Lao:]
-                           - [:Script = Hiragana:]];
-                           
-$MidLetter = [[:name = APOSTROPHE:] [:name = MIDDLE DOT:]  [:name = HEBREW PUNCTUATION GERSHAYIM:]
-              [:name = RIGHT SINGLE QUOTATION MARK:] [:name = HYPHENATION POINT:]];  
-              
-$MidNumLet = [[:name = FULL STOP:] [:name = COLON:]];
-
-$MidNum    = [[:LineBreak = Infix_Numeric:] - $MidNumLet];
-$Numeric   = [:LineBreak = Numeric:];
+!!chain;
 
 
 #
 #  Character Class Definitions.
-#    The names are those from TR29.
 #
-$CR         = \u000d;
-$LF         = \u000a;
-$Control    = [[:Zl:] [:Zp:] [:Cc:] [:Cf:]];
-$Extend     = [[:Grapheme_Extend = TRUE:]]; 
 
+$CR                 = [\p{Word_Break = CR}];
+$LF                 = [\p{Word_Break = LF}];
+$Newline            = [\p{Word_Break = Newline}];
+$Extend             = [\p{Word_Break = Extend}];
+$Format             = [\p{Word_Break = Format}];
+$Katakana           = [\p{Word_Break = Katakana}];
+$Hebrew_Letter      = [\p{Word_Break = Hebrew_Letter}];
+$ALetter            = [\p{Word_Break = ALetter}];
+$Single_Quote       = [\p{Word_Break = Single_Quote}];
+$Double_Quote       = [\p{Word_Break = Double_Quote}];
+$MidNumLet          = [\p{Word_Break = MidNumLet}];
+$MidLetter          = [\p{Word_Break = MidLetter}];
+$MidNum             = [\p{Word_Break = MidNum}];
+$Numeric            = [\p{Word_Break = Numeric}];
+$ExtendNumLet       = [\p{Word_Break = ExtendNumLet}];
 
+$Han                = [:Han:];
+$Hiragana           = [:Hiragana:];
 
+$RI_A        = \U0001F1E6;  # Trail ETU
+$RI_B        = \U0001F1E7;  # Trail ER
+$RI_C        = \U0001F1E8;  # Trail AHLNO
+$RI_D        = \U0001F1E9;  # Trail EK
+$RI_E        = \U0001F1EA;  # Trail S
+$RI_F        = \U0001F1EB;  # Trail IR
+$RI_G        = \U0001F1EC;  # Trail B
+$RI_H        = \U0001F1ED;  # Trail K
+$RI_I        = \U0001F1EE;  # Trail DELNT
+$RI_J        = \U0001F1EF;  # Trail OP
+$RI_K        = \U0001F1F0;  # Trail R
+$RI_M        = \U0001F1F2;  # Trail OXY
+$RI_N        = \U0001F1F3;  # Trail LOZ
+$RI_P        = \U0001F1F5;  # Trail HLRT
+$RI_R        = \U0001F1F7;  # Trail U
+$RI_S        = \U0001F1F8;  # Trail AEG
+$RI_T        = \U0001F1F9;  # Trail R
+$RI_U        = \U0001F1FA;  # Trail S
+$RI_V        = \U0001F1FB;     # Trail N
+$RI_Z        = \U0001F1FF;     # Trail A
 
-####################################################################################
-#
-#  Word Break Rules.    Definitions and Rules specific to word break begin Here. 
-#
-####################################################################################
+$RI_A_End    = [\U0001F1EA \U0001F1F9 \U0001F1FA];             # ETU
+$RI_B_End    = [\U0001F1EA \U0001F1F7];                         # ER
+$RI_C_End    = [\U0001F1E6 \U0001F1ED \U0001F1F1 \U0001F1F3 \U0001F1F4]; # AHLNO
+$RI_D_End    = [\U0001F1EA \U0001F1F0];                         # EK
+$RI_E_End    = \U0001F1F8;                                      # S
+$RI_F_End    = [\U0001F1EE \U0001F1F7];                         # IR
+$RI_G_End    = \U0001F1E7;                                      # B
+$RI_H_End    = \U0001F1F0;                                      # K
+$RI_I_End    = [\U0001F1E9 \U0001F1EA \U0001F1F1 \U0001F1F3 \U0001F1F9]; # DELNT
+$RI_J_End    = [\U0001F1F5 \U0001F1F4];                         # OP
+$RI_K_End    = \U0001F1F7;                                      # R
+$RI_M_End    = [\U0001F1F4 \U0001F1FD \U0001F1FE];              # OXY
+$RI_N_End    = [\U0001F1F1 \U0001F1F4 \U0001F1FF];              # LOZ
+$RI_P_End    = [\U0001F1ED \U0001F1F1 \U0001F1F7 \U0001F1F9];   # HLRT
+$RI_R_End    = \U0001F1FA;                                      # U
+$RI_S_End    = [\U0001F1E6 \U0001F1EA \U0001F1EC];              # AEG
+$RI_T_End    = \U0001F1F7;                                      # R
+$RI_U_End    = \U0001F1F8;                                      # S
+$RI_V_End    = \U0001F1F3;                                      # N
+$RI_Z_End    = \U0001F1E6;                                      # A
 
-$Format    = [[:Cf:]];
+# Special character classes for people & body part emoji:
+# Subsets of $Extend:
+$ZWJ = \u200D;
+$EmojiVar = \uFE0F;
+# The following are subsets of \p{Word_Break = Other}
+$EmojiForSeqs = [\u2764 \U0001F466-\U0001F469 \U0001F48B];
+$EmojiForMods = [\u261D \u270A-\u270C \U0001F385 \U0001F3C3-\U0001F3C4 \U0001F3C7 \U0001F3CA \U0001F442-\U0001F443 \U0001F446-\U0001F450 \U0001F466-\U0001F469 \U0001F46E-\U0001F478 \U0001F47C \U0001F481-\U0001F483 \U0001F485-\U0001F487 \U0001F4AA \U0001F596 \U0001F645-\U0001F647 \U0001F64B-\U0001F64F \U0001F6A3 \U0001F6B4-\U0001F6B6 \U0001F6C0];
+$EmojiMods = [\U0001F3FB-\U0001F3FF];
 
+#   Dictionary character set, for triggering language-based break engines. Currently
+#   limited to LineBreak=Complex_Context. Note that this set only works in Unicode
+#   5.0 or later as the definition of Complex_Context was corrected to include all
+#   characters requiring dictionary break.
 
+$Control        = [\p{Grapheme_Cluster_Break = Control}]; 
+$HangulSyllable = [\uac00-\ud7a3];
+$ComplexContext = [:LineBreak = Complex_Context:];
+$KanaKanji      = [$Han $Hiragana $Katakana];
+$dictionaryCJK  = [$KanaKanji $HangulSyllable];
+$dictionary     = [$ComplexContext $dictionaryCJK];
 
-# Rule 3:  Treat a grapheme cluster as if it were a single character.
-#          Hangul Syllables are easier to deal with here than they are in Grapheme Clusters
-#          because we don't need to find the boundaries between adjacent syllables -
-#          they won't be word boundaries.
-#
+# leave CJK scripts out of ALetterPlus
+$ALetterPlus  = [$ALetter-$dictionaryCJK [$ComplexContext-$Extend-$Control]];
 
 
 #
-#  "Extended"  definitions.  Grapheme Cluster + Format Chars, treated like the base char.
+#  Rules 4    Ignore Format and Extend characters, 
+#             except when they appear at the beginning of a region of text.
 #
-$ALetterEx    = $ALetter   $Extend*; 
-$NumericEx    = $Numeric   $Extend*;
-$MidNumEx     = $MidNum    $Extend*;
-$MidNumLetEx  = $MidNumLet $Extend*;
-$MidLetterEx  = $MidLetter $Extend*;
-$KatakanaEx   = $Katakana  $Extend*;
-$FormatEx     = $Format    $Extend*;
-
+# TODO: check if handling of katakana in dictionary makes rules incorrect/void
+$KatakanaEx           = $Katakana           ($Extend |  $Format)*;
+$Hebrew_LetterEx      = $Hebrew_Letter      ($Extend |  $Format)*;
+$ALetterEx            = $ALetterPlus        ($Extend |  $Format)*;
+$Single_QuoteEx       = $Single_Quote       ($Extend |  $Format)*;
+$Double_QuoteEx       = $Double_Quote       ($Extend |  $Format)*;
+$MidNumLetEx          = $MidNumLet          ($Extend |  $Format)*;
+$MidLetterEx          = $MidLetter          ($Extend |  $Format)*;
+$MidNumEx             = $MidNum             ($Extend |  $Format)*;
+$NumericEx            = $Numeric            ($Extend |  $Format)*;
+$ExtendNumLetEx       = $ExtendNumLet       ($Extend |  $Format)*;
 
-#
-#  Numbers.  Rules 8, 11, 12 form the TR.
-#
-$NumberSequence = $NumericEx ($FormatEx* ($MidNumEx | $MidNumLetEx)? $FormatEx* $NumericEx)*;
-$NumberSequence {100};
+$Ideographic    = [\p{Ideographic}];
+$HiraganaEx     = $Hiragana     ($Extend |  $Format)*;
+$IdeographicEx  = $Ideographic  ($Extend |  $Format)*;
 
-#
-#  Words.  Alpha-numerics.  Rule 5, 6, 7, 9, 10
-#     - must include at least one letter. 
-#     - may include both letters and numbers.
-#     - may include  MideLetter, MidNumber punctuation.
-#
-$LetterSequence = $ALetterEx ($FormatEx* ($MidLetterEx | $MidNumLetEx)? $FormatEx* $ALetterEx)*;     # rules #6, #7
-($NumberSequence $FormatEx*)? $LetterSequence ($FormatEx* ($NumberSequence | $LetterSequence))* {200};
+## -------------------------------------------------
 
-#
-#  Do not break between Katakana.   Rule #13.
-#
-$KatakanaEx ($FormatEx* $KatakanaEx)* {300};
-[:Hiragana:] $Extend* {300};
+!!forward;
 
-#
-#  Ideographic Characters.  Stand by themselves as words.
-#                           Separated from the "Everything Else" rule, below, only so that they
-#                           can be tagged with a return value.   TODO:  is this what we want?
-#
-[:IDEOGRAPHIC:] $Extend* {400};
 
+# Rule 3 - CR x LF
 #
-#  Everything Else, with no tag.
-#                   Non-Control chars combine with $Extend (combining) chars.
-#                   Controls are do not.
-#
-[^$Control [:Ideographic:]] $Extend*;
 $CR $LF;
 
+# Rule 4 - ignore Format and Extend characters, except when they appear at the beginning
+#          of a region of Text.   The rule here comes into play when the start of text
+#          begins with a group of Format chars, or with a "word" consisting of a single
+#          char that is not in any of the listed word break categories followed by
+#          format char(s), or is not a CJK dictionary character.
+[^$CR $LF $Newline]? ($Extend |  $Format)+;
+
+$NumericEx {100};
+$ALetterEx {200};
+$HangulSyllable {200};
+$Hebrew_LetterEx{200};
+$KatakanaEx {400};       # note:  these status values override those from rule 5
+$HiraganaEx {400};       #        by virtue of being numerically larger.
+$IdeographicEx {400};    #
+
 #
-#  Reverse Rules.   Back up over any of the chars that can group together.
-#                   (Reverse rules do not need to be exact; they can back up  too far,
-#                   but must back up at least enough, and must stop on a boundary.)
+# rule 5
+#    Do not break between most letters.
 #
+($ALetterEx | $Hebrew_LetterEx)  ($ALetterEx | $Hebrew_LetterEx) {200};
+
+# rule 6 and 7
+($ALetterEx | $Hebrew_LetterEx) ($MidLetterEx | $MidNumLetEx | $Single_QuoteEx) ($ALetterEx | $Hebrew_LetterEx) {200};
+
+# rule 7a
+$Hebrew_LetterEx $Single_QuoteEx {200};
+
+# rule 7b and 7c
+$Hebrew_LetterEx $Double_QuoteEx $Hebrew_LetterEx {200};
+
+# rule 8
+
+$NumericEx $NumericEx {100};
+
+# rule 9
+
+($ALetterEx | $Hebrew_LetterEx) $NumericEx {200};
+
+# rule 10
+
+$NumericEx ($ALetterEx | $Hebrew_LetterEx) {200};
+
+# rule 11 and 12 
+
+$NumericEx ($MidNumEx | $MidNumLetEx | $Single_QuoteEx) $NumericEx {100};
+
+# rule 13
+# to be consistent with $KanaKanji $KanaKanhi, changed
+# from 300 to 400.
+# See also TestRuleStatus in intltest/rbbiapts.cpp
+$KatakanaEx  $KatakanaEx {400};
+
+# rule 13a/b
+
+$ALetterEx       $ExtendNumLetEx {200};    #  (13a)
+$Hebrew_LetterEx $ExtendNumLetEx {200};    #  (13a)
+$NumericEx       $ExtendNumLetEx {100};    #  (13a)
+$KatakanaEx      $ExtendNumLetEx {400};    #  (13a)
+$ExtendNumLetEx  $ExtendNumLetEx {200};    #  (13a)
+
+$ExtendNumLetEx  $ALetterEx      {200};    #  (13b)
+$ExtendNumLetEx  $Hebrew_Letter  {200};    #  (13b)
+$ExtendNumLetEx  $NumericEx      {100};    #  (13b)
+$ExtendNumLetEx  $KatakanaEx     {400};    #  (13b)
+
+# rule 13c
+
+$RI_A ($Extend|$Format)* $RI_A_End ($Extend|$Format)*;
+$RI_B ($Extend|$Format)* $RI_B_End ($Extend|$Format)*;
+$RI_C ($Extend|$Format)* $RI_C_End ($Extend|$Format)*;
+$RI_D ($Extend|$Format)* $RI_D_End ($Extend|$Format)*;
+$RI_E ($Extend|$Format)* $RI_E_End ($Extend|$Format)*;
+$RI_F ($Extend|$Format)* $RI_F_End ($Extend|$Format)*;
+$RI_G ($Extend|$Format)* $RI_G_End ($Extend|$Format)*;
+$RI_H ($Extend|$Format)* $RI_H_End ($Extend|$Format)*;
+$RI_I ($Extend|$Format)* $RI_I_End ($Extend|$Format)*;
+$RI_J ($Extend|$Format)* $RI_J_End ($Extend|$Format)*;
+$RI_K ($Extend|$Format)* $RI_K_End ($Extend|$Format)*;
+$RI_M ($Extend|$Format)* $RI_M_End ($Extend|$Format)*;
+$RI_N ($Extend|$Format)* $RI_N_End ($Extend|$Format)*;
+$RI_P ($Extend|$Format)* $RI_P_End ($Extend|$Format)*;
+$RI_R ($Extend|$Format)* $RI_R_End ($Extend|$Format)*;
+$RI_S ($Extend|$Format)* $RI_S_End ($Extend|$Format)*;
+$RI_T ($Extend|$Format)* $RI_T_End ($Extend|$Format)*;
+$RI_U ($Extend|$Format)* $RI_U_End ($Extend|$Format)*;
+$RI_V ($Extend|$Format)* $RI_V_End ($Extend|$Format)*;
+$RI_Z ($Extend|$Format)* $RI_Z_End ($Extend|$Format)*;
+
+# Special forward rules for people & body part emoji:
+# don't break $ZWJ from subsequent $EmojiForSeqs; don't break between relevant emoji and $EmojiMods
+$ZWJ $EmojiForSeqs;
+$EmojiForMods $EmojiVar? $EmojiMods;
+
+# special handling for CJK characters: chain for later dictionary segmentation
+$HangulSyllable $HangulSyllable {200};
+$KanaKanji $KanaKanji {400}; # different rule status if both kana and kanji found 
+
 
-# NonStarters are the set of all characters that can appear at the 2nd - nth position of
-#    a word.   (They may also be the first.)   The reverse rule skips over these, until it
-#    reaches something that can only be the start (and probably only) char in a "word".
-#    A space or punctuation meets the test.
+## -------------------------------------------------
+
+!!reverse;
+
+$BackHebrew_LetterEx      = ($Format | $Extend)* $Hebrew_Letter;
+$BackALetterEx            = ($Format | $Extend)* $ALetterPlus;
+$BackSingle_QuoteEx       = ($Format | $Extend)* $Single_Quote;
+$BackDouble_QuoteEx       = ($Format | $Extend)* $Double_Quote;
+$BackMidNumLetEx          = ($Format | $Extend)* $MidNumLet;
+$BackNumericEx            = ($Format | $Extend)* $Numeric;
+$BackMidNumEx             = ($Format | $Extend)* $MidNum;
+$BackMidLetterEx          = ($Format | $Extend)* $MidLetter;
+$BackKatakanaEx           = ($Format | $Extend)* $Katakana;
+$BackHiraganaEx           = ($Format | $Extend)* $Hiragana;
+$BackExtendNumLetEx       = ($Format | $Extend)* $ExtendNumLet;
+
+# rule 3
+$LF $CR;
+
+# rule 4
+($Format | $Extend)*  [^$CR $LF $Newline]?;
+
+# rule 5
+
+($BackALetterEx | $BackHebrew_LetterEx) ($BackALetterEx | $BackHebrew_LetterEx);
+
+# rule 6 and 7
+
+($BackALetterEx | $BackHebrew_LetterEx) ($BackMidLetterEx | $BackMidNumLetEx | $BackSingle_QuoteEx) ($BackALetterEx | $BackHebrew_LetterEx);
+
+# rule 7a
+$BackSingle_QuoteEx $BackHebrew_LetterEx;
+
+# Rule 7b and 7c
+$BackHebrew_LetterEx $BackDouble_QuoteEx $BackHebrew_LetterEx;
+
+# rule 8
+
+$BackNumericEx $BackNumericEx;
+
+# rule 9
+
+$BackNumericEx ($BackALetterEx | $BackHebrew_LetterEx);
+
+# rule 10
+
+($BackALetterEx | $BackHebrew_LetterEx) $BackNumericEx;
+
+# rule 11 and 12
+
+$BackNumericEx ($BackMidNumEx | $BackMidNumLetEx | $BackSingle_QuoteEx) $BackNumericEx;
+
+# rule 13
+
+$BackKatakanaEx $BackKatakanaEx;
+
+# rules 13 a/b
 #
-$NonStarters = [$Numeric $ALetter $Katakana $MidLetter $MidNum $MidNumLet $Extend $Format];
+$BackExtendNumLetEx ($BackALetterEx | $BackHebrew_LetterEx | $BackNumericEx | $BackKatakanaEx | $BackExtendNumLetEx);
+($BackALetterEx | $BackHebrew_LetterEx | $BackNumericEx | $BackKatakanaEx) $BackExtendNumLetEx; 
+
+# rule 13c
+
+($Format|$Extend)* $RI_A_End ($Format|$Extend)* $RI_A;
+($Format|$Extend)* $RI_B_End ($Format|$Extend)* $RI_B;
+($Format|$Extend)* $RI_C_End ($Format|$Extend)* $RI_C;
+($Format|$Extend)* $RI_D_End ($Format|$Extend)* $RI_D;
+($Format|$Extend)* $RI_E_End ($Format|$Extend)* $RI_E;
+($Format|$Extend)* $RI_F_End ($Format|$Extend)* $RI_F;
+($Format|$Extend)* $RI_G_End ($Format|$Extend)* $RI_G;
+($Format|$Extend)* $RI_H_End ($Format|$Extend)* $RI_H;
+($Format|$Extend)* $RI_I_End ($Format|$Extend)* $RI_I;
+($Format|$Extend)* $RI_J_End ($Format|$Extend)* $RI_J;
+($Format|$Extend)* $RI_K_End ($Format|$Extend)* $RI_K;
+($Format|$Extend)* $RI_M_End ($Format|$Extend)* $RI_M;
+($Format|$Extend)* $RI_N_End ($Format|$Extend)* $RI_N;
+($Format|$Extend)* $RI_P_End ($Format|$Extend)* $RI_P;
+($Format|$Extend)* $RI_R_End ($Format|$Extend)* $RI_R;
+($Format|$Extend)* $RI_S_End ($Format|$Extend)* $RI_S;
+($Format|$Extend)* $RI_T_End ($Format|$Extend)* $RI_T;
+($Format|$Extend)* $RI_U_End ($Format|$Extend)* $RI_U;
+($Format|$Extend)* $RI_V_End ($Format|$Extend)* $RI_V;
+($Format|$Extend)* $RI_Z_End ($Format|$Extend)* $RI_Z;
+
+# Special reverse rules for people & body part emoji:
+# don't break $ZWJ from subsequent $EmojiForSeqs; don't break between relevant emoji and $EmojiMods
+$EmojiForSeqs $ZWJ;
+$EmojiMods $EmojiVar? $EmojiForMods;
+
+# special handling for CJK characters: chain for later dictionary segmentation
+$HangulSyllable $HangulSyllable;
+$KanaKanji $KanaKanji; #different rule status if both kanji and kana found
+
+## -------------------------------------------------
+
+!!safe_reverse;
+
+# rule 3
+($Extend | $Format)+ .?;
+
+# rule 6
+($MidLetter | $MidNumLet | $Single_Quote) ($BackALetterEx | $BackHebrew_LetterEx);
+
+# rule 7b
+$Double_Quote $BackHebrew_LetterEx;
+
+
+# rule 11
+($MidNum | $MidNumLet | $Single_Quote) $BackNumericEx;
+
+# For dictionary-based break
+$dictionary $dictionary;
+
+## -------------------------------------------------
+
+!!safe_forward;
+
+# rule 4
+($Extend | $Format)+ .?;
+
+# rule 6
+($MidLetterEx | $MidNumLetEx | $Single_QuoteEx) ($ALetterEx | $Hebrew_LetterEx);
+
+# rule 7b
+$Double_QuoteEx $Hebrew_LetterEx;
+
+# rule 11
+($MidNumEx | $MidNumLetEx | $Single_QuoteEx) $NumericEx;
 
-#!.*;
-! ($NonStarters* | \n \r) .;
+# For dictionary-based break
+$dictionary $dictionary;