Skip to content

Instantly share code, notes, and snippets.

@nrrb
Created November 1, 2019 16:51
Show Gist options
  • Save nrrb/d3ec8152bfde1fdb34809b4236e6f9df to your computer and use it in GitHub Desktop.
Save nrrb/d3ec8152bfde1fdb34809b4236e6f9df to your computer and use it in GitHub Desktop.
Making silly phrases out of initials
from random import choice
from functools import reduce
with open('mobypos.txt', 'r', encoding='latin1') as f:
moby_words = [line.strip() for line in f.readlines()]
words = [dict(zip(['word', 'pos'], moby_word.split('\\'))) for moby_word in moby_words]
pos_key = {
'Noun': 'N',
'Plural': 'p',
'Noun Phrase': 'h',
'Verb (usu participle)': 'V',
'Verb (transitive)': 't',
'Verb (intransitive)': 'i',
'Adjective': 'A',
'Adverb': 'v',
'Conjunction': 'C',
'Preposition': 'P',
'Interjection': '!',
'Pronoun': 'r',
'Definite Article': 'D',
'Indefinite Article': 'I',
'Nominative': 'o'
}
pos_words = lambda pos: list(filter(lambda w: pos_key[pos] in w['pos'], words))
words_by_first_letter = lambda word_list, first_letter: list(filter(lambda word: word['word'][0] == first_letter, word_list))
# we'll either have:
# N - Interjection!
# R - Adverb
# R - Verb
# B - Noun
# or
# N - Adjective
# R - Adverb
# R - Verb
# B - Noun
bloop = lambda pos, first_letter: [w['word'] for w in words_by_first_letter(pos_words(pos), first_letter)]
nrrb_string = lambda: ' '.join(map(lambda w: w.capitalize(), map(choice,
[[w + '!' for w in bloop('Interjection', 'n')] + bloop('Adjective', 'n'),
bloop('Adverb', 'r'),
bloop('Verb (usu participle)', 'r'),
bloop('Noun', 'b')])))
jsh_words = [[w + '!' for w in bloop('Interjection', 'j')],
bloop('Adjective', 's'),
bloop('Noun', 'h')]
print(reduce(lambda x,y: x*y, map(len, jsh_words)), ' combinations for JSH!')
jsh_string = lambda: ' '.join(map(lambda w: w.capitalize(),
map(choice, jsh_words)))
for _ in range(100):
print(jsh_string())
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment