Пример #1
0
def query_verificationen():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    user_word = verificationService.next_word(user)

    if user_word is None:
        return create_error_response(404, "No words to verify.")

    word = user_word.json()
    resp = {'word': word}

    num_words = verificationService.num_words(user)
    if num_words is not None:
        resp['num_words'] = num_words

    segmentations = []

    verification_proposals = verificationService.proposals_for_word(user_word)
    if verification_proposals is not None:
        for p in verification_proposals:
            s = Segmentation(word['text'],
                             p.user.first_name + " " + p.user.last_name,
                             "User", p.hyphenation, p.stress_pattern)
            segmentations.append(s.json())

    segmentation_proposals = dictionaryServiceen.query_segmentation(
        word['text'])
    segmentations = segmentations + segmentation_proposals

    if segmentations is not None:
        resp['segmentations'] = segmentations

    return create_response(200, resp)
Пример #2
0
def user_add_word():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    text = request.form.get("text")
    stress_pattern = request.form.get("stress_pattern")
    hyphenation = request.form.get("hyphenation")
    pos = request.form.get("pos")

    if not text or not stress_pattern or not hyphenation or not pos:
        return create_error_response(400, "Data not provided.")

    # check if the word was already added to the database.
    word = userService.get_word(user, DictionaryService.preprocess_entry(text),
                                pos)

    if word is not None:
        return create_response(201)

    db_word = userService.add_word(user, text, pos, stress_pattern,
                                   hyphenation)

    if not db_word or db_word is None:
        return create_error_response(404,
                                     "Error adding word to local database.")

    # print("word {0} added by {1}: {2},{3}".format(db_word.text, user.email, db_word.hyphenation, db_word.stress_pattern))

    # also add the word as a proposal into verification services.
    #if not verificationService.add_proposal(user,db_word, stress_pattern, hyphenation):
    #    return create_error_response(404, "Error adding proposal to verfication service.")

    return create_response(201)
Пример #3
0
def query_word(text, pos):
    user = userService.authenticate(Authentication.read(request))
    # TODO better method than to pass userService as a parameter?
    response = dictionaryService.query_word(text, pos, userService, user)

    if response is None:
        return create_error_response(404, "Word not found.")

    return create_response(200, response)
Пример #4
0
def query_texten():
    user = userService.authenticate(Authentication.read(request))
    text = request.form.get("text")

    response = dictionaryServiceen.query_text(text, userService, user)

    if response is None:
        return create_error_response(404, "Error analyzing text.")

    return create_response(200, response)
Пример #5
0
def user_get_texts():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    texts = userService.get_texts(user)

    if texts is None:
        return create_error_response(404, "Error getting texts.")

    return create_response(200, {'texts': texts})
Пример #6
0
def user_get_configurations():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    configurations = userService.get_configurations(user)

    if configurations is None:
        return create_error_response(404, "Error getting configurations.")

    return create_response(200, {'configurations': configurations})
Пример #7
0
def user_get_words():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    user_words = userService.list_words(user)

    if user_words is None:
        return create_error_response(404, "Error getting user words.")

    return create_response(200, {'user_words': user_words})
Пример #8
0
def query_text():
    user = userService.authenticate(Authentication.read(request))
    text = request.form.get("text")

    # TODO better method than to pass userService as a parameter?
    response = dictionaryService.query_text(text, userService, user)

    if response is None:
        return create_error_response(404, "Error analyzing text.")

    return create_response(200, response)
Пример #9
0
def user_delete_text():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    textId = request.form.get("id")

    if not textId:
        return create_error_response(400, "Text id not provided.")

    if not userService.delete_text(textId):
        return create_error_response(404, "Error deleting text.")

    return create_response(204)
Пример #10
0
def user_delete_configuration():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    configId = request.form.get("id")

    if not configId:
        return create_error_response(400, "Configuration id not provided.")

    if not userService.delete_configuration(configId):
        return create_error_response(404, "Error deleting configuration.")

    return create_response(204)
Пример #11
0
def user_update_configuration():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    configuration_id = request.form.get("id")
    name = request.form.get("name")

    stressed_color = request.form.get("stressed_color")
    unstressed_color = request.form.get("unstressed_color")
    word_background = request.form.get('word_background')
    alternate_color = request.form.get('alternate_color')
    syllable_separator = request.form.get('syllable_separator')

    line_height = request.form.get("line_height")
    word_distance = request.form.get('word_distance')
    syllable_distance = request.form.get('syllable_distance')
    font_size = request.form.get('font_size')
    letter_spacing = request.form.get('letter_spacing')

    use_background = map_boolean(request.form.get('use_background'))
    highlight_foreground = map_boolean(
        request.form.get('highlight_foreground'))
    stressed_bold = map_boolean(request.form.get('stressed_bold'))
    use_alternate_color = map_boolean(request.form.get('use_alternate_color'))
    use_syllable_separator = map_boolean(
        request.form.get('use_syllable_separator'))

    pos_config_list = json.loads(
        request.form.get("part_of_speech_configuration"))

    if not name or not stressed_color or not unstressed_color or not word_background or not line_height \
            or not word_distance or not syllable_distance or not font_size or not letter_spacing\
            or not alternate_color or not pos_config_list or not syllable_separator:
        return create_error_response(400, "Data not provided.")

    success = userService.update_configuration(
        configuration_id, name, stressed_color, unstressed_color,
        word_background, alternate_color, syllable_separator, word_distance,
        syllable_distance, font_size, letter_spacing, use_background,
        highlight_foreground, stressed_bold, line_height, use_alternate_color,
        use_syllable_separator, pos_config_list)

    if not success:
        return create_error_response(404,
                                     "Configuration to be updated not found.")

    return create_response(201)
Пример #12
0
def user_add_text():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    title = request.form.get("title")
    text = request.form.get("text")

    if not text:
        return create_error_response(400, "Text not provided.")

    if not title:
        return create_error_response(400, "Title not provided.")

    if not userService.add_text(user, title, text):
        return create_error_response(404, "Error adding text.")

    return create_response(201)
Пример #13
0
def user_delete():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(404, "Wrong password.")

    #if not userService.checkpw(user, password):
    #	return create_error_response(404, "Wrong password.")

    # delete user words and verification proposals
    words = userService.list_words(user)
    print(words)
    try:
        for w in words:
            userService.delete_word(w['id'])
            verificationService.cleanup_proposals(w)
    except Exception as e:
        print(e)
        return create_error_response(404, "Error deleting words.")

    # delete user texts
    texts = userService.get_texts(user)
    print(texts)
    try:
        for t in texts:
            userService.delete_text(t['id'])
    except Exception as e:
        print(e)
        return create_error_response(404, "Error deleting texts.")

    # delete user configurations
    conf = userService.get_configurations(user)
    print(conf)
    try:
        for c in conf:
            userService.delete_configuration(c['id'])
    except Exception as e:
        print(e)
        return create_error_response(404, "Error deleting configurations.")

    response = userService.delete_account(user)

    if not response:
        return create_error_response(404, "Error deleting account.")

    return create_response(201)
Пример #14
0
def submit_verificationen():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    word_id = request.form.get("id")

    if not word_id:
        return create_error_response(400, "Word id not provided.")

    stress_pattern = request.form.get("stress_pattern")
    hyphenation = request.form.get("hyphenation")

    if not stress_pattern or not hyphenation:
        return create_error_response(400, "Data not provided.")

    if not verificationService.submit(user, word_id, stress_pattern,
                                      hyphenation, dictionaryServiceen):
        return create_error_response(404, "Unable to submit proposal.")

    return create_response(201)
Пример #15
0
def query_verification():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(403, "Invalid credentials.")

    # get the next from a different user that needs to be verified.
    user_word = verificationService.next_word(user)

    if user_word is None:
        return create_error_response(404, "No words to verify.")

    word = user_word.json()
    resp = {'word': word}

    num_words = verificationService.num_words(user)
    if num_words is not None:
        resp['num_words'] = num_words

    #print("get proposals for {0}".format(word))
    segmentations = []

    # get proposals from other users and append them to the list of proposals.
    verification_proposals = verificationService.proposals_for_word(user_word)
    if verification_proposals is not None:
        for p in verification_proposals:
            s = Segmentation(word['text'],
                             p.user.first_name + " " + p.user.last_name,
                             "Benutzer", p.hyphenation, p.stress_pattern)
            segmentations.append(s.json())
            #print("proposal {0} by {1}: {2},{3}".format(s.json(), p.user.email, p.hyphenation, p.stress_pattern))

    # compute automatically generated proposals (i.e., MARY TTS and pyphen).
    segmentation_proposals = dictionaryService.query_segmentation(word['text'])
    segmentations = segmentations + segmentation_proposals

    if segmentations is not None:
        resp['segmentations'] = segmentations

    return create_response(200, resp)
Пример #16
0
def user_authenticate():
    user = userService.authenticate(Authentication.read(request))
    if not user: return create_error_response(401, "Invalid credentials.")

    return create_response(200, {'user': user.json()})