forked from castorini/anserini
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow stopwords to be configured at search time (castorini#1473)
Stopwords can currently be configured at index-time. This PR adds support for specifying stopwords at search-time as well. This is helpful because generally the same stopwords are used at both index and search time. If the stopword 'where' is dropped from the index but still included in searches, then a search for 'where' only matches words with the same stem like 'wheres'. This is tricky behavior and usually undesirable.
- Loading branch information
1 parent
d7ad388
commit 8d7c517
Showing
7 changed files
with
113 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/test/java/io/anserini/analysis/DefaultEnglishAnalyzerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/* | ||
* Anserini: A Lucene toolkit for replicable information retrieval research | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package io.anserini.analysis; | ||
|
||
import org.apache.lucene.analysis.CharArraySet; | ||
import org.apache.lucene.analysis.en.EnglishAnalyzer; | ||
import org.junit.Test; | ||
|
||
import java.util.Arrays; | ||
|
||
import static io.anserini.analysis.DefaultEnglishAnalyzer.fromArguments; | ||
import static org.junit.Assert.assertEquals; | ||
|
||
public class DefaultEnglishAnalyzerTest { | ||
|
||
@Test | ||
public void testKeepStopwords() throws Exception { | ||
DefaultEnglishAnalyzer defaultAnalyzer = fromArguments("porter", false, null); | ||
assertEquals(EnglishAnalyzer.getDefaultStopSet(), defaultAnalyzer.getStopwordSet()); | ||
|
||
DefaultEnglishAnalyzer analyzer = fromArguments("porter", true, null); | ||
assertEquals(CharArraySet.EMPTY_SET, analyzer.getStopwordSet()); | ||
} | ||
|
||
@Test | ||
public void testStopwordsLoading() throws Exception { | ||
DefaultEnglishAnalyzer analyzer = fromArguments("porter", false, "src/test/resources/test-stopwords.txt"); | ||
CharArraySet expectedStopwords = new CharArraySet(Arrays.asList("some", "very", "common", "words"), false); | ||
assertEquals(expectedStopwords, analyzer.getStopwordSet()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
some | ||
very | ||
common | ||
words |