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


Java ClasspathResourceLoader类代码示例

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


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

示例1: createComponents

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
@Override
protected TokenStreamComponents createComponents(String fieldName, Reader reader) {
    Tokenizer token = new IKTokenizer(reader, useSmart);
    Map<String, String> paramsMap = new HashMap<String, String>();
    Configuration cfg = DefaultConfig.getInstance();
    paramsMap.put("luceneMatchVersion", luceneMatchVersion.toString());
    paramsMap.put("synonyms", cfg.getExtSynonymDictionarys().get(0));
    paramsMap.put("ignoreCase", "true");
    SynonymFilterFactory factory = new SynonymFilterFactory(paramsMap);
    ResourceLoader loader = new ClasspathResourceLoader();
    try {
        factory.inform(loader);
    } catch (IOException e) {
        e.printStackTrace();
    }
    return new TokenStreamComponents(token, factory.create(token));
}
 
开发者ID:xindongzhang,项目名称:IK-Analyzer-2012FF,代码行数:18,代码来源:IKSynonymAnalyzer.java

示例2: testInform

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
public void testInform() throws Exception {
  ResourceLoader loader = new ClasspathResourceLoader(getClass());
  assertTrue("loader is null and it shouldn't be", loader != null);
  KeepWordFilterFactory factory = (KeepWordFilterFactory) tokenFilterFactory("KeepWord",
      "words", "keep-1.txt",
      "ignoreCase", "true");
  CharArraySet words = factory.getWords();
  assertTrue("words is null and it shouldn't be", words != null);
  assertTrue("words Size: " + words.size() + " is not: " + 2, words.size() == 2);

  factory = (KeepWordFilterFactory) tokenFilterFactory("KeepWord",
      "words", "keep-1.txt, keep-2.txt",
      "ignoreCase", "true");
  words = factory.getWords();
  assertTrue("words is null and it shouldn't be", words != null);
  assertTrue("words Size: " + words.size() + " is not: " + 4, words.size() == 4);
}
 
开发者ID:europeana,项目名称:search,代码行数:18,代码来源:TestKeepFilterFactory.java

示例3: create

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * Test for {@link JdbcSynonymFilterFactory#create(TokenStream)}.
 */
@Test
public void create() throws Exception {
   Map<String, String> args = new HashMap<>();
   args.put(AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM, Version.LATEST.toString());
   args.put(JdbcReaderFactoryParams.DATASOURCE, "java:comp/env/dataSource");
   args.put(JdbcReaderFactoryParams.SQL, "select stopword from stopwords");

   // White space tokenizer, to lower case tokenizer.
   MockTokenizer tokenizer = new MockTokenizer();
   tokenizer.setReader(new StringReader("test1 somestring test2 anotherstring"));

   JdbcStopFilterFactory factory = new JdbcStopFilterFactory(args);
   factory.inform(new ClasspathResourceLoader(getClass().getClassLoader()));

   try (TokenStream stream = factory.create(tokenizer)) {
      CharTermAttribute attribute = stream.addAttribute(CharTermAttribute.class);
      stream.reset();
      assertTrue(stream.incrementToken());
      assertEquals("test1", attribute.toString());
      assertTrue(stream.incrementToken());
      assertEquals("test2", attribute.toString());
      assertFalse(stream.incrementToken());
      stream.end();
   }
}
 
开发者ID:shopping24,项目名称:solr-jdbc,代码行数:29,代码来源:JdbcStopFilterFactoryTest.java

示例4: testFactory

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * Case: default
 */
public void testFactory() throws IOException {
  Map<String,String> args = new HashMap<String, String>();
  
  PhoneticFilterFactory ff = new PhoneticFilterFactory();
  
  args.put( PhoneticFilterFactory.ENCODER, "Metaphone" );
  ff.init( args );
  ff.inform(new ClasspathResourceLoader(ff.getClass()));
  assertTrue( ff.getEncoder() instanceof Metaphone );
  assertTrue( ff.inject ); // default

  args.put( PhoneticFilterFactory.INJECT, "false" );
  ff.init( args );
  ff.inform(new ClasspathResourceLoader(ff.getClass()));
  assertFalse( ff.inject );

  args.put( PhoneticFilterFactory.MAX_CODE_LENGTH, "2");
  ff.init(args);
  ff.inform(new ClasspathResourceLoader(ff.getClass()));
  assertEquals(2, ((Metaphone) ff.getEncoder()).getMaxCodeLen());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:25,代码来源:TestPhoneticFilterFactory.java

示例5: testHyphenationWithDictionary

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * Ensure the factory works with hyphenation grammar+dictionary: using default options.
 */
public void testHyphenationWithDictionary() throws Exception {
  Reader reader = new StringReader("min veninde som er lidt af en læsehest");
  Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
  HyphenationCompoundWordTokenFilterFactory factory = new HyphenationCompoundWordTokenFilterFactory();
  ResourceLoader loader = new ClasspathResourceLoader(getClass());
  Map<String,String> args = new HashMap<String,String>();
  args.put("hyphenator", "da_UTF8.xml");
  args.put("dictionary", "da_compoundDictionary.txt");
  factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
  factory.init(args);
  factory.inform(loader);
  TokenStream stream = factory.create(tokenizer);
  
  assertTokenStreamContents(stream, 
      new String[] { "min", "veninde", "som", "er", "lidt", "af", "en", "læsehest", "læse", "hest" },
      new int[] { 1, 1, 1, 1, 1, 1, 1, 1, 0, 0 }
  );
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:22,代码来源:TestHyphenationCompoundWordTokenFilterFactory.java

示例6: testHyphenationOnly

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * Ensure the factory works with no dictionary: using hyphenation grammar only.
 * Also change the min/max subword sizes from the default. When using no dictionary,
 * its generally necessary to tweak these, or you get lots of expansions.
 */
public void testHyphenationOnly() throws Exception {
  Reader reader = new StringReader("basketballkurv");
  Tokenizer tokenizer = new MockTokenizer(reader, MockTokenizer.WHITESPACE, false);
  HyphenationCompoundWordTokenFilterFactory factory = new HyphenationCompoundWordTokenFilterFactory();
  ResourceLoader loader = new ClasspathResourceLoader(getClass());
  Map<String,String> args = new HashMap<String,String>();
  args.put("hyphenator", "da_UTF8.xml");
  args.put("minSubwordSize", "2");
  args.put("maxSubwordSize", "4");
  factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
  factory.init(args);
  factory.inform(loader);
  TokenStream stream = factory.create(tokenizer);
  
  assertTokenStreamContents(stream,
      new String[] { "basketballkurv", "ba", "sket", "bal", "ball", "kurv" }
  );
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:24,代码来源:TestHyphenationCompoundWordTokenFilterFactory.java

示例7: testDefaults

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * If no words are provided, then a set of english default stopwords is used.
 */
public void testDefaults() throws Exception {
  ResourceLoader loader = new ClasspathResourceLoader(TestStopFilter.class);
  assertTrue("loader is null and it shouldn't be", loader != null);
  CommonGramsFilterFactory factory = new CommonGramsFilterFactory();
  factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
  Map<String, String> args = Collections.emptyMap();
  factory.init(args);
  factory.inform(loader);
  CharArraySet words = factory.getCommonWords();
  assertTrue("words is null and it shouldn't be", words != null);
  assertTrue(words.contains("the"));
  Tokenizer tokenizer = new MockTokenizer(new StringReader("testing the factory"), MockTokenizer.WHITESPACE, false);
  TokenStream stream = factory.create(tokenizer);
  assertTokenStreamContents(stream, 
      new String[] { "testing", "testing_the", "the", "the_factory", "factory" });
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:20,代码来源:TestCommonGramsFilterFactory.java

示例8: testDefaults

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * If no words are provided, then a set of english default stopwords is used.
 */
public void testDefaults() throws Exception {
  ResourceLoader loader = new ClasspathResourceLoader(TestStopFilter.class);
  assertTrue("loader is null and it shouldn't be", loader != null);
  CommonGramsQueryFilterFactory factory = new CommonGramsQueryFilterFactory();
  factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
  Map<String, String> args = Collections.emptyMap();
  factory.init(args);
  factory.inform(loader);
  CharArraySet words = factory.getCommonWords();
  assertTrue("words is null and it shouldn't be", words != null);
  assertTrue(words.contains("the"));
  Tokenizer tokenizer = new MockTokenizer(new StringReader("testing the factory"), MockTokenizer.WHITESPACE, false);
  TokenStream stream = factory.create(tokenizer);
  assertTokenStreamContents(stream, 
      new String[] { "testing_the", "the_factory" });
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:20,代码来源:TestCommonGramsQueryFilterFactory.java

示例9: testInform

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
@Test
public void testInform() throws Exception {
  ResourceLoader loader = new ClasspathResourceLoader(getClass());
  TypeTokenFilterFactory factory = new TypeTokenFilterFactory();
  Map<String, String> args = new HashMap<String, String>();
  args.put("types", "stoptypes-1.txt");
  args.put("enablePositionIncrements", "true");
  factory.setLuceneMatchVersion(TEST_VERSION_CURRENT);
  factory.init(args);
  factory.inform(loader);
  Set<String> types = factory.getStopTypes();
  assertTrue("types is null and it shouldn't be", types != null);
  assertTrue("types Size: " + types.size() + " is not: " + 2, types.size() == 2);
  assertTrue("enablePositionIncrements was set to true but not correctly parsed", factory.isEnablePositionIncrements());

  factory = new TypeTokenFilterFactory();
  args.put("types", "stoptypes-1.txt, stoptypes-2.txt");
  args.put("enablePositionIncrements", "false");
  args.put("useWhitelist","true");
  factory.init(args);
  factory.inform(loader);
  types = factory.getStopTypes();
  assertTrue("types is null and it shouldn't be", types != null);
  assertTrue("types Size: " + types.size() + " is not: " + 4, types.size() == 4);
  assertTrue("enablePositionIncrements was set to false but not correctly parsed", !factory.isEnablePositionIncrements());
}
 
开发者ID:pkarmstr,项目名称:NYBC,代码行数:27,代码来源:TestTypeTokenFilterFactory.java

示例10: create

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * Test for {@link JdbcSynonymFilterFactory#create(TokenStream)}.
 */
@Test
public void create() throws Exception {
   Map<String, String> args = new HashMap<>();
   args.put(AbstractAnalysisFactory.LUCENE_MATCH_VERSION_PARAM, Version.LUCENE_5_0_0.toString());
   args.put(JdbcReaderFactoryParams.DATASOURCE, "java:comp/env/dataSource");
   args.put(JdbcReaderFactoryParams.SQL, "select stopword from stopwords");

   // White space tokenizer, to lower case tokenizer.
   MockTokenizer tokenizer = new MockTokenizer();
   tokenizer.setReader(new StringReader("test1 somestring test2 anotherstring"));

   JdbcStopFilterFactory factory = new JdbcStopFilterFactory(args);
   factory.inform(new ClasspathResourceLoader());

   try (TokenStream stream = factory.create(tokenizer)) {
      CharTermAttribute attribute = stream.addAttribute(CharTermAttribute.class);
      stream.reset();
      assertTrue(stream.incrementToken());
      assertEquals("test1", attribute.toString());
      assertTrue(stream.incrementToken());
      assertEquals("test2", attribute.toString());
      assertFalse(stream.incrementToken());
      stream.end();
   }
}
 
开发者ID:shopping24,项目名称:solr-jdbc-synonyms,代码行数:29,代码来源:JdbcStopFilterFactoryTest.java

示例11: testMixedText

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
public void testMixedText() throws Exception {
  Reader reader = new StringReader("การที่ได้ต้องแสดงว่างานดี  This is a test ກວ່າດອກ");
  ICUTokenizerFactory factory = new ICUTokenizerFactory(new HashMap<String,String>());
  factory.inform(new ClasspathResourceLoader(getClass()));
  TokenStream stream = factory.create(newAttributeFactory(), reader);
  assertTokenStreamContents(stream,
      new String[] { "การ", "ที่", "ได้", "ต้อง", "แสดง", "ว่า", "งาน", "ดี",
      "This", "is", "a", "test", "ກວ່າ", "ດອກ"});
}
 
开发者ID:europeana,项目名称:search,代码行数:10,代码来源:TestICUTokenizerFactory.java

示例12: testTokenizeLatinOnWhitespaceOnly

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
public void testTokenizeLatinOnWhitespaceOnly() throws Exception {
  // “ U+201C LEFT DOUBLE QUOTATION MARK; ” U+201D RIGHT DOUBLE QUOTATION MARK
  Reader reader = new StringReader
      ("  Don't,break.at?/(punct)!  \u201Cnice\u201D\r\n\r\n85_At:all; `really\" +2=3$5,&813 [email protected]#%$^)(*@#$   ");
  final Map<String,String> args = new HashMap<>();
  args.put(ICUTokenizerFactory.RULEFILES, "Latn:Latin-break-only-on-whitespace.rbbi");
  ICUTokenizerFactory factory = new ICUTokenizerFactory(args);
  factory.inform(new ClasspathResourceLoader(this.getClass()));
  TokenStream stream = factory.create(newAttributeFactory(), reader);
  assertTokenStreamContents(stream,
      new String[] { "Don't,break.at?/(punct)!", "\u201Cnice\u201D", "85_At:all;", "`really\"",  "+2=3$5,&813", "[email protected]#%$^)(*@#$" },
      new String[] { "<ALPHANUM>",               "<ALPHANUM>",       "<ALPHANUM>", "<ALPHANUM>", "<NUM>",       "<OTHER>" });
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:TestICUTokenizerFactory.java

示例13: testTokenizeLatinDontBreakOnHyphens

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
public void testTokenizeLatinDontBreakOnHyphens() throws Exception {
  Reader reader = new StringReader
      ("One-two punch.  Brang-, not brung-it.  This one--not that one--is the right one, -ish.");
  final Map<String,String> args = new HashMap<>();
  args.put(ICUTokenizerFactory.RULEFILES, "Latn:Latin-dont-break-on-hyphens.rbbi");
  ICUTokenizerFactory factory = new ICUTokenizerFactory(args);
  factory.inform(new ClasspathResourceLoader(getClass()));
  TokenStream stream = factory.create(newAttributeFactory(), reader);
  assertTokenStreamContents(stream,
      new String[] { "One-two", "punch",
          "Brang", "not", "brung-it",
          "This", "one", "not", "that", "one", "is", "the", "right", "one", "ish" });
}
 
开发者ID:europeana,项目名称:search,代码行数:14,代码来源:TestICUTokenizerFactory.java

示例14: testKeywordTokenizeCyrillicAndThai

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * Specify more than one script/rule file pair.
 * Override default DefaultICUTokenizerConfig Thai script tokenization.
 * Use the same rule file for both scripts.
 */
public void testKeywordTokenizeCyrillicAndThai() throws Exception {
  Reader reader = new StringReader
      ("Some English.  Немного русский.  ข้อความภาษาไทยเล็ก ๆ น้อย ๆ  More English.");
  final Map<String,String> args = new HashMap<>();
  args.put(ICUTokenizerFactory.RULEFILES, "Cyrl:KeywordTokenizer.rbbi,Thai:KeywordTokenizer.rbbi");
  ICUTokenizerFactory factory = new ICUTokenizerFactory(args);
  factory.inform(new ClasspathResourceLoader(getClass()));
  TokenStream stream = factory.create(newAttributeFactory(), reader);
  assertTokenStreamContents(stream, new String[] { "Some", "English",
      "Немного русский.  ",
      "ข้อความภาษาไทยเล็ก ๆ น้อย ๆ  ",
      "More", "English" });
}
 
开发者ID:europeana,项目名称:search,代码行数:19,代码来源:TestICUTokenizerFactory.java

示例15: testFactoryDefaults

import org.apache.lucene.analysis.util.ClasspathResourceLoader; //导入依赖的package包/类
/**
 * Case: default
 */
public void testFactoryDefaults() throws IOException {
  Map<String,String> args = new HashMap<>();
  args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
  PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
  factory.inform(new ClasspathResourceLoader(factory.getClass()));
  assertTrue(factory.getEncoder() instanceof Metaphone);
  assertTrue(factory.inject); // default
}
 
开发者ID:europeana,项目名称:search,代码行数:12,代码来源:TestPhoneticFilterFactory.java


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