Async release
This commit is contained in:
28
app/helpers/text_helper.py
Normal file
28
app/helpers/text_helper.py
Normal file
@@ -0,0 +1,28 @@
|
||||
from nltk.corpus import words
|
||||
|
||||
|
||||
class TextHelper:
|
||||
|
||||
@classmethod
|
||||
def has_words(cls, text: str):
|
||||
if not cls._has_common_words(text):
|
||||
return False
|
||||
english_words = set(words.words())
|
||||
words_in_input = text.split()
|
||||
return any(word.lower() in english_words for word in words_in_input)
|
||||
|
||||
@classmethod
|
||||
def has_x_words(cls, text: str, quantity):
|
||||
if not cls._has_common_words(text):
|
||||
return False
|
||||
english_words = set(words.words())
|
||||
words_in_input = text.split()
|
||||
english_word_count = sum(1 for word in words_in_input if word.lower() in english_words)
|
||||
return english_word_count >= quantity
|
||||
|
||||
@staticmethod
|
||||
def _has_common_words(text: str):
|
||||
english_words = {"the", "be", "to", "of", "and", "a", "in", "that", "have", "i"}
|
||||
words_in_input = text.split()
|
||||
english_word_count = sum(1 for word in words_in_input if word.lower() in english_words)
|
||||
return english_word_count >= 10
|
||||
Reference in New Issue
Block a user