Search in sources :

Example 6 with ClasspathResourceLoader

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

the class TestPhoneticFilterFactory method testUnknownEncoderReflection.

public void testUnknownEncoderReflection() throws IOException {
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        Map<String, String> args = new HashMap<>();
        args.put("encoder", "org.apache.commons.codec.language.NonExistence");
        PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
        factory.inform(new ClasspathResourceLoader(factory.getClass()));
    });
    assertTrue(expected.getMessage().contains("Error loading encoder"));
}
Also used : HashMap(java.util.HashMap) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader)

Example 7 with ClasspathResourceLoader

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

the class TestMorfologikFilterFactory method testExplicitDictionary.

public void testExplicitDictionary() throws Exception {
    final ResourceLoader loader = new ClasspathResourceLoader(TestMorfologikFilterFactory.class);
    StringReader reader = new StringReader("inflected1 inflected2");
    Map<String, String> params = new HashMap<>();
    params.put(MorfologikFilterFactory.DICTIONARY_ATTRIBUTE, "custom-dictionary.dict");
    MorfologikFilterFactory factory = new MorfologikFilterFactory(params);
    factory.inform(loader);
    TokenStream stream = whitespaceMockTokenizer(reader);
    stream = factory.create(stream);
    assertTokenStreamContents(stream, new String[] { "lemma1", "lemma2" });
}
Also used : ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader) ResourceLoader(org.apache.lucene.analysis.util.ResourceLoader) TokenStream(org.apache.lucene.analysis.TokenStream) HashMap(java.util.HashMap) StringReader(java.io.StringReader) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader)

Example 8 with ClasspathResourceLoader

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

the class TestPhoneticFilterFactory method testFactoryDefaults.

/**
   * 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);
    // 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 9 with ClasspathResourceLoader

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

the class TestPhoneticFilterFactory method testUnknownEncoder.

public void testUnknownEncoder() throws IOException {
    IllegalArgumentException expected = expectThrows(IllegalArgumentException.class, () -> {
        Map<String, String> args = new HashMap<>();
        args.put("encoder", "XXX");
        PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
        factory.inform(new ClasspathResourceLoader(factory.getClass()));
    });
    assertTrue(expected.getMessage().contains("Error loading encoder"));
}
Also used : HashMap(java.util.HashMap) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader)

Example 10 with ClasspathResourceLoader

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

the class TestPhoneticFilterFactory method assertAlgorithm.

static void assertAlgorithm(String algName, String inject, String input, String[] expected) throws Exception {
    Tokenizer tokenizer = whitespaceMockTokenizer(input);
    Map<String, String> args = new HashMap<>();
    args.put("encoder", algName);
    args.put("inject", inject);
    PhoneticFilterFactory factory = new PhoneticFilterFactory(args);
    factory.inform(new ClasspathResourceLoader(factory.getClass()));
    TokenStream stream = factory.create(tokenizer);
    assertTokenStreamContents(stream, expected);
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) HashMap(java.util.HashMap) ClasspathResourceLoader(org.apache.lucene.analysis.util.ClasspathResourceLoader) Tokenizer(org.apache.lucene.analysis.Tokenizer)

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