| 1 |
<!-- |
| 2 |
Copyright (C) 2016 and later: Unicode, Inc. and others. |
| 3 |
License & terms of use: http://www.unicode.org/copyright.html |
| 4 |
|
| 5 |
Copyright (c) 2015-2016, International Business Machines Corporation and others. All Rights Reserved. |
| 6 |
--> |
| 7 |
|
| 8 |
This directory contains the break iterator reference rule files used by intltest rbbi/RBBIMonkeyTest/testMonkey. |
| 9 |
=========================================== |
| 10 |
|
| 11 |
The rules in this directory track the boundary rules from Unicode UAX 14 and 29. They are interpreted |
| 12 |
to provide an expected set of boundary positions to compare with the results from ICU break iteration. |
| 13 |
|
| 14 |
ICU4J also includes copies of the test reference rules, located in the directory |
| 15 |
main/core/src/test/resources/com/ibm/icu/dev/test/rbbi/break_rules/ |
| 16 |
The copies should be kept synchronized; there should be no differences. |
| 17 |
|
| 18 |
Each set of reference break rules lives in a separate file. |
| 19 |
The list of rule files to run by default is hard coded into the test code, in rbbimonkeytest.cpp. |
| 20 |
|
| 21 |
Each test file includes |
| 22 |
- The type of ICU break iterator to create (word, line, sentence, etc.) |
| 23 |
- The locale to use |
| 24 |
- Character Class definitions |
| 25 |
- Rule definitions |
| 26 |
|
| 27 |
To Do |
| 28 |
- Extend the syntax to support rule tailoring. |
| 29 |
|
| 30 |
|
| 31 |
**character class definition** |
| 32 |
|
| 33 |
name = set_regular_expression; |
| 34 |
|
| 35 |
*caution* When referenced, these definitions are textually substituted into the overall rule. |
| 36 |
To avoid unexpected behavior, include [brackets] around the full definition |
| 37 |
|
| 38 |
letter_number = [:Letter:][:Number:]; |
| 39 |
|
| 40 |
Will compile, but will produce unexpected results. |
| 41 |
|
| 42 |
letter_number = [[:Letter:][:Number:]]; |
| 43 |
|
| 44 |
is safe. The issue is similar to the problems that can occur with the C preprocessor |
| 45 |
and the use of parentheses around macro paramteters. |
| 46 |
|
| 47 |
**rule definition** |
| 48 |
|
| 49 |
rule_regular_expression; |
| 50 |
|
| 51 |
**name** |
| 52 |
|
| 53 |
[A-Za-z_][A-Za-z0-9_]* |
| 54 |
|
| 55 |
**set_regular_expression** |
| 56 |
|
| 57 |
The intersection of an ICU regular expression [set] expression and a UnicodeSet pattern |
| 58 |
(They are mostly the same). May include previously defined set names, which are logically |
| 59 |
expanded in-place. |
| 60 |
|
| 61 |
**rule_regular_expression** |
| 62 |
|
| 63 |
An ICU Regular Expression. |
| 64 |
May include set names, which are logically expanded in-place. |
| 65 |
May include a '÷', which defines a boundary position. |
| 66 |
|
| 67 |
Application of the rules: |
| 68 |
|
| 69 |
Matching begins at the start of text, or after a previously identified boundary. |
| 70 |
The pseudo-code below finds the next boundary. |
| 71 |
|
| 72 |
while position < end of text |
| 73 |
for each rule |
| 74 |
if the text at position matches this rule |
| 75 |
if the rule has a '÷' |
| 76 |
Boundary is found. |
| 77 |
return the position of the '÷' within the match. |
| 78 |
else |
| 79 |
position = last character of the rule match. |
| 80 |
break from the inner rule loop, continue the outer loop. |
| 81 |
|
| 82 |
This differs from the Unicode UAX algorithm in that each position in the text is |
| 83 |
not tested separately. Instead, when a rule match is found, rule application restarts with the last |
| 84 |
character of the preceding rule match. ICU's break rules also operate this way. |
| 85 |
|
| 86 |
Expressing rules this way simplifies UAX rules that have leading or trailing context; it |
| 87 |
is no longer necessary to write expressions that match the context starting from |
| 88 |
any position within it. |
| 89 |
|
| 90 |
This rule form differs from ICU rules in that the rules are applied sequentially, as they |
| 91 |
are with the Unicode UAX rules. With the main ICU break rules, all are applied in parallel. |
| 92 |
|
| 93 |
**Word Dictionaries** |
| 94 |
|
| 95 |
|
| 96 |
The monkey test does not test dictionary based breaking. The set named 'dictionary' is special, |
| 97 |
as it is in the main ICU rules. For the monkey test, no characters from the dictionary set are |
| 98 |
included in the randomly-generated test data. |
| 99 |
|
| 100 |
|