Search in sources :

Example 1 with StringMockResourceLoader

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

the class TestFactories method initialize.

/** tries to initialize a factory with no arguments */
private AbstractAnalysisFactory initialize(Class<? extends AbstractAnalysisFactory> factoryClazz) throws IOException {
    Map<String, String> args = new HashMap<>();
    args.put("luceneMatchVersion", Version.LATEST.toString());
    Constructor<? extends AbstractAnalysisFactory> ctor;
    try {
        ctor = factoryClazz.getConstructor(Map.class);
    } catch (Exception e) {
        throw new RuntimeException("factory '" + factoryClazz + "' does not have a proper ctor!");
    }
    AbstractAnalysisFactory factory = null;
    try {
        factory = ctor.newInstance(args);
    } catch (InstantiationException | IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InvocationTargetException e) {
        if (e.getCause() instanceof IllegalArgumentException) {
            // it's ok if we dont provide the right parameters to throw this
            return null;
        }
    }
    if (factory instanceof ResourceLoaderAware) {
        try {
            ((ResourceLoaderAware) factory).inform(new StringMockResourceLoader(""));
        } catch (IOException ignored) {
        // it's ok if the right files arent available or whatever to throw this
        } catch (IllegalArgumentException ignored) {
        // is this ok? I guess so
        }
    }
    return factory;
}
Also used : HashMap(java.util.HashMap) IOException(java.io.IOException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InvocationTargetException(java.lang.reflect.InvocationTargetException) ResourceLoaderAware(org.apache.lucene.analysis.util.ResourceLoaderAware) AbstractAnalysisFactory(org.apache.lucene.analysis.util.AbstractAnalysisFactory) HashMap(java.util.HashMap) Map(java.util.Map) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader)

Example 2 with StringMockResourceLoader

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

the class TestSnowballPorterFilterFactory method testProtected.

/**
   * Test the protected words mechanism of SnowballPorterFilterFactory
   */
public void testProtected() throws Exception {
    Reader reader = new StringReader("ridding of some stemming");
    TokenStream stream = whitespaceMockTokenizer(reader);
    stream = tokenFilterFactory("SnowballPorter", Version.LATEST, new StringMockResourceLoader("ridding"), "protected", "protwords.txt", "language", "English").create(stream);
    assertTokenStreamContents(stream, new String[] { "ridding", "of", "some", "stem" });
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader)

Example 3 with StringMockResourceLoader

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

the class TestMultiWordSynonyms method testMultiWordSynonyms.

public void testMultiWordSynonyms() throws Exception {
    Reader reader = new StringReader("a e");
    TokenStream stream = whitespaceMockTokenizer(reader);
    stream = tokenFilterFactory("Synonym", Version.LATEST, new StringMockResourceLoader("a b c,d"), "synonyms", "synonyms.txt").create(stream);
    // This fails because ["e","e"] is the value of the token stream
    assertTokenStreamContents(stream, new String[] { "a", "e" });
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader)

Example 4 with StringMockResourceLoader

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

the class TestKeywordMarkerFilterFactory method testKeywordsCaseInsensitive.

public void testKeywordsCaseInsensitive() throws Exception {
    Reader reader = new StringReader("dogs cats Cats");
    TokenStream stream = whitespaceMockTokenizer(reader);
    stream = tokenFilterFactory("KeywordMarker", Version.LATEST, new StringMockResourceLoader("cats"), "protected", "protwords.txt", "ignoreCase", "true").create(stream);
    stream = tokenFilterFactory("PorterStem").create(stream);
    assertTokenStreamContents(stream, new String[] { "dog", "cats", "Cats" });
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader)

Example 5 with StringMockResourceLoader

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

the class TestStemmerOverrideFilterFactory method testKeywordsCaseInsensitive.

public void testKeywordsCaseInsensitive() throws Exception {
    Reader reader = new StringReader("testing DoGs");
    TokenStream stream = whitespaceMockTokenizer(reader);
    stream = tokenFilterFactory("StemmerOverride", Version.LATEST, new StringMockResourceLoader("dogs\tcat"), "dictionary", "stemdict.txt", "ignoreCase", "true").create(stream);
    stream = tokenFilterFactory("PorterStem").create(stream);
    assertTokenStreamContents(stream, new String[] { "test", "cat" });
}
Also used : TokenStream(org.apache.lucene.analysis.TokenStream) StringReader(java.io.StringReader) StringReader(java.io.StringReader) Reader(java.io.Reader) StringMockResourceLoader(org.apache.lucene.analysis.util.StringMockResourceLoader)

Aggregations

StringMockResourceLoader (org.apache.lucene.analysis.util.StringMockResourceLoader)11 Reader (java.io.Reader)9 StringReader (java.io.StringReader)9 TokenStream (org.apache.lucene.analysis.TokenStream)9 Collator (com.ibm.icu.text.Collator)1 RuleBasedCollator (com.ibm.icu.text.RuleBasedCollator)1 ULocale (com.ibm.icu.util.ULocale)1 File (java.io.File)1 FileOutputStream (java.io.FileOutputStream)1 IOException (java.io.IOException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 AbstractAnalysisFactory (org.apache.lucene.analysis.util.AbstractAnalysisFactory)1 FilesystemResourceLoader (org.apache.lucene.analysis.util.FilesystemResourceLoader)1 ResourceLoader (org.apache.lucene.analysis.util.ResourceLoader)1 ResourceLoaderAware (org.apache.lucene.analysis.util.ResourceLoaderAware)1