def set_know_word_prob():
    zeeguu.app.test_request_context().push()
    zeeguu.db.session.commit()
    enc_probs = EncounterBasedProbability.find_all()
    ex_probs = ExerciseBasedProbability.find_all()
    for prob in enc_probs:
        user = prob.user
        word = prob.ranked_word.word
        language = prob.ranked_word.language
        user_word = None
        if UserWord.exists(word, language):
            user_word = UserWord.find(word, language)
        if ExerciseBasedProbability.exists(user, user_word):
            ex_prob = ExerciseBasedProbability.find(user, user_word)
            known_word_prob = KnownWordProbability.calculateKnownWordProb(ex_prob.probability, prob.probability)
            known_word_probability_obj = KnownWordProbability.find(user, user_word, prob.ranked_word, known_word_prob)
        else:
            known_word_probability_obj = KnownWordProbability.find(user, None, prob.ranked_word, prob.probability)
        zeeguu.db.session.add(known_word_probability_obj)
        zeeguu.db.session.commit()
    for prob in ex_probs:
        user = prob.user
        language = prob.user_word.language
        word = prob.user_word.word
        ranked_word = None
        if RankedWord.exists(word, language):
            ranked_word = RankedWord.find(word, language)
        if not EncounterBasedProbability.exists(user, ranked_word):
            if UserWord.exists(word, language):
                user_word = UserWord.find(word, language)
                known_word_probability_obj = KnownWordProbability(user, user_word, ranked_word, prob.probability)
                zeeguu.db.session.add(known_word_probability_obj)
                zeeguu.db.session.commit()
    print "job3"
Beispiel #2
0
def lookup(from_lang, term, to_lang):
    """
    Used to log a given search.
    TODO: See what's the relation between this and goslate,
     that is, /goslate should already log the search...
     also, this requires both from and to_lang, but goslate does not.

    :param from_lang:
    :param term:
    :param to_lang:
    :return:
    """
    from_lang = Language.find(from_lang)
    if not isinstance(to_lang, Language):
        to_lang = Language.find(to_lang)
    user = flask.g.user
    content = flask.request.form.get("text")
    if content is not None:
        text = Text.find(content, from_lang)
        user.read(text)
    else:
        text = None
    word = decode_word(term)
    rank = UserWord.find_rank(word, to_lang)
    user.searches.append(
        Search(user, UserWord.find(word, from_lang),
                     to_lang, text)
    )
    zeeguu.db.session.commit()
    return "OK"
Beispiel #3
0
def lookup(from_lang, term, to_lang):
    """
    Used to log a given search.
    TODO: See what's the relation between this and goslate,
     that is, /goslate should already log the search...
     also, this requires both from and to_lang, but goslate does not.

    :param from_lang:
    :param term:
    :param to_lang:
    :return:
    """
    from_lang = Language.find(from_lang)
    if not isinstance(to_lang, Language):
        to_lang = Language.find(to_lang)
    user = flask.g.user
    content = flask.request.form.get("text")
    if content is not None:
        text = Text.find(content, from_lang)
        user.read(text)
    else:
        text = None
    word = decode_word(term)
    rank = UserWord.find_rank(word, to_lang)
    user.searches.append(
        Search(user, UserWord.find(word, from_lang), to_lang, text))
    zeeguu.db.session.commit()
    return "OK"
Beispiel #4
0
def bookmark_with_context(from_lang_code, term, to_lang_code, translation):
    """
    The preferred way of a user saving a word/translation/context to his
    profile.
    :param from_lang_code:
    :param term:
    :param to_lang_code:
    :param translation:
    :return:
    """

    if 'title' in flask.request.form:
        bookmarked_url_title = flask.request.form['title']
    else:
        bookmarked_url_title = ''

    bookmarked_url = flask.request.form['url']
    context = flask.request.form['context']

    url = Url.find(bookmarked_url, bookmarked_url_title)

    from_lang = Language.find(from_lang_code)
    to_lang = Language.find(to_lang_code)

    word = (decode_word(term))
    translation_word = decode_word(translation)
    user_word = UserWord.find(word, from_lang)
    translation = UserWord.find(translation_word, to_lang)

    # search = Search.query.filter_by(
    #     user=flask.g.user, user_word=user_word, language=to_lang
    # ).order_by(Search.id.desc()).first()

    #create the text entity first
    new_text = Text(context, from_lang, url)
    bookmark = Bookmark(user_word, translation, flask.g.user, new_text,
                        datetime.datetime.now())
    zeeguu.db.session.add(bookmark)
    bookmark.calculate_probabilities_after_adding_a_bookmark(
        flask.g.user, bookmark.origin.language)
    return str(bookmark.id)
Beispiel #5
0
def bookmark_with_context(from_lang_code, term, to_lang_code, translation):
    """
    The preferred way of a user saving a word/translation/context to his
    profile.
    :param from_lang_code:
    :param term:
    :param to_lang_code:
    :param translation:
    :return:
    """

    if 'title' in flask.request.form:
        bookmarked_url_title = flask.request.form['title']
    else:
        bookmarked_url_title = ''

    bookmarked_url = flask.request.form['url']
    context = flask.request.form['context']


    url = Url.find(bookmarked_url, bookmarked_url_title)

    from_lang = Language.find(from_lang_code)
    to_lang = Language.find(to_lang_code)

    word = (decode_word(term))
    translation_word = decode_word(translation)
    user_word = UserWord.find(word,from_lang)
    translation = UserWord.find(translation_word,to_lang)

    # search = Search.query.filter_by(
    #     user=flask.g.user, user_word=user_word, language=to_lang
    # ).order_by(Search.id.desc()).first()

    #create the text entity first
    new_text = Text(context, from_lang, url)
    bookmark = Bookmark(user_word, translation, flask.g.user, new_text, datetime.datetime.now())
    zeeguu.db.session.add(bookmark)
    bookmark.calculate_probabilities_after_adding_a_bookmark(flask.g.user, bookmark.origin.language)
    return str(bookmark.id)
Beispiel #6
0
def add_new_translation_to_bookmark(word_translation, bookmark_id):
    bookmark = Bookmark.query.filter_by(id=bookmark_id).first()
    translations_of_bookmark = bookmark.translations_list
    for transl in translations_of_bookmark:
        if transl.word == word_translation:
            return 'FAIL'

    translation_user_word = UserWord.find(word_translation,
                                          translations_of_bookmark[0].language)
    bookmark.add_new_translation(translation_user_word)
    zeeguu.db.session.add(translation_user_word)
    zeeguu.db.session.commit()
    return "OK"
def set_know_word_prob():
    zeeguu.app.test_request_context().push()
    zeeguu.db.session.commit()
    enc_probs = EncounterBasedProbability.find_all()
    ex_probs = ExerciseBasedProbability.find_all()
    for prob in enc_probs:
        user = prob.user
        word = prob.ranked_word.word
        language = prob.ranked_word.language
        user_word = None
        if UserWord.exists(word, language):
            user_word = UserWord.find(word, language)
        if ExerciseBasedProbability.exists(user, user_word):
            ex_prob = ExerciseBasedProbability.find(user, user_word)
            known_word_prob = KnownWordProbability.calculateKnownWordProb(
                ex_prob.probability, prob.probability)
            known_word_probability_obj = KnownWordProbability.find(
                user, user_word, prob.ranked_word, known_word_prob)
        else:
            known_word_probability_obj = KnownWordProbability.find(
                user, None, prob.ranked_word, prob.probability)
        zeeguu.db.session.add(known_word_probability_obj)
        zeeguu.db.session.commit()
    for prob in ex_probs:
        user = prob.user
        language = prob.user_word.language
        word = prob.user_word.word
        ranked_word = None
        if RankedWord.exists(word, language):
            ranked_word = RankedWord.find(word, language)
        if not EncounterBasedProbability.exists(user, ranked_word):
            if UserWord.exists(word, language):
                user_word = UserWord.find(word, language)
                known_word_probability_obj = KnownWordProbability(
                    user, user_word, ranked_word, prob.probability)
                zeeguu.db.session.add(known_word_probability_obj)
                zeeguu.db.session.commit()
    print 'job3'
Beispiel #8
0
    def test_importance_level(self):
        word = "beschloss"
        if(model.RankedWord.exists(word.lower(), self.de)):
            rank = model.UserWord.find_rank(word.lower(), self.de)
            new_word = model.UserWord.find(word,self.de)
        else:
            new_word = model.UserWord.find(word,self.de)

        db.session.add(new_word)
        db.session.commit()

        word = "unexistingword"
        beschloss = UserWord.find(word, self.de)
        assert beschloss
        assert beschloss.importance_level() == 0
Beispiel #9
0
    def test_importance_level(self):
        word = "beschloss"
        if (model.RankedWord.exists(word.lower(), self.de)):
            rank = model.UserWord.find_rank(word.lower(), self.de)
            new_word = model.UserWord.find(word, self.de)
        else:
            new_word = model.UserWord.find(word, self.de)

        db.session.add(new_word)
        db.session.commit()

        word = "unexistingword"
        beschloss = UserWord.find(word, self.de)
        assert beschloss
        assert beschloss.importance_level() == 0
Beispiel #10
0
def add_new_translation_to_bookmark(word_translation, bookmark_id):
    bookmark = Bookmark.query.filter_by(
        id=bookmark_id
    ).first()
    translations_of_bookmark = bookmark.translations_list
    for transl in translations_of_bookmark:
        if transl.word ==word_translation:
            return 'FAIL'


    translation_user_word = UserWord.find(word_translation,translations_of_bookmark[0].language)
    bookmark.add_new_translation(translation_user_word)
    zeeguu.db.session.add(translation_user_word)
    zeeguu.db.session.commit()
    return "OK"
Beispiel #11
0
 def test_find_word(self):
     word = "baum"
     rank = model.UserWord.find_rank(word, self.de)
     assert UserWord.find(word, self.de, rank)
Beispiel #12
0
 def test_find_word(self):
     word = "baum"
     rank = model.UserWord.find_rank(word, self.de)
     assert UserWord.find(word, self.de, rank)
Beispiel #13
0
 def test_search_1(self):
     word = UserWord.find("hauen345", self.de)
     s = model.Search(self.mir, word, self.de)
     db.session.add(s)
     db.session.commit()
Beispiel #14
0
 def test_find_word(self):
     word = "baum"
     assert UserWord.find(word, self.de)
Beispiel #15
0
 def test_find_word(self):
     word = "baum"
     assert UserWord.find(word, self.de)
Beispiel #16
0
 def test_search_1(self):
     word = UserWord.find("hauen345", self.de)
     s = model.Search(self.mir, word, self.de)
     db.session.add(s)
     db.session.commit()
    def test_find(self):
        user_word_should_be = UserWordRule().user_word
        user_word_to_check = UserWord.find(user_word_should_be.word,
                                           user_word_should_be.language)

        assert user_word_to_check == user_word_should_be