29 lines
1.0 KiB
Python
29 lines
1.0 KiB
Python
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
|