zeeguu/core/language/strategies/word_history_difficulty_estimator.py
def difficulty(cls, language: 'model.Language', user: 'model.User', mode = 1):
        """
                This estimator computes the ratio of new words for a given user and language
                :param language: language of the text that needs to be estimated
                :param user: the user for which the difficulty estimation needs to be done
                :rtype: WordHistoryDifficultyEstimator
                :return: WordHistoryDifficultyEstimator with initialized user, language and word => score map
                        which can be used for determining scores for multiple articles for the same user and language
        """

        estimator = cls(language, user)

        # determine word scores
        words_history = WordInteractionHistory.find_all_word_histories_for_user_language(user, language)

        words_found = [w.word.word for w in words_history]
        event_history = [w.interaction_history for w in words_history]

        words_score = []

        if mode == 1:

            for e in event_history:
                if len(e) > 10:
                    words_score.append(0)
                else:
                    N_seen_context = sum([event == WIH_READ_NOT_CLICKED_IN_SENTENCE for event in event_history])
                    N_seen = sum([event == WIH_READ_NOT_CLICKED_OUT_SENTENCE for event in event_history])
                    # N_clicked = sum([event == WIH_READ_CLICKED for event in event_history])

                    if N_seen_context > 3 or N_seen > 6:
                        words_score.append(0)
                    else:
                        words_score.append(min(1 - N_seen_context / 4, 1 - N_seen / 7))
        elif mode == 2:
            for e in event_history:
                words_score.append(max(1 - len(e)/10,0))

        elif mode == 3:
            length = 0
            for e in event_history[::-1]:
                if e is not WIH_READ_CLICKED or e is not WIH_WRONG_EX_CHOICE or e is not WIH_WRONG_EX_MATCH or e is not WIH_WRONG_EX_RECOGNIZE or\
                    e is not WIH_WRONG_EX_TRANSLATE:
                    length += 1
                words_score.append(max(1 - len(e)/10,0))

        estimator.score_map = dict(zip(words_found, words_score))

        return estimator

                This estimator computes the ratio of new words for a given user and language
                :param language: language of the text that needs to be estimated
                :param user: the user for which the difficulty estimation needs to be done
                :rtype: WordHistoryDifficultyEstimator
                :return: WordHistoryDifficultyEstimator with initialized user, language and word => score map
                        which can be used for determining scores for multiple articles for the same user and language
        
This estimator computes the ratio of new words for a given user and language
This estimator computes the ratio of new words for a given user and language
def difficulty(cls, language: 'model.Language', user: 'model.User', mode = 1):
        estimator = cls(language, user)
        words_history = WordInteractionHistory.find_all_word_histories_for_user_language(user, language)
        words_found = [w.word.word for w in words_history]
        event_history = [w.interaction_history for w in words_history]
        words_score = []
        if mode == 1:
            for e in event_history:
                if len(e) > 10:
                    words_score.append(0)
                else:
                    N_seen_context = sum([event == WIH_READ_NOT_CLICKED_IN_SENTENCE for event in event_history])
                    N_seen = sum([event == WIH_READ_NOT_CLICKED_OUT_SENTENCE for event in event_history])
                    if N_seen_context > 3 or N_seen > 6:
                        words_score.append(0)
                    else:
                        words_score.append(min(1 - N_seen_context / 4, 1 - N_seen / 7))
        elif mode == 2:
            for e in event_history:
                words_score.append(max(1 - len(e)/10,0))
        elif mode == 3:
            length = 0
            for e in event_history[::-1]:
                if e is not WIH_READ_CLICKED or e is not WIH_WRONG_EX_CHOICE or e is not WIH_WRONG_EX_MATCH or e is not WIH_WRONG_EX_RECOGNIZE or\
                    e is not WIH_WRONG_EX_TRANSLATE:
                    length += 1
                words_score.append(max(1 - len(e)/10,0))
        estimator.score_map = dict(zip(words_found, words_score))
        return estimator
def difficulty ( cls , language : 'model.Language' , user : 'model.User' , mode = 1 ) : estimator = cls ( language , user ) words_history = WordInteractionHistory . find_all_word_histories_for_user_language ( user , language ) words_found = [ w . word . word for w in words_history ] event_history = [ w . interaction_history for w in words_history ] words_score = [ ] if mode == 1 : for e in event_history : if len ( e ) > 10 : words_score . append ( 0 ) else : N_seen_context = sum ( [ event == WIH_READ_NOT_CLICKED_IN_SENTENCE for event in event_history ] ) N_seen = sum ( [ event == WIH_READ_NOT_CLICKED_OUT_SENTENCE for event in event_history ] ) if N_seen_context > 3 or N_seen > 6 : words_score . append ( 0 ) else : words_score . append ( min ( 1 - N_seen_context / 4 , 1 - N_seen / 7 ) ) elif mode == 2 : for e in event_history : words_score . append ( max ( 1 - len ( e ) / 10 , 0 ) ) elif mode == 3 : length = 0 for e in event_history [ : : - 1 ] : if e is not WIH_READ_CLICKED or e is not WIH_WRONG_EX_CHOICE or e is not WIH_WRONG_EX_MATCH or e is not WIH_WRONG_EX_RECOGNIZE or e is not WIH_WRONG_EX_TRANSLATE : length += 1 words_score . append ( max ( 1 - len ( e ) / 10 , 0 ) ) estimator . score_map = dict ( zip ( words_found , words_score ) ) return estimator
This estimator computes the ratio of new words for a given user and language
This estimator computes the ratio of new words for a given user and language
"""
                This estimator computes the ratio of new words for a given user and language
                :param language: language of the text that needs to be estimated
                :param user: the user for which the difficulty estimation needs to be done
                :rtype: WordHistoryDifficultyEstimator
                :return: WordHistoryDifficultyEstimator with initialized user, language and word => score map
                        which can be used for determining scores for multiple articles for the same user and language
        """ # determine word scores # N_clicked = sum([event == WIH_READ_CLICKED for event in event_history])
WordHistoryDifficultyEstimator with initialized user, language and word => score map
which can be used for determining scores for multiple articles for the same user and language
WordHistoryDifficultyEstimator with initialized user language and word = > score map which can be used for determining scores for multiple articles for the same user and language
WordHistoryDifficultyEstimator
cls
language
'model.Language'
language of the text that needs to be estimated
language of the text that needs to be estimated
user
'model.User'
the user for which the difficulty estimation needs to be done
the user for which the difficulty estimation needs to be done
mode