This repository has been archived on 2023-06-09. You can view files and clone it, but cannot push or open issues or pull requests.
jarvis-server/jarvis/utils/nlp_utils.py

24 lines
599 B
Python
Raw Normal View History

import spacy
from jarvis.utils import languages_utils
2021-07-27 18:07:04 +02:00
nlp = None
def get_spacy_nlp():
2021-07-27 18:07:04 +02:00
global nlp
if nlp is None:
2021-07-27 18:07:51 +02:00
print("A Spacy model is starting, it might take a few seconds (starts only once)")
2021-07-27 18:07:04 +02:00
nlp = spacy.load(languages_utils.get_spacy_model())
return nlp
def get_text_without_stopwords(sentence):
stopwords_spacy = get_spacy_nlp().Defaults.stop_words
stop_words = set(stopwords_spacy)
filtered_sentence = [w for w in sentence.lower().split() if w not in stop_words]
filtered_sentence = " ".join(filtered_sentence)
return filtered_sentence