Skip to content

Instantly share code, notes, and snippets.

@JackBelodeau
Last active October 5, 2018 05:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JackBelodeau/f698c64037878cce9bbca2324319f39b to your computer and use it in GitHub Desktop.
Save JackBelodeau/f698c64037878cce9bbca2324319f39b to your computer and use it in GitHub Desktop.
import pronouncing
from textblob import TextBlob
import pycorpora
import random
def an(word):
if (word[0] in ["a","e","i","o","u"]):
return "an" + word
else:
return "a" + word
template = """
I believe that I'm a {0}
so look for me in the {1}
"""
pair = random.choice(get_pairs())
poem = template.format(
pair[0],
(pair[1])
)
print(poem)
def get_words(pos):
if (pos is "nouns"):
all_words = pycorpora.words.nouns["nouns"]
elif (pos is "verbs"):
all_words = [w["present"] for w in pycorpora.words.verbs["verbs"]]
keepers = []
for n in all_words:
pl = pronouncing.phones_for_word(n)
if (len(pl) > 0):
sc = pronouncing.syllable_count(pl[0])
if (sc == 1):
keepers.append(n)
return keepers
def get_pairs():
verbs = get_words("verbs")
nouns = get_words("nouns")
pairs = []
for n in nouns:
for v in verbs:
if (v in pronouncing.rhymes(n)):
pairs.append( (v,n) )
return pairs
len(get_pairs())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment