LUCENE-2510: fix more factory arg bugs found by TestFactories

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/branches/lucene2510@1365426 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Robert Muir 2012-07-25 03:33:29 +00:00
parent 862dd75357
commit d58041803c
4 changed files with 20 additions and 5 deletions

View File

@ -39,6 +39,9 @@ import org.apache.lucene.analysis.util.TokenizerFactory;
* we do our best to see if we can sanely initialize it with
* no parameters and smoke test it, etc.
*/
// TODO: move this, TestRandomChains, and TestAllAnalyzersHaveFactories
// to an integration test module that sucks in all analysis modules.
// currently the only way to do this is via eclipse etc (LUCENE-3974)
public class TestFactories extends BaseTokenStreamTestCase {
public void test() throws IOException {
for (String tokenizer : TokenizerFactory.availableTokenizers()) {

View File

@ -45,12 +45,15 @@ public class JapanesePartOfSpeechStopFilterFactory extends TokenFilterFactory im
public void inform(ResourceLoader loader) {
String stopTagFiles = args.get("tags");
enablePositionIncrements = getBoolean("enablePositionIncrements", false);
stopTags = null;
try {
CharArraySet cas = getWordSet(loader, stopTagFiles, false);
stopTags = new HashSet<String>();
for (Object element : cas) {
char chars[] = (char[]) element;
stopTags.add(new String(chars));
if (cas != null) {
stopTags = new HashSet<String>();
for (Object element : cas) {
char chars[] = (char[]) element;
stopTags.add(new String(chars));
}
}
} catch (IOException e) {
throw new InitializationException("IOException thrown while loading tags", e);
@ -58,6 +61,7 @@ public class JapanesePartOfSpeechStopFilterFactory extends TokenFilterFactory im
}
public TokenStream create(TokenStream stream) {
return new JapanesePartOfSpeechStopFilter(enablePositionIncrements, stream, stopTags);
// if stoptags is null, it means the file is empty
return stopTags == null ? stream : new JapanesePartOfSpeechStopFilter(enablePositionIncrements, stream, stopTags);
}
}

View File

@ -18,6 +18,7 @@ package org.apache.lucene.analysis.uima;
*/
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.util.InitializationException;
import org.apache.lucene.analysis.util.TokenizerFactory;
import org.apache.lucene.analysis.uima.UIMAAnnotationsTokenizer;
@ -37,6 +38,9 @@ public class UIMAAnnotationsTokenizerFactory extends TokenizerFactory {
super.init(args);
descriptorPath = args.get("descriptorPath");
tokenType = args.get("tokenType");
if (descriptorPath == null || tokenType == null) {
throw new InitializationException("Both descriptorPath and tokenType are mandatory");
}
}
@Override

View File

@ -19,6 +19,7 @@ package org.apache.lucene.analysis.uima;
import org.apache.lucene.analysis.Tokenizer;
import org.apache.lucene.analysis.uima.UIMATypeAwareAnnotationsTokenizer;
import org.apache.lucene.analysis.util.InitializationException;
import org.apache.lucene.analysis.util.TokenizerFactory;
import java.io.Reader;
@ -39,6 +40,9 @@ public class UIMATypeAwareAnnotationsTokenizerFactory extends TokenizerFactory {
descriptorPath = args.get("descriptorPath");
tokenType = args.get("tokenType");
featurePath = args.get("featurePath");
if (descriptorPath == null || tokenType == null || featurePath == null) {
throw new InitializationException("descriptorPath, tokenType, and featurePath are mandatory");
}
}
@Override