예제 #1
0
def test_finding_rhymes():
    print('testing rhyme finding?')
    rhyme_style = []
    # generate our line-by-line data:
    for t in tests:
        metadata = {
        'syllables': corpustor.count_syllables(t),
        'end_word': corpustor.end_sount(t)
        'end_sound': corpustor.end_sound(t)[1:],
        'real_word_ratio': corpustor.real_word_ratio(t),
        'text': corpustor.get_last_word(t)
        }
        
        if metadata['end_sound']:
            rhyme_style.append(metadata)

    print('extracted metadata from %d rhymes' % len(rhyme_style))
    # actually look for rhymes:
    set_of_rhymes = set(repr(w['end_sound']) for w in rhyme_style)

    set_of_rhymes = [eval(w) for w in set_of_rhymes]
    print('found %d unique sounds in %d total' % (len(set_of_rhymes), len(rhyme_style)))
    
    rhymes = list()
    for r in set_of_rhymes:
        rw = ''.join(r)
        rr = [w['text'] for w in rhyme_style if w['end_sound'] == r]
        if len(rr) > 1:
            rhymes.append(rr)


    for r in rhymes:
        print(r,'\n\n')
예제 #2
0
def test_end_sounds():
    
    for t in tests:
        w = corpustor.get_last_word(t)
        s = corpustor.end_sound(t)
        print( w, s, sep=' ')