1
package org.apache.lucene.analysis.icu.segmentation;
4
* Licensed to the Apache Software Foundation (ASF) under one or more
5
* contributor license agreements. See the NOTICE file distributed with
6
* this work for additional information regarding copyright ownership.
7
* The ASF licenses this file to You under the Apache License, Version 2.0
8
* (the "License"); you may not use this file except in compliance with
9
* the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing, software
14
* distributed under the License is distributed on an "AS IS" BASIS,
15
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16
* See the License for the specific language governing permissions and
17
* limitations under the License.
20
import java.io.InputStream;
22
import org.apache.lucene.util.LuceneTestCase;
24
import com.ibm.icu.lang.UCharacter;
25
import com.ibm.icu.text.BreakIterator;
26
import com.ibm.icu.text.RuleBasedBreakIterator;
27
import com.ibm.icu.text.UTF16;
30
* Tests LaoBreakIterator and its RBBI rules
32
public class TestLaoBreakIterator extends LuceneTestCase {
33
private BreakIterator wordIterator;
36
public void setUp() throws Exception {
38
InputStream is = getClass().getResourceAsStream("Lao.brk");
39
wordIterator = new LaoBreakIterator(RuleBasedBreakIterator.getInstanceFromCompiledRules(is));
43
private void assertBreaksTo(BreakIterator iterator, String sourceText, String tokens[]) {
44
char text[] = sourceText.toCharArray();
45
CharArrayIterator ci = new CharArrayIterator();
46
ci.setText(text, 0, text.length);
49
for (int i = 0; i < tokens.length; i++) {
52
start = iterator.current();
53
end = iterator.next();
54
} while (end != BreakIterator.DONE && !isWord(text, start, end));
55
assertTrue(start != BreakIterator.DONE);
56
assertTrue(end != BreakIterator.DONE);
57
assertEquals(tokens[i], new String(text, start, end - start));
60
assertTrue(iterator.next() == BreakIterator.DONE);
63
protected boolean isWord(char text[], int start, int end) {
65
for (int i = start; i < end; i += UTF16.getCharCount(codepoint)) {
66
codepoint = UTF16.charAt(text, 0, end, start);
68
if (UCharacter.isLetterOrDigit(codepoint))
75
public void testBasicUsage() throws Exception {
76
assertBreaksTo(wordIterator, "ກວ່າດອກ", new String[] { "ກວ່າ", "ດອກ" });
77
assertBreaksTo(wordIterator, "ຜູ້ເຂົ້າ", new String[] { "ຜູ້", "ເຂົ້າ" });
78
assertBreaksTo(wordIterator, "", new String[] {});
79
assertBreaksTo(wordIterator, "ສະບາຍດີ", new String[] { "ສະ", "ບາຍ", "ດີ" });
82
public void testNumerics() throws Exception {
83
assertBreaksTo(wordIterator, "໐໑໒໓", new String[] { "໐໑໒໓" });
84
assertBreaksTo(wordIterator, "໐໑໒໓.໕໖", new String[] { "໐໑໒໓.໕໖" });
87
public void testTextAndNumerics() throws Exception {
88
assertBreaksTo(wordIterator, "ກວ່າດອກ໐໑໒໓", new String[] { "ກວ່າ", "ດອກ", "໐໑໒໓" });