Esempio n. 1
0
File: rhymes.py Progetto: 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
Esempio n. 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
Esempio n. 3
0
File: syllables.py Progetto: rec/p4p
def line_syllables(line):
    return sum(_SYLLABLES.get(w, 1) for w in text.split_into_words(line))