本文整理汇总了Java中com.ibm.icu.text.Transliterator类的典型用法代码示例。如果您正苦于以下问题:Java Transliterator类的具体用法?Java Transliterator怎么用?Java Transliterator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Transliterator类属于com.ibm.icu.text包,在下文中一共展示了Transliterator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: transliterate
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
public static String transliterate(String text, String transliterationCode) {
if (Str.isEmpty(text))
return text;
if (transliterationCode == null) {
transliterationCode = DEFAULT_TRANSLITERATION_CODE;
}
String transliteratedText = text.replace(ae, transliterateReplaceChars.get(ae))
.replace(oe, transliterateReplaceChars.get(oe)).replace(ue, transliterateReplaceChars.get(ue))
.replace(Ae, transliterateReplaceChars.get(Ae)).replace(Oe, transliterateReplaceChars.get(Oe))
.replace(Ue, transliterateReplaceChars.get(Ue)).replace(ss, transliterateReplaceChars.get(ss))
.replace(Str.AT, transliterateReplaceChars.get(Str.AT))
.replace(Str.AMPERSAND, transliterateReplaceChars.get(Str.AMPERSAND));
Transliterator t = transliteratorCache.get(transliterationCode);
if (t == null) {
t = Transliterator.getInstance(transliterationCode);
transliteratorCache.put(transliterationCode, t);
}
transliteratedText = t.transform(transliteratedText);
return Normalizer.normalize(transliteratedText, Normalizer.Form.NFD);
}
示例2: Icu4jPageOutput
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
public Icu4jPageOutput(TaskSource taskSource, Schema inputSchema, Schema outputSchema, PageOutput output) {
this.task = taskSource.loadTask(PluginTask.class);
this.keyNameColumns = Lists.newArrayList();
this.transliteratorsList = Lists.newArrayList();
this.inputSchema = inputSchema;
this.outputSchema = outputSchema;
for (String keyName : task.getKeyNames()) {
keyNameColumns.add(inputSchema.lookupColumn(keyName));
}
for (Map<String, String> setting : task.getSettings()) {
List<Transliterator> tokenizers = Lists.newArrayList();
for (String convertType : setting.get("transliterators").split(",")) {
Transliterator transliterator = Transliterator.getInstance(convertType);
tokenizers.add(transliterator);
}
transliteratorsList.add(tokenizers);
}
reader = new PageReader(inputSchema);
builder = new PageBuilder(Exec.getBufferAllocator(), outputSchema, output);
}
示例3: testEnglishSort
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
public void testEnglishSort() {
final Transliterator normalizer = Transliterator.createFromRules("", Language.en.getDefaultNormalizerRules(), Transliterator.FORWARD);
final List<String> words = Arrays.asList(
"pre-print",
"preppie",
"preppy",
"preprocess");
final List<String> sorted = new ArrayList<String>(words);
final NormalizeComparator comparator = new NormalizeComparator(normalizer, Language.en.getCollator(), 7);
Collections.sort(sorted, comparator);
for (int i = 0; i < words.size(); ++i) {
if (i > 0) {
assertTrue(comparator.compare(words.get(i-1), words.get(i)) < 0);
}
System.out.println(words.get(i) + "\t" + sorted.get(i));
assertEquals(words.get(i), sorted.get(i));
}
assertTrue(comparator.compare("pre-print", "preppy") < 0);
}
示例4: init
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
@Override
public void init(Map<String,String> args) {
super.init(args);
String id = args.get("id");
if (id == null) {
throw new IllegalArgumentException("id is required.");
}
int dir;
String direction = args.get("direction");
if (direction == null || direction.equalsIgnoreCase("forward"))
dir = Transliterator.FORWARD;
else if (direction.equalsIgnoreCase("reverse"))
dir = Transliterator.REVERSE;
else
throw new IllegalArgumentException("invalid direction: " + direction);
transliterator = Transliterator.getInstance(id, dir);
}
示例5: getJapaneseTransliterator
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
private static Transliterator getJapaneseTransliterator() {
synchronized(JapaneseContactUtils.class) {
if (!mInitializedTransliterator) {
mInitializedTransliterator = true;
Transliterator t = null;
try {
t = Transliterator.getInstance("Hiragana-Latin; Katakana-Latin;"
+ " Latin-Ascii");
} catch (RuntimeException e) {
Log.w(TAG, "Hiragana/Katakana-Latin transliterator data"
+ " is missing");
}
mJapaneseTransliterator = t;
}
return mJapaneseTransliterator;
}
}
示例6: IcuTransformTokenFilterFactory
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
public IcuTransformTokenFilterFactory(IndexSettings indexSettings, Environment environment, String name, Settings settings) {
super(indexSettings, name, settings);
this.id = settings.get("id", "Null");
String s = settings.get("dir", "forward");
this.dir = "forward".equals(s) ? Transliterator.FORWARD : Transliterator.REVERSE;
this.transliterator = Transliterator.getInstance(id, dir);
}
示例7: formatInput
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
/**
* For debugging purposes; format the given text in the form
* aaa{bbb|ccc|ddd}eee, where the {} indicate the context start
* and limit, and the || indicate the start and limit.
*/
public static String formatInput(ReplaceableString input,
Transliterator.Position pos) {
StringBuffer appendTo = new StringBuffer();
formatInput(appendTo, input, pos);
return com.ibm.icu.impl.Utility.escape(appendTo.toString());
}
示例8: IcuNormalizer
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
public IcuNormalizer(String translitId) {
try {
transliterator = Transliterator.getInstance(translitId);
} catch (IllegalArgumentException ex) {
throw new MisconfigurationException("ILLEGAL_TRANSILIT_ID", translitId, ex);
}
}
示例9: transliterate
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
@Nullable
private String transliterate(Transliterator transliterator, @Nullable String text) {
if (text == null) {
return null;
}
String result = transliterator.transliterate(text);
if (result == null || result.isEmpty()) {
return null;
}
return result;
}
示例10: IcuTransformTokenFilterFactory
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
@Inject
public IcuTransformTokenFilterFactory(Index index,
@IndexSettings Settings indexSettings,
@Assisted String name,
@Assisted Settings settings) {
super(index, indexSettings, name, settings);
String id = settings.get("id", "Null");
String s = settings.get("dir", "forward");
int dir = "forward".equals(s) ? Transliterator.FORWARD : Transliterator.REVERSE;
this.transliterator = Transliterator.getInstance(id, dir);
}
示例11: getPunctuationTransLiterator
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
public static Transliterator getPunctuationTransLiterator()
{
Transliterator tl = (Transliterator) transHolder.get();
if (tl == null)
{
tl = Transliterator.getInstance("Any-Latin; Lower; NFD; [[:P:]] Remove; NFC;");
transHolder.set(tl);
}
return tl;
}
示例12: convert
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
/**
* @param column
* @param suffix
* @param type
* @return
*/
private String convert(String string, String suffix, String type, List<Transliterator> transliterators) {
for (Transliterator transliterator : transliterators) {
string = transliterator.transliterate(string);
}
if ("upper".equals(type)) {
string = string.toUpperCase();
} else if ("lower".equals(type)) {
string = string.toLowerCase();
}
return string;
}
示例13: icu4jNormalize
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
public static String icu4jNormalize(final String input) {
if (input == null) {
return input;
}
Transliterator normalizer = Transliterator.getInstance("NFD; [:Nonspacing Mark:] Remove; NFC;");
String temp = normalizer.transliterate(input);
return temp;
}
示例14: ICUTransformFilter
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
/**
* Create a new ICUTransformFilter that transforms text on the given stream.
*
* @param input {@link TokenStream} to filter.
* @param transform Transliterator to transform the text.
*/
public ICUTransformFilter(TokenStream input, Transliterator transform) {
super(input);
this.transform = transform;
/*
* This is cheating, but speeds things up a lot.
* If we wanted to use pkg-private APIs we could probably do better.
*/
if (transform.getFilter() == null && transform instanceof com.ibm.icu.text.RuleBasedTransliterator) {
final UnicodeSet sourceSet = transform.getSourceSet();
if (sourceSet != null && !sourceSet.isEmpty())
transform.setFilter(sourceSet);
}
}
示例15: ICUTransformFilterFactory
import com.ibm.icu.text.Transliterator; //导入依赖的package包/类
/** Creates a new ICUTransformFilterFactory */
public ICUTransformFilterFactory(Map<String,String> args) {
super(args);
String id = require(args, "id");
String direction = get(args, "direction", Arrays.asList("forward", "reverse"), "forward", false);
int dir = "forward".equals(direction) ? Transliterator.FORWARD : Transliterator.REVERSE;
transliterator = Transliterator.getInstance(id, dir);
if (!args.isEmpty()) {
throw new IllegalArgumentException("Unknown parameters: " + args);
}
}