zeeguu/core/language/strategies/frequency_difficulty_estimator.py
def estimate_difficulty(self, text: str):
        """
        This estimator computes the difficulty based on how often words in the text are used in the given language
        :param text: See DifficultyEstimatorStrategy
        :param language: See DifficultyEstimatorStrategy
        :param user: See DifficultyEstimatorStrategy
        :rtype: dict
        :return: The dictionary contains the keys and return types
                    normalized: float (0<=normalized<=1)
                    discrete: string [EASY, MEDIUM, HARD]
        """
        # Calculate difficulty for each word
        words = split_words_from_text(text)

        stemmer = SnowballStemmer(self.language.name.lower())
        words = [stemmer.stem(w.lower()) for w in words]

        words_freq = defaultdict(int)
        total_words = 0
        for w in words:
            total_words += 1
            words_freq[w] += 1

        word_scores = [self.word_difficulty(self.score_map, True, w) * (words_freq[w] / total_words) for w in
                       words_freq.keys()]

        # If we can't compute the text difficulty, we estimate hard
        if (len(word_scores)) == 0:
            normalized_estimate = 1.00
            words_new = 1.00
            discrete_difficulty = "HARD"
        else:
            # Median difficulty is used for discretization
            word_scores.sort()
            center = int(round(len(word_scores) / 2, 0))
            difficulty_median = word_scores[center]

            normalized_estimate = sum(word_scores)
            discrete_difficulty = self.discrete_text_difficulty(difficulty_median)

        difficulty_scores = dict(
            normalized=normalized_estimate,  # Originally called 'score_average'
            discrete=discrete_difficulty  # Originally called 'estimated_difficulty'
        )

        return difficulty_scores

        This estimator computes the difficulty based on how often words in the text are used in the given language
        :param text: See DifficultyEstimatorStrategy
        :param language: See DifficultyEstimatorStrategy
        :param user: See DifficultyEstimatorStrategy
        :rtype: dict
        :return: The dictionary contains the keys and return types
                    normalized: float (0<=normalized<=1)
                    discrete: string [EASY, MEDIUM, HARD]
        
This estimator computes the difficulty based on how often words in the text are used in the given language
This estimator computes the difficulty based on how often words in the text are used in the given language
def estimate_difficulty(self, text: str):
        words = split_words_from_text(text)
        stemmer = SnowballStemmer(self.language.name.lower())
        words = [stemmer.stem(w.lower()) for w in words]
        words_freq = defaultdict(int)
        total_words = 0
        for w in words:
            total_words += 1
            words_freq[w] += 1
        word_scores = [self.word_difficulty(self.score_map, True, w) * (words_freq[w] / total_words) for w in
                       words_freq.keys()]
        if (len(word_scores)) == 0:
            normalized_estimate = 1.00
            words_new = 1.00
            discrete_difficulty = "HARD"
        else:
            word_scores.sort()
            center = int(round(len(word_scores) / 2, 0))
            difficulty_median = word_scores[center]
            normalized_estimate = sum(word_scores)
            discrete_difficulty = self.discrete_text_difficulty(difficulty_median)
        difficulty_scores = dict(
            normalized=normalized_estimate,  
            discrete=discrete_difficulty  
        )
        return difficulty_scores
def estimate_difficulty ( self , text : str ) : words = split_words_from_text ( text ) stemmer = SnowballStemmer ( self . language . name . lower ( ) ) words = [ stemmer . stem ( w . lower ( ) ) for w in words ] words_freq = defaultdict ( int ) total_words = 0 for w in words : total_words += 1 words_freq [ w ] += 1 word_scores = [ self . word_difficulty ( self . score_map , True , w ) * ( words_freq [ w ] / total_words ) for w in words_freq . keys ( ) ] if ( len ( word_scores ) ) == 0 : normalized_estimate = 1.00 words_new = 1.00 discrete_difficulty = "HARD" else : word_scores . sort ( ) center = int ( round ( len ( word_scores ) / 2 , 0 ) ) difficulty_median = word_scores [ center ] normalized_estimate = sum ( word_scores ) discrete_difficulty = self . discrete_text_difficulty ( difficulty_median ) difficulty_scores = dict ( normalized = normalized_estimate , discrete = discrete_difficulty ) return difficulty_scores
This estimator computes the difficulty based on how often words in the text are used in the given language
This estimator computes the difficulty based on how often words in the text are used in the given language
"""
        This estimator computes the difficulty based on how often words in the text are used in the given language
        :param text: See DifficultyEstimatorStrategy
        :param language: See DifficultyEstimatorStrategy
        :param user: See DifficultyEstimatorStrategy
        :rtype: dict
        :return: The dictionary contains the keys and return types
                    normalized: float (0<=normalized<=1)
                    discrete: string [EASY, MEDIUM, HARD]
        """ # Calculate difficulty for each word # If we can't compute the text difficulty, we estimate hard # Median difficulty is used for discretization # Originally called 'score_average' # Originally called 'estimated_difficulty'
The dictionary contains the keys and return types
normalized: float (0<=normalized<=1)
discrete: string [EASY, MEDIUM, HARD]
The dictionary contains the keys and return types normalized : float ( 0< = normalized< = 1 ) discrete : string [ EASY MEDIUM HARD ]
dict
self
text
str
None
language
None
user
None