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


Java RuleBasedCollator类代码示例

本文整理汇总了Java中com.ibm.icu.text.RuleBasedCollator的典型用法代码示例。如果您正苦于以下问题:Java RuleBasedCollator类的具体用法?Java RuleBasedCollator怎么用?Java RuleBasedCollator使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


RuleBasedCollator类属于com.ibm.icu.text包,在下文中一共展示了RuleBasedCollator类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCustomRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
public void testCustomRules() throws Exception {
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE"));
    String DIN5007_2_tailorings =
            "& ae , a\u0308 & AE , A\u0308"+
                    "& oe , o\u0308 & OE , O\u0308"+
                    "& ue , u\u0308 & UE , u\u0308";

    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();

    Settings settings = Settings.builder()
            .put("index.analysis.filter.myCollator.type", "icu_collation")
            .put("index.analysis.filter.myCollator.rules", tailoredRules)
            .put("index.analysis.filter.myCollator.strength", "primary")
            .build();
    TestAnalysis analysis = createTestAnalysis(new Index("test", "_na_"), settings, new AnalysisICUPlugin());

    TokenFilterFactory filterFactory = analysis.tokenFilter.get("myCollator");
    assertCollatesToSame(filterFactory, "Töne", "Toene");
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:SimpleIcuCollationTokenFilterTests.java

示例2: setCollatorStrength

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
private static void setCollatorStrength(RuleBasedCollator collator, CollationSpecifier specifier) {
    if (specifier.caseSensitive() && specifier.accentSensitive()) {
        collator.setStrength(Collator.TERTIARY);
        collator.setCaseLevel(false);
    }
    else if (specifier.caseSensitive() && !specifier.accentSensitive()) {
        collator.setCaseLevel(true);
        collator.setStrength(Collator.PRIMARY);
    }
    else if (!specifier.caseSensitive() && specifier.accentSensitive()) {
        collator.setStrength(Collator.SECONDARY);
        collator.setCaseLevel(false);
    }
    else {
        collator.setStrength(Collator.PRIMARY);
        collator.setCaseLevel(false);
    }
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:19,代码来源:CollationSpecifier.java

示例3: testCustomRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
@Test
public void testCustomRules() throws Exception {
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE"));
    String DIN5007_2_tailorings =
            "& ae , a\u0308 & AE , A\u0308& oe , o\u0308 & OE , O\u0308& ue , u\u0308 & UE , u\u0308";

    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();

    Settings settings = Settings.builder()
            .put("index.analysis.analyzer.myAnalyzer.type", "icu_collation")
            .put("index.analysis.analyzer.myAnalyzer.rules", tailoredRules)
            .put("index.analysis.analyzer.myAnalyzer.strength", "primary")
            .build();
    Analyzer analyzer = analyzer(settings, "myAnalyzer");

    String germanUmlaut = "Töne";
    TokenStream tsUmlaut = analyzer.tokenStream(null, germanUmlaut);
    BytesRef b1 = bytesFromTokenStream(tsUmlaut);

    String germanExpandedUmlaut = "Toene";
    TokenStream tsExpanded = analyzer.tokenStream(null, germanExpandedUmlaut);
    BytesRef b2 = bytesFromTokenStream(tsExpanded);

    assertTrue(compare(b1.bytes, b2.bytes) == 0);
}
 
开发者ID:jprante,项目名称:elasticsearch-plugin-bundle,代码行数:27,代码来源:IcuCollationAnalyzerTests.java

示例4: catch

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
public void	Init(String locale, boolean numeric_ordering) {
	try {
		this.collator = Collator.getInstance(Locale.forLanguageTag(locale));
		if (numeric_ordering) {
			RuleBasedCollator rbc = (RuleBasedCollator)collator;
			rbc.setNumericCollation(true);
		}
	} catch (Exception e) {throw Err_.new_wo_type("collator init failed", "err", Err_.Message_lang(e));}		
}
 
开发者ID:gnosygnu,项目名称:xowa_android,代码行数:10,代码来源:Uca_collator__icu__4_8.java

示例5: requireThatArabicHasCorrectRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
private void requireThatArabicHasCorrectRules(Collator col) {
    final int reorderCodes [] = {UScript.ARABIC};
    assertEquals("6.2.0.0", col.getUCAVersion().toString());
    assertEquals("58.0.0.6", col.getVersion().toString());
    assertEquals(Arrays.toString(reorderCodes), Arrays.toString(col.getReorderCodes()));
    assertTrue(col.compare("a", "b") < 0);
    assertTrue(col.compare("a", "aس") < 0);
    assertFalse(col.compare("س", "a") < 0);

    assertEquals(" [reorder Arab]&ت<<ة<<<ﺔ<<<ﺓ&ي<<ى<<<ﯨ<<<ﯩ<<<ﻰ<<<ﻯ<<<ﲐ<<<ﱝ", ((RuleBasedCollator) col).getRules());
    assertFalse(col.compare("س", "a") < 0);
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:13,代码来源:SortingTestCase.java

示例6: requireThatChineseHasCorrectRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
private void requireThatChineseHasCorrectRules(Collator col) {
    final int reorderCodes [] = {UScript.HAN};
    assertEquals("8.0.0.0", col.getUCAVersion().toString());
    assertEquals("153.64.29.0", col.getVersion().toString());
    assertEquals(Arrays.toString(reorderCodes), Arrays.toString(col.getReorderCodes()));

    assertNotEquals("", ((RuleBasedCollator) col).getRules());
}
 
开发者ID:vespa-engine,项目名称:vespa,代码行数:9,代码来源:SortingTestCase.java

示例7: testCustomRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
@Test
public void testCustomRules() throws Exception {
    RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE"));
    String DIN5007_2_tailorings =
            "& ae , a\u0308 & AE , A\u0308& oe , o\u0308 & OE , O\u0308& ue , u\u0308 & UE , u\u0308";

    RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
    String tailoredRules = tailoredCollator.getRules();

    Index index = new Index("test");
    Settings settings = Settings.settingsBuilder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .put("path.home", System.getProperty("path.home"))
            .put("index.analysis.analyzer.myAnalyzer.type", "icu_collation")
            .put("index.analysis.analyzer.myAnalyzer.rules", tailoredRules)
            .put("index.analysis.analyzer.myAnalyzer.strength", "primary")
            .build();
    AnalysisService analysisService = createAnalysisService(index, settings);
    Analyzer analyzer = analysisService.analyzer("myAnalyzer").analyzer();

    String germanUmlaut = "Töne";
    TokenStream tsUmlaut = analyzer.tokenStream(null, germanUmlaut);
    BytesRef b1 = bytesFromTokenStream(tsUmlaut);

    String germanExpandedUmlaut = "Toene";
    TokenStream tsExpanded = analyzer.tokenStream(null, germanExpandedUmlaut);
    BytesRef b2 = bytesFromTokenStream(tsExpanded);

    assertTrue(compare(b1.bytes, b2.bytes) == 0);
}
 
开发者ID:jprante,项目名称:elasticsearch-icu,代码行数:31,代码来源:IcuCollationAnalyzerTests.java

示例8: createCollator

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
public RuleBasedCollator createCollator() {
    ULocale ulocale = new ULocale(locale);
    checkLocale(ulocale, scheme);
    ulocale = setKeywords(ulocale, keywordsToValues);

    RuleBasedCollator collator = (RuleBasedCollator) RuleBasedCollator.getInstance(ulocale);
    checkKeywords(collator.getLocale(ULocale.VALID_LOCALE), keywordsToValues,
            scheme);

    if (shouldSetStrength()) {
        setCollatorStrength(collator, this);
    }
    
    return collator;
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:16,代码来源:CollationSpecifier.java

示例9: forScheme

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
/**
 * Construct an actual ICU Collator given a collation specifier. The
 * result is a Collator that must be use in a thread-private manner.
 */
static synchronized Collator forScheme(final CollationSpecifier specifier) {
    RuleBasedCollator collator = (RuleBasedCollator) sourceMap.get(specifier.toString());
    if (collator == null) {
        collator = specifier.createCollator();
        sourceMap.put(specifier.toString(), collator);
    }
    collator = collator.cloneAsThawed();
    return collator;
}
 
开发者ID:jaytaylor,项目名称:sql-layer,代码行数:14,代码来源:AkCollatorFactory.java

示例10: createFromRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
private Collator createFromRules(String fileName, ResourceLoader loader) {
  InputStream input = null;
  try {
   input = loader.openResource(fileName);
   String rules = toUTF8String(input);
   return new RuleBasedCollator(rules);
  } catch (Exception e) {
    // io error or invalid rules
    throw new RuntimeException(e);
  } finally {
    IOUtils.closeWhileHandlingException(input);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:ICUCollationKeyFilterFactory.java

示例11: testCustomRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
public void testCustomRules() throws Exception {
  RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de_DE"));

  String DIN5007_2_tailorings =
    "& ae , a\u0308 & AE , A\u0308"+
    "& oe , o\u0308 & OE , O\u0308"+
    "& ue , u\u0308 & UE , u\u0308";

  RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
  String tailoredRules = tailoredCollator.getRules();
  //
  // at this point, you would save these tailoredRules to a file, 
  // and use the custom parameter.
  //
  String germanUmlaut = "Töne";
  String germanOE = "Toene";
  Map<String,String> args = new HashMap<>();
  args.put("custom", "rules.txt");
  args.put("strength", "primary");
  ICUCollationKeyFilterFactory factory = new ICUCollationKeyFilterFactory(args);
  factory.inform(new StringMockResourceLoader(tailoredRules));
  TokenStream tsUmlaut = factory.create(
      new KeywordTokenizer(new StringReader(germanUmlaut)));
  TokenStream tsOE = factory.create(
      new KeywordTokenizer(new StringReader(germanOE)));

  assertCollatesToSame(tsUmlaut, tsOE);
}
 
开发者ID:europeana,项目名称:search,代码行数:29,代码来源:TestICUCollationKeyFilterFactory.java

示例12: createFromRules

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
/**
 * Read custom rules from a file, and create a RuleBasedCollator
 * The file cannot support comments, as # might be in the rules!
 */
private Collator createFromRules(String fileName, ResourceLoader loader) {
  InputStream input = null;
  try {
   input = loader.openResource(fileName);
   String rules = IOUtils.toString(input, "UTF-8");
   return new RuleBasedCollator(rules);
  } catch (Exception e) {
    // io error or invalid rules
    throw new RuntimeException(e);
  } finally {
    IOUtils.closeQuietly(input);
  }
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:ICUCollationField.java

示例13: setupSolrHome

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
/**
 * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
 * These are largish files, and jvm-specific (as our documentation says, you should always
 * look out for jvm differences with collation).
 * So its preferable to create this file on-the-fly.
 */
public static String setupSolrHome() throws Exception {
  String tmpFile = createTempDir().getAbsolutePath();
  // make data and conf dirs
  new File(tmpFile  + "/collection1", "data").mkdirs();
  File confDir = new File(tmpFile + "/collection1", "conf");
  confDir.mkdirs();
  
  // copy over configuration files
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"), new File(confDir, "solrconfig.xml"));
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/schema-icucollate.xml"), new File(confDir, "schema.xml"));
  
  // generate custom collation rules (DIN 5007-2), saving to customrules.dat
  RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de", "DE"));

  String DIN5007_2_tailorings =
    "& ae , a\u0308 & AE , A\u0308"+
    "& oe , o\u0308 & OE , O\u0308"+
    "& ue , u\u0308 & UE , u\u0308";

  RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
  String tailoredRules = tailoredCollator.getRules();
  FileOutputStream os = new FileOutputStream(new File(confDir, "customrules.dat"));
  IOUtils.write(tailoredRules, os, "UTF-8");
  os.close();

  return tmpFile;
}
 
开发者ID:europeana,项目名称:search,代码行数:34,代码来源:TestICUCollationField.java

示例14: setupSolrHome

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
/**
 * Ugly: but what to do? We want to test custom sort, which reads rules in as a resource.
 * These are largish files, and jvm-specific (as our documentation says, you should always
 * look out for jvm differences with collation).
 * So its preferable to create this file on-the-fly.
 */
public static String setupSolrHome() throws Exception {
  File tmpFile = createTempDir();
  
  // make data and conf dirs
  new File(tmpFile + "/collection1", "data").mkdirs();
  File confDir = new File(tmpFile + "/collection1", "conf");
  confDir.mkdirs();
  
  // copy over configuration files
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/solrconfig-icucollate.xml"), new File(confDir, "solrconfig.xml"));
  FileUtils.copyFile(getFile("analysis-extras/solr/collection1/conf/schema-icucollate-dv.xml"), new File(confDir, "schema.xml"));
  
  // generate custom collation rules (DIN 5007-2), saving to customrules.dat
  RuleBasedCollator baseCollator = (RuleBasedCollator) Collator.getInstance(new ULocale("de", "DE"));

  String DIN5007_2_tailorings =
    "& ae , a\u0308 & AE , A\u0308"+
    "& oe , o\u0308 & OE , O\u0308"+
    "& ue , u\u0308 & UE , u\u0308";

  RuleBasedCollator tailoredCollator = new RuleBasedCollator(baseCollator.getRules() + DIN5007_2_tailorings);
  String tailoredRules = tailoredCollator.getRules();
  FileOutputStream os = new FileOutputStream(new File(confDir, "customrules.dat"));
  IOUtils.write(tailoredRules, os, "UTF-8");
  os.close();

  return tmpFile.getAbsolutePath();
}
 
开发者ID:europeana,项目名称:search,代码行数:35,代码来源:TestICUCollationFieldDocValues.java

示例15: KeyComparator

import com.ibm.icu.text.RuleBasedCollator; //导入依赖的package包/类
public KeyComparator(int strength, Map<String, CollationKey> cache, boolean alternateHandlingShifted) {
    try {
        collator = (RuleBasedCollator)Collator.getInstance(Locale.ROOT).clone();
    } catch (CloneNotSupportedException e) {
        throw new RuntimeException(e);
    }
    collator.setStrength(strength);
    collator.setAlternateHandlingShifted(alternateHandlingShifted);
    this.cache = cache;
}
 
开发者ID:itkach,项目名称:slobj,代码行数:11,代码来源:Slob.java


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