Exemple #1
0
def test_line_similarity_short_last_word():
    first_line = "I love to hear her speak, yet well I know"
    second_line = "I grant I never saw a goddess go"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 2 / 3
Exemple #2
0
def from_lines(lines, symbols=DEFAULT_SYMBOLS):
    rhyme_scheme = [None, ] * len(lines)
    current_symbol_idx = 0

    for idx, line in enumerate(lines):
        if rhyme_scheme[idx]:
            continue

        start_idx = idx + 1

        if start_idx == len(lines):
            continue

        for compare_idx, compare_line in enumerate(lines[start_idx:], start=start_idx):
            similarity = rhymes.line_similarity(line, compare_line)

            if similarity > 0.5:
                current_symbol = symbols[current_symbol_idx]
                rhyme_scheme[idx] = rhyme_scheme[compare_idx] = current_symbol

                current_symbol_idx += 1

                break

    return rhyme_scheme
Exemple #3
0
def test_line_similarity_far():
    first_line = "My mistress' eyes are nothing like the sun"
    second_line = "Coral is far more red than her lips' red"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 0
Exemple #4
0
def test_line_similarity_exact():
    first_line = "My mistress' eyes are nothing like the sun"
    second_line = "My mistress' eyes are nothing like the sun"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 1
Exemple #5
0
def test_line_similarity_similar():
    first_line = "My mistress' eyes are nothing like the sun"
    second_line = "If snow be white, why then her breasts are dun"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 3 / 4
def test_line_similarity_short_last_word():
    first_line = "I love to hear her speak, yet well I know"
    second_line = "I grant I never saw a goddess go"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 2/3
def test_line_similarity_exact():
    first_line = "My mistress' eyes are nothing like the sun"
    second_line = "My mistress' eyes are nothing like the sun"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 1
def test_line_similarity_far():
    first_line = "My mistress' eyes are nothing like the sun"
    second_line = "Coral is far more red than her lips' red"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 0
def test_line_similarity_similar():
    first_line = "My mistress' eyes are nothing like the sun"
    second_line = "If snow be white, why then her breasts are dun"

    index = rhymes.line_similarity(first_line, second_line)

    assert index == 3/4