2020-04-03 21:14:04 +00:00
|
|
|
import itertools
|
2020-02-21 23:52:29 +00:00
|
|
|
from Phyme import Phyme
|
|
|
|
import random
|
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
2020-04-03 21:14:04 +00:00
|
|
|
random.seed(time.time())
|
2020-02-21 23:52:29 +00:00
|
|
|
|
|
|
|
ph = Phyme()
|
|
|
|
|
2020-04-10 20:52:27 +00:00
|
|
|
|
2020-04-03 21:14:04 +00:00
|
|
|
def get_rhyme(word):
|
|
|
|
# Get all rhymes and merge to one list (normally separated by syllable count)
|
|
|
|
rhymes = ph.get_perfect_rhymes(word)
|
|
|
|
rhyme_vals = list(itertools.chain.from_iterable(list(rhymes.values())))
|
2020-02-21 23:52:29 +00:00
|
|
|
|
2020-04-03 21:14:04 +00:00
|
|
|
# Pick a random rhyme and strip out any non alpha characters
|
|
|
|
rhymed_word = rhyme_vals[random.randint(0, len(rhyme_vals) - 1)]
|
|
|
|
rhymed_word = ''.join(letter for letter in rhymed_word if letter.isalpha())
|
2020-02-21 23:52:29 +00:00
|
|
|
|
2020-04-03 21:14:04 +00:00
|
|
|
return rhymed_word.capitalize()
|
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
print(get_rhyme(sys.argv[1]))
|