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


Java RuleBasedCollator.getRules方法代码示例

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


在下文中一共展示了RuleBasedCollator.getRules方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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: 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

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

    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

示例4: 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

示例5: 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

示例6: 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

示例7: 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";
  ICUCollationKeyFilterFactory factory = new ICUCollationKeyFilterFactory();
  Map<String,String> args = new HashMap<String,String>();
  args.put("custom", "rules.txt");
  args.put("strength", "primary");
  factory.init(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:pkarmstr,项目名称:NYBC,代码行数:30,代码来源:TestICUCollationKeyFilterFactory.java

示例8: 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 {
  // make a solr home underneath the test's TEMP_DIR
  File tmpFile = File.createTempFile("test", "tmp", TEMP_DIR);
  tmpFile.delete();
  tmpFile.mkdir();
  
  // 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.getAbsolutePath();
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:38,代码来源:TestICUCollationField.java

示例9: 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 = ImmutableSettings.settingsBuilder()
            .put(IndexMetaData.SETTING_VERSION_CREATED, Version.CURRENT)
            .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-analysis-german,代码行数:30,代码来源:IcuCollationAnalyzerTests.java

示例10: 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<String,String>();
  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:jimaguere,项目名称:Maskana-Gestor-de-Conocimiento,代码行数:29,代码来源:TestICUCollationKeyFilterFactory.java


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