~ubuntu-branches/ubuntu/vivid/icu4j-4.4/vivid

« back to all changes in this revision

Viewing changes to main/tests/core/src/com/ibm/icu/dev/test/rbbi/BreakIteratorRules_en_US_TEST.java

  • Committer: Bazaar Package Importer
  • Author(s): Niels Thykier
  • Date: 2011-08-02 15:50:33 UTC
  • Revision ID: james.westby@ubuntu.com-20110802155033-itjzsl21y2lqdonn
Tags: upstream-4.4.2
ImportĀ upstreamĀ versionĀ 4.4.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 *******************************************************************************
 
3
 * Copyright (C) 1996-2004, International Business Machines Corporation and    *
 
4
 * others. All Rights Reserved.                                                *
 
5
 *******************************************************************************
 
6
 */
 
7
package com.ibm.icu.dev.test.rbbi;
 
8
 
 
9
import java.util.ListResourceBundle;
 
10
 
 
11
/**
 
12
 * This resource bundle is included for testing and demonstration purposes only.
 
13
 * It applies the dictionary-based algorithm to English text that has had all the
 
14
 * spaces removed.  Once we have good test cases for Thai, we will replace this
 
15
 * with good resource data (and a good dictionary file) for Thai
 
16
 */
 
17
public class BreakIteratorRules_en_US_TEST extends ListResourceBundle {
 
18
    private static final String DATA_NAME = "/com/ibm/icu/dev/data/rbbi/english.dict";
 
19
 
 
20
    // calling code will handle case where dictionary does not exist
 
21
 
 
22
    public Object[][] getContents() {
 
23
        return new Object[][] {
 
24
            // names of classes to instantiate for the different kinds of break
 
25
            // iterator.  Notice we're now using DictionaryBasedBreakIterator
 
26
            // for word and line breaking.
 
27
            {   "BreakIteratorClasses",
 
28
                new String[] {
 
29
                    "RuleBasedBreakIterator",
 
30
                    // character-break iterator class
 
31
                    "DictionaryBasedBreakIterator",
 
32
                    // word-break iterator class
 
33
                    "DictionaryBasedBreakIterator",
 
34
                    // line-break iterator class
 
35
                    "RuleBasedBreakIterator" } // sentence-break iterator class
 
36
            },
 
37
 
 
38
            // These are the same word-breaking rules as are specified in the default
 
39
            // resource, except that the Latin letters, apostrophe, and hyphen are
 
40
            // specified as dictionary characters
 
41
            {
 
42
                "WordBreakRules",
 
43
                // ignore non-spacing marks, enclosing marks, and format characters,
 
44
                // all of which should not influence the algorithm
 
45
                "$_ignore_=[[:Mn:][:Me:][:Cf:]];"
 
46
 
 
47
                // lower and upper case Roman letters, apostrophy and dash are
 
48
                // in the English dictionary
 
49
                +"$_dictionary_=[a-zA-Z\\'\\-];"
 
50
 
 
51
                // Hindi phrase separator, kanji, katakana, hiragana, CJK diacriticals,
 
52
                // other letters, and digits
 
53
                +"$danda=[\u0964\u0965];"
 
54
                    + "$kanji=[\u3005\u4e00-\u9fa5\uf900-\ufa2d];"
 
55
                    + "$kata=[\u3099-\u309c\u30a1-\u30fe];"
 
56
                    + "$hira=[\u3041-\u309e\u30fc];"
 
57
                    + "$let=[[[:L:][:Mc:]]-[$kanji$kata$hira]];"
 
58
                    + "$dgt=[:N:];"
 
59
 
 
60
                // punctuation that can occur in the middle of a word: currently
 
61
                // dashes, apostrophes, and quotation marks
 
62
                +"$mid_word=[[:Pd:]\u00ad\u2027\\\"\\\'];"
 
63
 
 
64
                // punctuation that can occur in the middle of a number: currently
 
65
                // apostrophes, qoutation marks, periods, commas, and the Arabic
 
66
                // decimal point
 
67
                +"$mid_num=[\\\"\\\'\\,\u066b\\.];"
 
68
 
 
69
                // punctuation that can occur at the beginning of a number: currently
 
70
                // the period, the number sign, and all currency symbols except the cents sign
 
71
                +"$pre_num=[[[:Sc:]-[\u00a2]]\\#\\.];"
 
72
 
 
73
                // punctuation that can occur at the end of a number: currently
 
74
                // the percent, per-thousand, per-ten-thousand, and Arabic percent
 
75
                // signs, the cents sign, and the ampersand
 
76
                +"$post_num=[\\%\\&\u00a2\u066a\u2030\u2031];"
 
77
 
 
78
                // line separators: currently LF, FF, PS, and LS
 
79
                +"$ls=[\n\u000c\u2028\u2029];"
 
80
 
 
81
                // whitespace: all space separators and the tab character
 
82
                +"$ws=[[:Zs:]\t];"
 
83
 
 
84
                // a word is a sequence of letters that may contain internal
 
85
                // punctuation, as long as it begins and ends with a letter and
 
86
                // never contains two punctuation marks in a row
 
87
                +"$word=($let+($mid_word$let+)*$danda?);"
 
88
 
 
89
                // a number is a sequence of digits that may contain internal
 
90
                // punctuation, as long as it begins and ends with a digit and
 
91
                // never contains two punctuation marks in a row.
 
92
                +"$number=($dgt+($mid_num$dgt+)*);"
 
93
 
 
94
                // break after every character, with the following exceptions
 
95
                // (this will cause punctuation marks that aren't considered
 
96
                // part of words or numbers to be treated as words unto themselves)
 
97
                +".;"
 
98
 
 
99
                // keep together any sequence of contiguous words and numbers
 
100
                // (including just one of either), plus an optional trailing
 
101
                // number-suffix character
 
102
                +"$word?($number$word)*($number$post_num?)?;"
 
103
 
 
104
                // keep together and sequence of contiguous words and numbers
 
105
                // that starts with a number-prefix character and a number,
 
106
                // and may end with a number-suffix character
 
107
                +"$pre_num($number$word)*($number$post_num?)?;"
 
108
 
 
109
                // keep together runs of whitespace (optionally with a single trailing
 
110
                // line separator or CRLF sequence)
 
111
                +"$ws*\r?$ls?;"
 
112
 
 
113
                // keep together runs of Katakana
 
114
                +"$kata*;"
 
115
 
 
116
                // keep together runs of Hiragana
 
117
                +"$hira*;"
 
118
 
 
119
                // keep together runs of Kanji
 
120
                +"$kanji*;" },
 
121
 
 
122
            // These are the same line-breaking rules as are specified in the default
 
123
            // resource, except that the Latin letters, apostrophe, and hyphen are
 
124
            // specified as dictionary characters
 
125
            {   "LineBreakRules",
 
126
                // ignore non-spacing marks, enclosing marks, and format characters
 
127
                "$_ignore_=[[:Mn:][:Me:][:Cf:]];"
 
128
 
 
129
                // lower and upper case Roman letters, apostrophy and dash
 
130
                // are in the English dictionary
 
131
                +"$_dictionary_=[a-zA-Z\\'\\-];"
 
132
 
 
133
                // Hindi phrase separators
 
134
                +"$danda=[\u0964\u0965];"
 
135
 
 
136
                // characters that always cause a break: ETX, tab, LF, FF, LS, and PS
 
137
                +"$break=[\u0003\t\n\f\u2028\u2029];"
 
138
 
 
139
                // characters that always prevent a break: the non-breaking space
 
140
                // and similar characters
 
141
                +"$nbsp=[\u00a0\u2007\u2011\ufeff];"
 
142
 
 
143
                // whitespace: space separators and control characters, except for
 
144
                // CR and the other characters mentioned above
 
145
                +"$space=[[[:Zs:][:Cc:]]-[$nbsp$break\r]];"
 
146
 
 
147
                // dashes: dash punctuation and the discretionary hyphen, except for
 
148
                // non-breaking hyphens
 
149
                +"$dash=[[[:Pd:]\u00ad]-[$nbsp]];"
 
150
 
 
151
                // characters that stick to a word if they precede it: currency symbols
 
152
                // (except the cents sign) and starting punctuation
 
153
                +"$pre_word=[[[:Sc:]-[\u00a2]][:Ps:]\\\"\\\'];"
 
154
 
 
155
                // characters that stick to a word if they follow it: ending punctuation,
 
156
                // other punctuation that usually occurs at the end of a sentence,
 
157
                // small Kana characters, some CJK diacritics, etc.
 
158
                +"$post_word=[[:Pe:]\\!\\\"\\\'\\%\\.\\,\\:\\;\\?\u00a2\u00b0\u066a\u2030-\u2034"
 
159
                    + "\u2103\u2105\u2109\u3001\u3002\u3005\u3041\u3043\u3045\u3047\u3049\u3063"
 
160
                    + "\u3083\u3085\u3087\u308e\u3099-\u309e\u30a1\u30a3\u30a5\u30a7\u30a9"
 
161
                    + "\u30c3\u30e3\u30e5\u30e7\u30ee\u30f5\u30f6\u30fc-\u30fe\uff01\uff0c"
 
162
                    + "\uff0e\uff1f];"
 
163
 
 
164
                // Kanji: actually includes both Kanji and Kana, except for small Kana and
 
165
                // CJK diacritics
 
166
                +"$kanji=[[\u4e00-\u9fa5\uf900-\ufa2d\u3041-\u3094\u30a1-\u30fa]-[$post_word$_ignore_]];"
 
167
 
 
168
                // digits
 
169
                +"$digit=[[:Nd:][:No:]];"
 
170
 
 
171
                // punctuation that can occur in the middle of a number: periods and commas
 
172
                +"$mid_num=[\\.\\,];"
 
173
 
 
174
                // everything not mentioned above, plus the quote marks (which are both
 
175
                // <pre-word>, <post-word>, and <char>)
 
176
                +"$char=[^$break$space$dash$kanji$nbsp$_ignore_$pre_word$post_word$mid_num$danda\r\\\"\\\'];"
 
177
 
 
178
                // a "number" is a run of prefix characters and dashes, followed by one or
 
179
                // more digits with isolated number-punctuation characters interspersed
 
180
                +"$number=([$pre_word$dash]*$digit+($mid_num$digit+)*);"
 
181
 
 
182
                // the basic core of a word can be either a "number" as defined above, a single
 
183
                // "Kanji" character, or a run of any number of not-explicitly-mentioned
 
184
                // characters (this includes Latin letters)
 
185
                +"$word_core=([$pre_word$char]*|$kanji|$number);"
 
186
 
 
187
                // a word may end with an optional suffix that be either a run of one or
 
188
                // more dashes or a run of word-suffix characters, followed by an optional
 
189
                // run of whitespace
 
190
                +"$word_suffix=(($dash+|$post_word*)$space*);"
 
191
 
 
192
                // a word, thus, is an optional run of word-prefix characters, followed by
 
193
                // a word core and a word suffix (the syntax of <word-core> and <word-suffix>
 
194
                // actually allows either of them to match the empty string, putting a break
 
195
                // between things like ")(" or "aaa(aaa"
 
196
                +"$word=($pre_word*$word_core$word_suffix);"
 
197
 
 
198
                // finally, the rule that does the work: Keep together any run of words that
 
199
                // are joined by runs of one of more non-spacing mark.  Also keep a trailing
 
200
                // line-break character or CRLF combination with the word.  (line separators
 
201
                // "win" over nbsp's)
 
202
                +"$word($nbsp+$word)*\r?$break?;" },
 
203
 
 
204
            // these two resources specify the pathnames of the dictionary files to
 
205
            // use for word breaking and line breaking.  Both currently refer to
 
206
            // a file called english.dict placed in com.ibm.icu.impl.data
 
207
            // somewhere in the class path.  It's important to note that
 
208
            // english.dict was created for testing purposes only, and doesn't
 
209
            // come anywhere close to being an exhaustive dictionary of English
 
210
            // words (basically, it contains all the words in the Declaration of
 
211
            // Independence, and the Revised Standard Version of the book of Genesis,
 
212
            // plus a few other words thrown in to show more interesting cases).
 
213
            // { "WordBreakDictionary", "com\\ibm\\text\\resources\\english.dict" },
 
214
            // { "LineBreakDictionary", "com\\ibm\\text\\resources\\english.dict" }
 
215
            {   "WordBreakDictionary", DATA_NAME }, 
 
216
            {   "LineBreakDictionary", DATA_NAME }
 
217
        };
 
218
    }
 
219
}