def set_default_encounter_based_prob(): zeeguu.app.test_request_context().push() zeeguu.db.session.commit() default_probability = 0.5 languages = Language.all() users = User.find_all() for user in users: for lang in languages: marked_words_of_user_in_text = [] words_of_all_bookmarks_content = [] for bookmark in Bookmark.find_by_specific_user(user): if bookmark.origin.language == lang: # bookmark_content_words = re.sub("[^\w]", " ", bookmark.text.content).split() bookmark_content_words = re.findall(r'(?u)\w+', bookmark.text.content) words_of_all_bookmarks_content.extend(bookmark_content_words) marked_words_of_user_in_text.append(bookmark.origin.word) words_known_from_user= [word for word in words_of_all_bookmarks_content if word not in marked_words_of_user_in_text] for word_known in words_known_from_user: if RankedWord.exists(word_known, lang): rank = RankedWord.find(word_known, lang) if EncounterBasedProbability.exists(user, rank): prob = EncounterBasedProbability.find(user,rank, default_probability) prob.not_looked_up_counter +=1 else: prob = EncounterBasedProbability.find(user,rank,default_probability) zeeguu.db.session.add(prob) zeeguu.db.session.commit() print 'job2'
def set_default_encounter_based_prob(): zeeguu.app.test_request_context().push() zeeguu.db.session.commit() default_probability = 0.5 languages = Language.all() users = User.find_all() for user in users: for lang in languages: marked_words_of_user_in_text = [] words_of_all_bookmarks_content = [] for bookmark in Bookmark.find_by_specific_user(user): if bookmark.origin.language == lang: # bookmark_content_words = re.sub("[^\w]", " ", bookmark.text.content).split() bookmark_content_words = re.findall( r'(?u)\w+', bookmark.text.content) words_of_all_bookmarks_content.extend( bookmark_content_words) marked_words_of_user_in_text.append(bookmark.origin.word) words_known_from_user = [ word for word in words_of_all_bookmarks_content if word not in marked_words_of_user_in_text ] for word_known in words_known_from_user: if RankedWord.exists(word_known, lang): rank = RankedWord.find(word_known, lang) if EncounterBasedProbability.exists(user, rank): prob = EncounterBasedProbability.find( user, rank, default_probability) prob.not_looked_up_counter += 1 else: prob = EncounterBasedProbability.find( user, rank, default_probability) zeeguu.db.session.add(prob) zeeguu.db.session.commit() print 'job2'
def set_default_exercise_based_prob(): zeeguu.app.test_request_context().push() zeeguu.db.session.commit() users = User.find_all() languages = Language.all() for user in users: for language in languages: user_words_by_language = UserWord.find_by_language(language) for word in user_words_by_language: if ExerciseBasedProbability.exists(user, word): prob = ExerciseBasedProbability.find(user, word) bookmarks_by_user_and_word = Bookmark.find_all_by_user_and_word( user, word) total_prob = 0 for bookmark in bookmarks_by_user_and_word: prob.calculate_known_bookmark_probability(bookmark) total_prob += float(prob.probability) if bookmarks_by_user_and_word: prob.probability = total_prob / len( bookmarks_by_user_and_word) zeeguu.db.session.commit() print('job1')