Spaces:
Runtime error
Runtime error
File size: 651 Bytes
7c88df9 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
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)
|