This file contains hidden or 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
from textblob import TextBlob | |
from nltk.stem.porter import PorterStemmer | |
def _extract_ngrams(data: str, num: int): | |
n_grams = TextBlob(data).ngrams(num) | |
return [' '.join(grams).lower() for grams in n_grams] | |
def _delete_duplicate_food_n_grams(text: str, foods: List[str]) -> List[str]: | |
foods.sort(key=lambda x: -len(x.split())) # Sort desc by number of words | |
result_foods = [] |