Fixed test failure. ClassCastException because the dictionary
name wasn't a URL as expected by BreakIterator X-SVN-Rev: 934
This commit is contained in:
parent
94cca6161d
commit
b4c2715073
@ -13,6 +13,7 @@
|
||||
package com.ibm.text.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* This resource bundle is included for testing and demonstration purposes only.
|
||||
@ -22,10 +23,14 @@ import java.util.ListResourceBundle;
|
||||
*/
|
||||
public class BreakIteratorRules_en_US_TEST extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
URL url = getClass().getResource("english.dict");
|
||||
|
||||
static final Object[][] contents = {
|
||||
// if dictionary wasn't found, then this resource bundle doesn't have
|
||||
// much to contribute...
|
||||
if (url == null) {
|
||||
return new Object[0][0];
|
||||
}
|
||||
return new Object[][] {
|
||||
// names of classes to instantiate for the different kinds of break
|
||||
// iterator. Notice we're now using DictionaryBasedBreakIterator
|
||||
// for word and line breaking.
|
||||
@ -40,29 +45,29 @@ public class BreakIteratorRules_en_US_TEST extends ListResourceBundle {
|
||||
// resource, except that the Latin letters, apostrophe, and hyphen are
|
||||
// specified as dictionary characters
|
||||
{ "WordBreakRules",
|
||||
"<ignore>=[:Mn::Me::Cf:];"
|
||||
+ "<dictionary>=[a-zA-z\\'\\-];"
|
||||
+ "<kanji>=[\u3005\u4e00-\u9fa5\uf900-\ufa2d];"
|
||||
+ "<kata>=[\u30a1-\u30fa];"
|
||||
+ "<hira>=[\u3041-\u3094];"
|
||||
+ "<cjk-diacrit>=[\u3099-\u309c];"
|
||||
+ "<let>=[:L:^[<kanji><kata><hira><cjk-diacrit><dictionary>]];"
|
||||
+ "<dgt>=[:N:];"
|
||||
+ "<mid-word>=[:Pd:\u00ad\u2027\\\"\\\'\\.];"
|
||||
+ "<mid-num>=[\\\"\\\'\\,\u066b\\.];"
|
||||
+ "<pre-num>=[:Sc:\\#\\.^\u00a2];"
|
||||
+ "<post-num>=[\\%\\&\u00a2\u066a\u2030\u2031];"
|
||||
+ "<ls>=[\n\u000c\u2028\u2029];"
|
||||
+ "<ws>=[:Zs:\t];"
|
||||
+ "<word>=(<let><let>*(<mid-word><let><let>*)*|[a-zA-Z][a-z\\'\\-]*);"
|
||||
+ "<number>=(<dgt><dgt>*(<mid-num><dgt><dgt>*)*);"
|
||||
"$ignore=[[:Mn:][:Me:][:Cf:]];"
|
||||
+ "dictionary=[a-zA-z\\'\\-];"
|
||||
+ "kanji=[\u3005\u4e00-\u9fa5\uf900-\ufa2d];"
|
||||
+ "kata=[\u30a1-\u30fa];"
|
||||
+ "hira=[\u3041-\u3094];"
|
||||
+ "cjk-diacrit=[\u3099-\u309c];"
|
||||
+ "let=[[:L:]^[{kanji}{kata}{hira}{cjk-diacrit}{dictionary}]];"
|
||||
+ "dgt=[[:N:]];"
|
||||
+ "mid-word=[[:Pd:]\u00ad\u2027\\\"\\\'\\.];"
|
||||
+ "mid-num=[\\\"\\\'\\,\u066b\\.];"
|
||||
+ "pre-num=[[:Sc:]\\#\\.^\u00a2];"
|
||||
+ "post-num=[\\%\\&\u00a2\u066a\u2030\u2031];"
|
||||
+ "ls=[\n\u000c\u2028\u2029];"
|
||||
+ "ws=[[:Zs:]\t];"
|
||||
+ "word=({let}{let}*({mid-word}{let}{let}*)*|[a-zA-Z][a-z\\'\\-]*);"
|
||||
+ "number=({dgt}{dgt}*({mid-num}{dgt}{dgt}*)*);"
|
||||
+ ".;"
|
||||
+ "{<word>}(<number><word>)*{<number>{<post-num>}};"
|
||||
+ "<pre-num>(<number><word>)*{<number>{<post-num>}};"
|
||||
+ "<ws>*{\r}{<ls>};"
|
||||
+ "[<kata><cjk-diacrit>]*;"
|
||||
+ "[<hira><cjk-diacrit>]*;"
|
||||
+ "<kanji>*;" },
|
||||
+ "{{word}}({number}{word})*{{number}{{post-num}}};"
|
||||
+ "{pre-num}({number}{word})*{{number}{{post-num}}};"
|
||||
+ "{ws}*{\r}{{ls}};"
|
||||
+ "[{kata}{cjk-diacrit}]*;"
|
||||
+ "[{hira}{cjk-diacrit}]*;"
|
||||
+ "{kanji}*;" },
|
||||
|
||||
// These are the same line-breaking rules as are specified in the default
|
||||
// resource, except that the Latin letters, apostrophe, and hyphen are
|
||||
@ -99,7 +104,10 @@ public class BreakIteratorRules_en_US_TEST extends ListResourceBundle {
|
||||
// words (basically, it contains all the words in the Declaration of
|
||||
// Independence, and the Revised Standard Version of the book of Genesis,
|
||||
// plus a few other words thrown in to show more interesting cases).
|
||||
{ "WordBreakDictionary", "com\\ibm\\text\\resources\\english.dict" },
|
||||
{ "LineBreakDictionary", "com\\ibm\\text\\resources\\english.dict" }
|
||||
// { "WordBreakDictionary", "com\\ibm\\text\\resources\\english.dict" },
|
||||
// { "LineBreakDictionary", "com\\ibm\\text\\resources\\english.dict" }
|
||||
{ "WordBreakDictionary", url },
|
||||
{ "LineBreakDictionary", url }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -107,19 +107,19 @@ public class SimpleBITest extends TestFmwk{
|
||||
public void testWordBreak() throws Exception {
|
||||
BreakIterator wordBreak = BreakIterator.getWordInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(wordBreak);
|
||||
errln(String.valueOf(breaks));
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
|
||||
public void testLineBreak() throws Exception {
|
||||
BreakIterator lineBreak = BreakIterator.getLineInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(lineBreak);
|
||||
errln(String.valueOf(breaks));
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
|
||||
public void testSentenceBreak() throws Exception {
|
||||
BreakIterator sentenceBreak = BreakIterator.getSentenceInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(sentenceBreak);
|
||||
errln(String.valueOf(breaks));
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
|
||||
private int doTest(BreakIterator bi) {
|
||||
|
@ -13,6 +13,7 @@
|
||||
package com.ibm.text.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
import java.net.URL;
|
||||
|
||||
/**
|
||||
* This resource bundle is included for testing and demonstration purposes only.
|
||||
@ -22,10 +23,14 @@ import java.util.ListResourceBundle;
|
||||
*/
|
||||
public class BreakIteratorRules_en_US_TEST extends ListResourceBundle {
|
||||
public Object[][] getContents() {
|
||||
return contents;
|
||||
}
|
||||
URL url = getClass().getResource("english.dict");
|
||||
|
||||
static final Object[][] contents = {
|
||||
// if dictionary wasn't found, then this resource bundle doesn't have
|
||||
// much to contribute...
|
||||
if (url == null) {
|
||||
return new Object[0][0];
|
||||
}
|
||||
return new Object[][] {
|
||||
// names of classes to instantiate for the different kinds of break
|
||||
// iterator. Notice we're now using DictionaryBasedBreakIterator
|
||||
// for word and line breaking.
|
||||
@ -40,29 +45,29 @@ public class BreakIteratorRules_en_US_TEST extends ListResourceBundle {
|
||||
// resource, except that the Latin letters, apostrophe, and hyphen are
|
||||
// specified as dictionary characters
|
||||
{ "WordBreakRules",
|
||||
"<ignore>=[:Mn::Me::Cf:];"
|
||||
+ "<dictionary>=[a-zA-z\\'\\-];"
|
||||
+ "<kanji>=[\u3005\u4e00-\u9fa5\uf900-\ufa2d];"
|
||||
+ "<kata>=[\u30a1-\u30fa];"
|
||||
+ "<hira>=[\u3041-\u3094];"
|
||||
+ "<cjk-diacrit>=[\u3099-\u309c];"
|
||||
+ "<let>=[:L:^[<kanji><kata><hira><cjk-diacrit><dictionary>]];"
|
||||
+ "<dgt>=[:N:];"
|
||||
+ "<mid-word>=[:Pd:\u00ad\u2027\\\"\\\'\\.];"
|
||||
+ "<mid-num>=[\\\"\\\'\\,\u066b\\.];"
|
||||
+ "<pre-num>=[:Sc:\\#\\.^\u00a2];"
|
||||
+ "<post-num>=[\\%\\&\u00a2\u066a\u2030\u2031];"
|
||||
+ "<ls>=[\n\u000c\u2028\u2029];"
|
||||
+ "<ws>=[:Zs:\t];"
|
||||
+ "<word>=(<let><let>*(<mid-word><let><let>*)*|[a-zA-Z][a-z\\'\\-]*);"
|
||||
+ "<number>=(<dgt><dgt>*(<mid-num><dgt><dgt>*)*);"
|
||||
"$ignore=[[:Mn:][:Me:][:Cf:]];"
|
||||
+ "dictionary=[a-zA-z\\'\\-];"
|
||||
+ "kanji=[\u3005\u4e00-\u9fa5\uf900-\ufa2d];"
|
||||
+ "kata=[\u30a1-\u30fa];"
|
||||
+ "hira=[\u3041-\u3094];"
|
||||
+ "cjk-diacrit=[\u3099-\u309c];"
|
||||
+ "let=[[:L:]^[{kanji}{kata}{hira}{cjk-diacrit}{dictionary}]];"
|
||||
+ "dgt=[[:N:]];"
|
||||
+ "mid-word=[[:Pd:]\u00ad\u2027\\\"\\\'\\.];"
|
||||
+ "mid-num=[\\\"\\\'\\,\u066b\\.];"
|
||||
+ "pre-num=[[:Sc:]\\#\\.^\u00a2];"
|
||||
+ "post-num=[\\%\\&\u00a2\u066a\u2030\u2031];"
|
||||
+ "ls=[\n\u000c\u2028\u2029];"
|
||||
+ "ws=[[:Zs:]\t];"
|
||||
+ "word=({let}{let}*({mid-word}{let}{let}*)*|[a-zA-Z][a-z\\'\\-]*);"
|
||||
+ "number=({dgt}{dgt}*({mid-num}{dgt}{dgt}*)*);"
|
||||
+ ".;"
|
||||
+ "{<word>}(<number><word>)*{<number>{<post-num>}};"
|
||||
+ "<pre-num>(<number><word>)*{<number>{<post-num>}};"
|
||||
+ "<ws>*{\r}{<ls>};"
|
||||
+ "[<kata><cjk-diacrit>]*;"
|
||||
+ "[<hira><cjk-diacrit>]*;"
|
||||
+ "<kanji>*;" },
|
||||
+ "{{word}}({number}{word})*{{number}{{post-num}}};"
|
||||
+ "{pre-num}({number}{word})*{{number}{{post-num}}};"
|
||||
+ "{ws}*{\r}{{ls}};"
|
||||
+ "[{kata}{cjk-diacrit}]*;"
|
||||
+ "[{hira}{cjk-diacrit}]*;"
|
||||
+ "{kanji}*;" },
|
||||
|
||||
// These are the same line-breaking rules as are specified in the default
|
||||
// resource, except that the Latin letters, apostrophe, and hyphen are
|
||||
@ -99,7 +104,10 @@ public class BreakIteratorRules_en_US_TEST extends ListResourceBundle {
|
||||
// words (basically, it contains all the words in the Declaration of
|
||||
// Independence, and the Revised Standard Version of the book of Genesis,
|
||||
// plus a few other words thrown in to show more interesting cases).
|
||||
{ "WordBreakDictionary", "com\\ibm\\text\\resources\\english.dict" },
|
||||
{ "LineBreakDictionary", "com\\ibm\\text\\resources\\english.dict" }
|
||||
// { "WordBreakDictionary", "com\\ibm\\text\\resources\\english.dict" },
|
||||
// { "LineBreakDictionary", "com\\ibm\\text\\resources\\english.dict" }
|
||||
{ "WordBreakDictionary", url },
|
||||
{ "LineBreakDictionary", url }
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -107,19 +107,19 @@ public class SimpleBITest extends TestFmwk{
|
||||
public void testWordBreak() throws Exception {
|
||||
BreakIterator wordBreak = BreakIterator.getWordInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(wordBreak);
|
||||
errln(String.valueOf(breaks));
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
|
||||
public void testLineBreak() throws Exception {
|
||||
BreakIterator lineBreak = BreakIterator.getLineInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(lineBreak);
|
||||
errln(String.valueOf(breaks));
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
|
||||
public void testSentenceBreak() throws Exception {
|
||||
BreakIterator sentenceBreak = BreakIterator.getSentenceInstance(new Locale("en", "US", "TEST"));
|
||||
int breaks = doTest(sentenceBreak);
|
||||
errln(String.valueOf(breaks));
|
||||
logln(String.valueOf(breaks));
|
||||
}
|
||||
|
||||
private int doTest(BreakIterator bi) {
|
||||
|
Loading…
Reference in New Issue
Block a user