예제 #1
0
def check_rhyme(rhyme_scheme, line, phonemes):
    ''' rhyme_scheme: a dict of end rhymes for the current limerick, of the form
                        {'A': phoneme, 'B': phoneme}
        line:         position of line whose ending we are checking ('A' or 'B')
        phonemes:     the phoneme ending the current line, to check against rhyme_scheme
    '''
    if not line in rhyme_scheme:
        return False

    return poetry.rhyme_from_phonemes(rhyme_scheme[line], phonemes)
예제 #2
0
def check_rhyme(rhyme_scheme, line, phonemes):
    ''' rhyme_scheme: a dict of end rhymes for the current limerick, of the form
                        {'A': phoneme, 'B': phoneme}
        line:         position of line whose ending we are checking ('A' or 'B')
        phonemes:     the phoneme ending the current line, to check against rhyme_scheme
    '''
    if not line in rhyme_scheme:
        return False

    return poetry.rhyme_from_phonemes(rhyme_scheme[line], phonemes)
예제 #3
0
def cmu_phonemes(word):
    # If in cmudict, just use cmudict
    if not word.lower() in d:
        return False
    else:
        return min(d[word.lower()], key=len)


hit = 0
miss = 0

for word, vals in d.iteritems():
    cmu = cmu_phonemes(word)
    suff = suffdict_phonemes(word)
    if cmu and suff and poetry.rhyme_from_phonemes(cmu, suff):
        hit += 1
    elif not cmu:
        print "Not in cmudict!"
    elif not suff:
        print "Not in suffdict!"
    else:
        print word
        miss += 1

print "hits: "
print hit
print "misses: "
print miss
print "Percent accuracy: "
print (hit / (hit + miss)) * 100
예제 #4
0
 if overflows_line(syllable_counter, sylct):
     break  # break out if a word overflows the line
 word_array.append(next_word)
 syllable_counter += sylct
 phonemes = word_data[next_word]['phonemes']
 if syllable_counter == 8:
     if not phonemes:
         break
     rhyme_scheme['A'] = phonemes
     word_array.append("\n")
 elif syllable_counter == 16:
     word_array.append("\n")
     if not phonemes:
         break
     if (not 'A' in rhyme_scheme or not \
         poetry.rhyme_from_phonemes(rhyme_scheme['A'], phonemes)):
         break
 elif syllable_counter == 21:
     if phonemes == rhyme_scheme['A'] or not phonemes:
         break
     rhyme_scheme['B'] = phonemes
     word_array.append("\n")
 elif syllable_counter == 26:
     word_array.append("\n")
     if not phonemes:
         break
     if (not 'B' in rhyme_scheme or not \
         poetry.rhyme_from_phonemes(rhyme_scheme['B'], phonemes)):
         break
 elif syllable_counter == 35:
     if not phonemes:
예제 #5
0
 sylct = word_data[next_word]['sylct']
 if overflows_line(syllable_counter, sylct):
     break  # break out if a word overflows the line
 word_array.append(next_word)
 syllable_counter += sylct
 phonemes = word_data[next_word]['phonemes']
 if syllable_counter == 8:
     if not phonemes:
         break
     rhyme_scheme['A'] = phonemes
     word_array.append("\n")
 elif syllable_counter == 16:
     word_array.append("\n")
     if not phonemes:
         break
     if not 'A' in rhyme_scheme or not poetry.rhyme_from_phonemes(rhyme_scheme['A'], phonemes):
         break
 elif syllable_counter == 21:
     if phonemes == rhyme_scheme['A'] or not phonemes:
         break
     rhyme_scheme['B'] = phonemes
     word_array.append("\n")
 elif syllable_counter == 26:
     word_array.append("\n")
     if not phonemes:
         break
     if not 'B' in rhyme_scheme or not poetry.rhyme_from_phonemes(rhyme_scheme['B'], phonemes):
         break
 elif syllable_counter == 35:
     if not phonemes:
         break
예제 #6
0
def cmu_phonemes(word):
    # If in cmudict, just use cmudict
    if not word.lower() in d:
        return False
    else:
        return min(d[word.lower()], key=len)


hit = 0
miss = 0

for word, vals in d.iteritems():
    cmu = cmu_phonemes(word)
    suff = suffdict_phonemes(word)
    if cmu and suff and poetry.rhyme_from_phonemes(cmu, suff):
        hit += 1
    elif not cmu:
        print "Not in cmudict!"
    elif not suff:
        print "Not in suffdict!"
    else:
        print word
        miss += 1

print "hits: "
print hit
print "misses: "
print miss
print "Percent accuracy: "
print(hit / (hit + miss)) * 100