Пример #1
0
Файл: rhymes.py Проект: rec/p4p
def _read_rhyme_dictionary(filename):
    rhymes = {}
    with open(filename) as f:
        for line in f:
            line = line.strip()
            if line:
                words = set(text.split_into_words(line))
                for w in words:
                    assert w not in rhymes
                    rhymes[w] = words
    return rhymes
Пример #2
0
def get_pairs_for_list(tokens_list, number):
    """Return all pairs from database for chosen start token"""
    start = tokens_list[-1]
    conn, cursor = start_connection()
    cursor.execute('SELECT * from pairs WHERE begin = ?;', (start,))
    result = cursor.fetchall()
    if not result:
        start = ' '.join(text.split_into_words(' '.join(tokens_list))[-number:])
        cursor.execute('SELECT * from pairs WHERE begin = ?;', (start,))
        result = cursor.fetchall()
    cursor.execute('SELECT SUM(count) from pairs WHERE begin = ?;', (start,))
    count = cursor.fetchone()
    end_connecion(conn)
    if not result:
        return [], 0
    return result, count[0] if count else 0
Пример #3
0
def line_syllables(line):
    return sum(_SYLLABLES.get(w, 1) for w in text.split_into_words(line))