当前位置: 首页>>代码示例>>Java>>正文


Java Transliterator类代码示例

本文整理汇总了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);
}
 
开发者ID:geetools,项目名称:geeCommerce-Java-Shop-Software-and-PIM,代码行数:27,代码来源:Strings.java

示例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);
}
 
开发者ID:toyama0919,项目名称:embulk-filter-icu4j,代码行数:22,代码来源:Icu4jPageOutput.java

示例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);

}
 
开发者ID:rdoeffinger,项目名称:DictionaryPC,代码行数:24,代码来源:LanguageTest.java

示例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);
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:20,代码来源:ICUTransformFilterFactory.java

示例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;
    }
}
 
开发者ID:SilentCircle,项目名称:silent-contacts-android,代码行数:18,代码来源:ContactLocaleUtils43.java

示例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);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:8,代码来源:IcuTransformTokenFilterFactory.java

示例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());
}
 
开发者ID:abhijitvalluri,项目名称:fitnotifications,代码行数:12,代码来源:UtilityExtensions.java

示例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);
    }
}
 
开发者ID:kawasima,项目名称:enkan,代码行数:8,代码来源:IcuNormalizer.java

示例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;
}
 
开发者ID:ranmocy,项目名称:MonkeyTree,代码行数:12,代码来源:ContactFixer.java

示例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);
}
 
开发者ID:jprante,项目名称:elasticsearch-icu,代码行数:12,代码来源:IcuTransformTokenFilterFactory.java

示例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;
}
 
开发者ID:SeldonIO,项目名称:semantic-vectors-lucene-tools,代码行数:11,代码来源:TransliteratorPeer.java

示例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;
}
 
开发者ID:toyama0919,项目名称:embulk-filter-icu4j,代码行数:18,代码来源:Icu4jPageOutput.java

示例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;
}
 
开发者ID:Biblivre,项目名称:Biblivre-3,代码行数:9,代码来源:TextUtils.java

示例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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:21,代码来源:ICUTransformFilter.java

示例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);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:ICUTransformFilterFactory.java


注:本文中的com.ibm.icu.text.Transliterator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。