zeeguu/core/language/strategies/word_history_difficulty_estimator.py
def difficulty_until_timestamp(cls, language: 'model.Language', user: 'model.User', max_timestamp, mode = 1, scaling = 10.0, scaling2 = 20.0):
        """
                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 = []
        event_history = []
        for wh in words_history:
            history = [event for event in wh.interaction_history if event.seconds_since_epoch <= max_timestamp]

            if history:
                words_found.append(wh.word.word)
                event_history.append(history)

        words_score = []

        if mode == 1:

            for e in event_history:
                N_seen_context = sum([event.event_type == WIH_READ_NOT_CLICKED_IN_SENTENCE for event in e])
                N_seen = sum([event.event_type == WIH_READ_NOT_CLICKED_OUT_SENTENCE for event in e])
                # N_clicked = sum([event == WIH_READ_CLICKED for event in event_history])

                words_score.append(max(0,1 - N_seen_context / scaling - N_seen / scaling2))
        elif mode == 2:
            for e in event_history:
                words_score.append(max(1 - len(e)/scaling,0))

        elif mode == 3:
            length = 0
            for e in event_history:
                events= e[::-1]
                for event in events:
                    if event.event_type is not WIH_READ_CLICKED or event.event_type is not WIH_WRONG_EX_CHOICE or event.event_type is not WIH_WRONG_EX_MATCH or event.event_type is not WIH_WRONG_EX_RECOGNIZE or \
                            event.event_type is not WIH_WRONG_EX_TRANSLATE:
                        length += 1
                words_score.append(max(1 - len(e)/scaling,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_until_timestamp(cls, language: 'model.Language', user: 'model.User', max_timestamp, mode = 1, scaling = 10.0, scaling2 = 20.0):
        estimator = cls(language, user)
        words_history = WordInteractionHistory.find_all_word_histories_for_user_language(user, language)
        words_found = []
        event_history = []
        for wh in words_history:
            history = [event for event in wh.interaction_history if event.seconds_since_epoch <= max_timestamp]
            if history:
                words_found.append(wh.word.word)
                event_history.append(history)
        words_score = []
        if mode == 1:
            for e in event_history:
                N_seen_context = sum([event.event_type == WIH_READ_NOT_CLICKED_IN_SENTENCE for event in e])
                N_seen = sum([event.event_type == WIH_READ_NOT_CLICKED_OUT_SENTENCE for event in e])
                words_score.append(max(0,1 - N_seen_context / scaling - N_seen / scaling2))
        elif mode == 2:
            for e in event_history:
                words_score.append(max(1 - len(e)/scaling,0))
        elif mode == 3:
            length = 0
            for e in event_history:
                events= e[::-1]
                for event in events:
                    if event.event_type is not WIH_READ_CLICKED or event.event_type is not WIH_WRONG_EX_CHOICE or event.event_type is not WIH_WRONG_EX_MATCH or event.event_type is not WIH_WRONG_EX_RECOGNIZE or \
                            event.event_type is not WIH_WRONG_EX_TRANSLATE:
                        length += 1
                words_score.append(max(1 - len(e)/scaling,0))
        estimator.score_map = dict(zip(words_found, words_score))
        return estimator
def difficulty_until_timestamp ( cls , language : 'model.Language' , user : 'model.User' , max_timestamp , mode = 1 , scaling = 10.0 , scaling2 = 20.0 ) : estimator = cls ( language , user ) words_history = WordInteractionHistory . find_all_word_histories_for_user_language ( user , language ) words_found = [ ] event_history = [ ] for wh in words_history : history = [ event for event in wh . interaction_history if event . seconds_since_epoch <= max_timestamp ] if history : words_found . append ( wh . word . word ) event_history . append ( history ) words_score = [ ] if mode == 1 : for e in event_history : N_seen_context = sum ( [ event . event_type == WIH_READ_NOT_CLICKED_IN_SENTENCE for event in e ] ) N_seen = sum ( [ event . event_type == WIH_READ_NOT_CLICKED_OUT_SENTENCE for event in e ] ) words_score . append ( max ( 0 , 1 - N_seen_context / scaling - N_seen / scaling2 ) ) elif mode == 2 : for e in event_history : words_score . append ( max ( 1 - len ( e ) / scaling , 0 ) ) elif mode == 3 : length = 0 for e in event_history : events = e [ : : - 1 ] for event in events : if event . event_type is not WIH_READ_CLICKED or event . event_type is not WIH_WRONG_EX_CHOICE or event . event_type is not WIH_WRONG_EX_MATCH or event . event_type is not WIH_WRONG_EX_RECOGNIZE or event . event_type is not WIH_WRONG_EX_TRANSLATE : length += 1 words_score . append ( max ( 1 - len ( e ) / scaling , 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
max_timestamp
mode
scaling
scaling2