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;
}
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" });
}
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" });
}
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" });
}
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" });
}
Aggregations