Search in sources :

Example 16 with ClasspathResourceLoader

use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.

the class TestStopFilterFactory method testInform.

public void testInform() throws Exception {
    ResourceLoader loader = new ClasspathResourceLoader(getClass());
    assertTrue("loader is null and it shouldn't be", loader != null);
    StopFilterFactory factory = (StopFilterFactory) tokenFilterFactory("Stop", "words", "stop-1.txt", "ignoreCase", "true");
    CharArraySet words = factory.getStopWords();
    assertTrue("words is null and it shouldn't be", words != null);
    assertTrue("words Size: " + words.size() + " is not: " + 2, words.size() == 2);
    assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory.isIgnoreCase() == true);
    factory = (StopFilterFactory) tokenFilterFactory("Stop", "words", "stop-1.txt, stop-2.txt", "ignoreCase", "true");
    words = factory.getStopWords();
    assertTrue("words is null and it shouldn't be", words != null);
    assertTrue("words Size: " + words.size() + " is not: " + 4, words.size() == 4);
    assertTrue(factory.isIgnoreCase() + " does not equal: " + true, factory.isIgnoreCase() == true);
    factory = (StopFilterFactory) tokenFilterFactory("Stop", "words", "stop-snowball.txt", "format", "snowball", "ignoreCase", "true");
    words = factory.getStopWords();
    assertEquals(8, words.size());
    assertTrue(words.contains("he"));
    assertTrue(words.contains("him"));
    assertTrue(words.contains("his"));
    assertTrue(words.contains("himself"));
    assertTrue(words.contains("she"));
    assertTrue(words.contains("her"));
    assertTrue(words.contains("hers"));
    assertTrue(words.contains("herself"));
    // defaults
    factory = (StopFilterFactory) tokenFilterFactory("Stop");
    assertEquals(StopAnalyzer.ENGLISH_STOP_WORDS_SET, factory.getStopWords());
    assertEquals(false, factory.isIgnoreCase());
}
Also used : ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader) ResourceLoader(org.apache.lucene.analysis.util.ResourceLoader) CharArraySet(org.apache.lucene.analysis.CharArraySet) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader)

Example 17 with ClasspathResourceLoader

use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.

the class TestPhoneticFilterFactory method testInjectFalse.

public void testInjectFalse() throws IOException {
    Map<String, String> args = new HashMap<>();
    args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
    args.put(PhoneticFilterFactory.INJECT, "false");
    PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
    factory.inform(new ClasspathResourceLoader(factory.getClass()));
    assertFalse(factory.inject);
}
Also used : HashMap(java.util.HashMap) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader)

Example 18 with ClasspathResourceLoader

use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.

the class TestPhoneticFilterFactory method testMaxCodeLength.

public void testMaxCodeLength() throws IOException {
    Map<String, String> args = new HashMap<>();
    args.put(PhoneticFilterFactory.ENCODER, "Metaphone");
    args.put(PhoneticFilterFactory.MAX_CODE_LENGTH, "2");
    PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
    factory.inform(new ClasspathResourceLoader(factory.getClass()));
    assertEquals(2, ((Metaphone) factory.getEncoder()).getMaxCodeLen());
}
Also used : HashMap(java.util.HashMap) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader)

Example 19 with ClasspathResourceLoader

use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.

the class TestPhoneticFilterFactory method testFactoryReflection.

/**
   * Case: Reflection
   */
public void testFactoryReflection() throws IOException {
    Map<String, String> args = new HashMap<>();
    args.put(PhoneticFilterFactory.ENCODER, "org.apache.commons.codec.language.Metaphone");
    PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
    factory.inform(new ClasspathResourceLoader(factory.getClass()));
    assertTrue(factory.getEncoder() instanceof Metaphone);
    // default
    assertTrue(factory.inject);
}
Also used : HashMap(java.util.HashMap) Metaphone(org.apache.commons.codec.language.Metaphone) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader)

Example 20 with ClasspathResourceLoader

use of org.apache.lucene.analysis.util.ClasspathResourceLoader in project lucene-solr by apache.

the class TestPhoneticFilterFactory method testFactoryReflectionCaverphone.

public void testFactoryReflectionCaverphone() throws IOException {
    Map<String, String> args = new HashMap<>();
    args.put(PhoneticFilterFactory.ENCODER, "Caverphone");
    PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
    factory.inform(new ClasspathResourceLoader(factory.getClass()));
    assertTrue(factory.getEncoder() instanceof Caverphone2);
    // default
    assertTrue(factory.inject);
}
Also used : HashMap(java.util.HashMap) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader) Caverphone2(org.apache.commons.codec.language.Caverphone2)

Aggregations

ClasspathResourceLoader (org.apache.lucene.analysis.util.ClasspathResourceLoader)25 HashMap (java.util.HashMap)16 ResourceLoader (org.apache.lucene.analysis.util.ResourceLoader)7 StringReader (java.io.StringReader)5 CharArraySet (org.apache.lucene.analysis.CharArraySet)5 Tokenizer (org.apache.lucene.analysis.Tokenizer)5 Reader (java.io.Reader)4 JsonElement (com.google.gson.JsonElement)3 JsonObject (com.google.gson.JsonObject)3 ResourceLoaderAware (org.apache.lucene.analysis.util.ResourceLoaderAware)3 JsonArray (com.google.gson.JsonArray)2 LinkedList (java.util.LinkedList)2 Caverphone2 (org.apache.commons.codec.language.Caverphone2)2 Metaphone (org.apache.commons.codec.language.Metaphone)2 TokenStream (org.apache.lucene.analysis.TokenStream)2 IOException (java.io.IOException)1 NodeStateResourceLoader (org.apache.jackrabbit.oak.plugins.index.lucene.NodeStateAnalyzerFactory.NodeStateResourceLoader)1 NodeBuilder (org.apache.jackrabbit.oak.spi.state.NodeBuilder)1 LimitTokenCountFilterFactory (org.apache.lucene.analysis.miscellaneous.LimitTokenCountFilterFactory)1 CharFilterFactory (org.apache.lucene.analysis.util.CharFilterFactory)1