| 1 |
# |
| 2 |
# Licensed to the Apache Software Foundation (ASF) under one or more |
| 3 |
# contributor license agreements. See the NOTICE file distributed with |
| 4 |
# this work for additional information regarding copyright ownership. |
| 5 |
# The ASF licenses this file to You under the Apache License, Version 2.0 |
| 6 |
# (the "License"); you may not use this file except in compliance with |
| 7 |
# the License. You may obtain a copy of the License at |
| 8 |
# |
| 9 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 |
# |
| 11 |
# Unless required by applicable law or agreed to in writing, software |
| 12 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 |
# See the License for the specific language governing permissions and |
| 15 |
# limitations under the License. |
| 16 |
# |
| 17 |
# This file is from ICU (with some small modifications, to avoid CJK dictionary break, |
| 18 |
# and status code change related to that) |
| 19 |
# |
| 20 |
# To update this file: grab rule file corresponding to your ICU version, e.g.: |
| 21 |
# https://github.com/unicode-org/icu/blob/release-74-2/icu4c/source/data/brkitr/rules/word.txt |
| 22 |
# |
| 23 |
# * Prevent dictionary break: disable final rule that would chain han and kana |
| 24 |
# * For kana rules, change from 400 to 300 status (since there's no dictionary break) |
| 25 |
# |
| 26 |
# Copyright (C) 2016 and later: Unicode, Inc. and others. |
| 27 |
# License & terms of use: http://www.unicode.org/copyright.html |
| 28 |
# Copyright (C) 2002-2016, International Business Machines Corporation |
| 29 |
# and others. All Rights Reserved. |
| 30 |
# |
| 31 |
# file: word.txt |
| 32 |
# |
| 33 |
# ICU Word Break Rules |
| 34 |
# See Unicode Standard Annex #29. |
| 35 |
# These rules are based on UAX #29 Revision 34 for Unicode Version 12.0 |
| 36 |
# |
| 37 |
# Note: Updates to word.txt will usually need to be merged into |
| 38 |
# word_POSIX.txt and word_fi_sv.txt also. |
| 39 |
|
| 40 |
############################################################################## |
| 41 |
# |
| 42 |
# Character class definitions from TR 29 |
| 43 |
# |
| 44 |
############################################################################## |
| 45 |
|
| 46 |
!!chain; |
| 47 |
!!quoted_literals_only; |
| 48 |
|
| 49 |
|
| 50 |
# |
| 51 |
# Character Class Definitions. |
| 52 |
# |
| 53 |
|
| 54 |
$Han = [:Han:]; |
| 55 |
|
| 56 |
$CR = [\p{Word_Break = CR}]; |
| 57 |
$LF = [\p{Word_Break = LF}]; |
| 58 |
$Newline = [\p{Word_Break = Newline}]; |
| 59 |
$Extend = [\p{Word_Break = Extend}-$Han]; |
| 60 |
$ZWJ = [\p{Word_Break = ZWJ}]; |
| 61 |
$Regional_Indicator = [\p{Word_Break = Regional_Indicator}]; |
| 62 |
$Format = [\p{Word_Break = Format}]; |
| 63 |
$Katakana = [\p{Word_Break = Katakana}]; |
| 64 |
$Hebrew_Letter = [\p{Word_Break = Hebrew_Letter}]; |
| 65 |
$ALetter = [\p{Word_Break = ALetter}]; |
| 66 |
$Single_Quote = [\p{Word_Break = Single_Quote}]; |
| 67 |
$Double_Quote = [\p{Word_Break = Double_Quote}]; |
| 68 |
$MidNumLet = [\p{Word_Break = MidNumLet}]; |
| 69 |
$MidLetter = [\p{Word_Break = MidLetter} - [\: \uFE55 \uFF1A]]; |
| 70 |
$MidNum = [\p{Word_Break = MidNum}]; |
| 71 |
$Numeric = [\p{Word_Break = Numeric}]; |
| 72 |
$ExtendNumLet = [\p{Word_Break = ExtendNumLet}]; |
| 73 |
$WSegSpace = [\p{Word_Break = WSegSpace}]; |
| 74 |
$Extended_Pict = [\p{Extended_Pictographic}]; |
| 75 |
|
| 76 |
$Hiragana = [:Hiragana:]; |
| 77 |
$Ideographic = [\p{Ideographic}]; |
| 78 |
|
| 79 |
|
| 80 |
# Dictionary character set, for triggering language-based break engines. Currently |
| 81 |
# limited to LineBreak=Complex_Context. Note that this set only works in Unicode |
| 82 |
# 5.0 or later as the definition of Complex_Context was corrected to include all |
| 83 |
# characters requiring dictionary break. |
| 84 |
|
| 85 |
$Control = [\p{Grapheme_Cluster_Break = Control}]; |
| 86 |
$HangulSyllable = [\uac00-\ud7a3]; |
| 87 |
$ComplexContext = [:LineBreak = Complex_Context:]; |
| 88 |
$KanaKanji = [$Han $Hiragana $Katakana]; |
| 89 |
$dictionaryCJK = [$KanaKanji $HangulSyllable]; |
| 90 |
$dictionary = [$ComplexContext $dictionaryCJK]; |
| 91 |
|
| 92 |
# TODO: check if handling of katakana in dictionary makes rules incorrect/void |
| 93 |
|
| 94 |
# leave CJK scripts out of ALetterPlus |
| 95 |
$ALetterPlus = [$ALetter-$dictionaryCJK [$ComplexContext-$Extend-$Control]]; |
| 96 |
|
| 97 |
|
| 98 |
## ------------------------------------------------- |
| 99 |
|
| 100 |
# Rule 3 - CR x LF |
| 101 |
# |
| 102 |
$CR $LF; |
| 103 |
|
| 104 |
# Rule 3c Do not break within emoji zwj sequences. |
| 105 |
# ZWJ × \p{Extended_Pictographic}. Precedes WB4, so no intervening Extend chars allowed. |
| 106 |
# |
| 107 |
$ZWJ $Extended_Pict; |
| 108 |
|
| 109 |
# Rule 3d - Keep horizontal whitespace together. |
| 110 |
# |
| 111 |
$WSegSpace $WSegSpace; |
| 112 |
|
| 113 |
# Rule 4 - ignore Format and Extend characters, except when they appear at the beginning |
| 114 |
# of a region of Text. |
| 115 |
|
| 116 |
$ExFm = [$Extend $Format $ZWJ]; |
| 117 |
|
| 118 |
^$ExFm+; # This rule fires only when there are format or extend characters at the |
| 119 |
# start of text, or immediately following another boundary. It groups them, in |
| 120 |
# the event there are more than one. |
| 121 |
|
| 122 |
[^$CR $LF $Newline $ExFm] $ExFm*; # This rule rule attaches trailing format/extends to words, |
| 123 |
# with no special rule status value. |
| 124 |
|
| 125 |
$Numeric $ExFm* {100}; # This group of rules also attach trailing format/extends, but |
| 126 |
$ALetterPlus $ExFm* {200}; # with rule status set based on the word's final base character. |
| 127 |
$HangulSyllable {200}; |
| 128 |
$Hebrew_Letter $ExFm* {200}; |
| 129 |
$Katakana $ExFm* {300}; # note: these status values override those from rule 5 |
| 130 |
$Hiragana $ExFm* {300}; # by virtue of being numerically larger. |
| 131 |
$Ideographic $ExFm* {400}; # |
| 132 |
|
| 133 |
# |
| 134 |
# rule 5 |
| 135 |
# Do not break between most letters. |
| 136 |
# |
| 137 |
($ALetterPlus | $Hebrew_Letter) $ExFm* ($ALetterPlus | $Hebrew_Letter); |
| 138 |
|
| 139 |
# rule 6 and 7 |
| 140 |
($ALetterPlus | $Hebrew_Letter) $ExFm* ($MidLetter | $MidNumLet | $Single_Quote) $ExFm* ($ALetterPlus | $Hebrew_Letter) {200}; |
| 141 |
|
| 142 |
# rule 7a |
| 143 |
$Hebrew_Letter $ExFm* $Single_Quote {200}; |
| 144 |
|
| 145 |
# rule 7b and 7c |
| 146 |
$Hebrew_Letter $ExFm* $Double_Quote $ExFm* $Hebrew_Letter; |
| 147 |
|
| 148 |
# rule 8 |
| 149 |
|
| 150 |
$Numeric $ExFm* $Numeric; |
| 151 |
|
| 152 |
# rule 9 |
| 153 |
|
| 154 |
($ALetterPlus | $Hebrew_Letter) $ExFm* $Numeric; |
| 155 |
|
| 156 |
# rule 10 |
| 157 |
|
| 158 |
$Numeric $ExFm* ($ALetterPlus | $Hebrew_Letter); |
| 159 |
|
| 160 |
# rule 11 and 12 |
| 161 |
|
| 162 |
$Numeric $ExFm* ($MidNum | $MidNumLet | $Single_Quote) $ExFm* $Numeric; |
| 163 |
|
| 164 |
# rule 13 |
| 165 |
# to be consistent with $KanaKanji $KanaKanhi, changed |
| 166 |
# from 300 to 400. |
| 167 |
# See also TestRuleStatus in intltest/rbbiapts.cpp |
| 168 |
$Katakana $ExFm* $Katakana {300}; |
| 169 |
|
| 170 |
# rule 13a/b |
| 171 |
|
| 172 |
$ALetterPlus $ExFm* $ExtendNumLet {200}; # (13a) |
| 173 |
$Hebrew_Letter $ExFm* $ExtendNumLet {200}; # (13a) |
| 174 |
$Numeric $ExFm* $ExtendNumLet {100}; # (13a) |
| 175 |
$Katakana $ExFm* $ExtendNumLet {300}; # (13a) |
| 176 |
$ExtendNumLet $ExFm* $ExtendNumLet {200}; # (13a) |
| 177 |
|
| 178 |
$ExtendNumLet $ExFm* $ALetterPlus {200}; # (13b) |
| 179 |
$ExtendNumLet $ExFm* $Hebrew_Letter {200}; # (13b) |
| 180 |
$ExtendNumLet $ExFm* $Numeric {100}; # (13b) |
| 181 |
$ExtendNumLet $ExFm* $Katakana {300}; # (13b) |
| 182 |
|
| 183 |
# rules 15 - 17 |
| 184 |
# Pairs of Regional Indicators stay together. |
| 185 |
# With incoming rule chaining disabled by ^, this rule will match exactly two of them. |
| 186 |
# No other rule begins with a Regional_Indicator, so chaining cannot extend the match. |
| 187 |
# |
| 188 |
^$Regional_Indicator $ExFm* $Regional_Indicator; |
| 189 |
|
| 190 |
# special handling for CJK characters: chain for later dictionary segmentation |
| 191 |
$HangulSyllable $HangulSyllable {200}; |
| 192 |
|
| 193 |
# Rule 999 |
| 194 |
# Match a single code point if no other rule applies. |
| 195 |
.; |