-
Notifications
You must be signed in to change notification settings - Fork 111
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1551 from vespa-engine/andreer/stopword-removal
remove stopwords
- Loading branch information
Showing
4 changed files
with
459 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import spacy | ||
import os | ||
|
||
# Download the model if it is not already present | ||
if not spacy.util.is_package("en_core_web_sm"): | ||
spacy.cli.download("en_core_web_sm") | ||
nlp = spacy.load("en_core_web_sm") | ||
|
||
# It would be possible to remove bolding for stopwords without removing them from the query, | ||
# but that would require a java plugin which we didn't want to complicate this sample app with. | ||
def filter(text): | ||
doc = nlp(text) | ||
tokens = [token.text for token in doc if not token.is_stop] | ||
if len(tokens) == 0: | ||
# if we remove all the words we don't have a query at all, so use the original | ||
return text | ||
return " ".join(tokens) |
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
Oops, something went wrong.