another refinement to the ongoing StopFilter refactorings

git-svn-id: https://svn.apache.org/repos/asf/lucene/java/trunk@150227 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Erik Hatcher 2004-03-10 09:59:57 +00:00
parent 3c93b62676
commit 8d7ce21934
1 changed files with 7 additions and 7 deletions

View File

@ -65,7 +65,7 @@ import java.util.Set;
public final class StopFilter extends TokenFilter { public final class StopFilter extends TokenFilter {
private Set table; private Set stopWords;
/** /**
* Constructs a filter which removes words from the input * Constructs a filter which removes words from the input
@ -73,7 +73,7 @@ public final class StopFilter extends TokenFilter {
*/ */
public StopFilter(TokenStream in, String[] stopWords) { public StopFilter(TokenStream in, String[] stopWords) {
super(in); super(in);
table = makeStopSet(stopWords); this.stopWords = makeStopSet(stopWords);
} }
/** /**
@ -84,16 +84,16 @@ public final class StopFilter extends TokenFilter {
*/ */
public StopFilter(TokenStream in, Hashtable stopTable) { public StopFilter(TokenStream in, Hashtable stopTable) {
super(in); super(in);
table = stopTable.keySet(); stopWords = new HashSet(stopTable.keySet());
} }
/** /**
* Constructs a filter which removes words from the input * Constructs a filter which removes words from the input
* TokenStream that are named in the Set. * TokenStream that are named in the Set.
*/ */
public StopFilter(TokenStream in, Set stopTable) { public StopFilter(TokenStream in, Set stopWords) {
super(in); super(in);
table = stopTable; this.stopWords = new HashSet(stopWords);
} }
/** /**
@ -114,7 +114,7 @@ public final class StopFilter extends TokenFilter {
/** /**
* Builds a Set from an array of stop words, * Builds a Set from an array of stop words,
* appropriate for passing into the StopFilter constructor. * appropriate for passing into the StopFilter constructor.
* This permits this table construction to be cached once when * This permits this stopWords construction to be cached once when
* an Analyzer is constructed. * an Analyzer is constructed.
*/ */
public static final Set makeStopSet(String[] stopWords) { public static final Set makeStopSet(String[] stopWords) {
@ -130,7 +130,7 @@ public final class StopFilter extends TokenFilter {
public final Token next() throws IOException { public final Token next() throws IOException {
// return the first non-stop word found // return the first non-stop word found
for (Token token = input.next(); token != null; token = input.next()) for (Token token = input.next(); token != null; token = input.next())
if (!table.contains(token.termText)) if (!stopWords.contains(token.termText))
return token; return token;
// reached EOS -- return null // reached EOS -- return null
return null; return null;