#!/usr/bin/python3 # -*- coding: utf-8 -*- """Generate dramatic phrases. You don’t make beautiful music by collecting together beautiful sounds. You don’t make delicious food by combining delicious ingredients. But to some extent you can generate overwrought dramatic phrases by combining overwrought dramatic words, and that’s what this module does. Sample output: The raw wind of the smooth horse. An evil labyrinth of the monstrous, dying waters. The mere gate of deserted gardens. The smiling stairway of countless sweet fangs. The shattered witch of the diseased, ruby monk. The asphalt house of the smooth unicorn. A haunted fire of the sorrowful theft. The stainless raven of countless living gates. My haunted cloud beneath her glorious father. The brazen father of their raw villages. Its output is mostly valid English noun phrases, although it sometimes screws up adjective order or adds an unnecessary comma (“diseased, ruby monk” would be better without the comma, for example.) Sometimes it fails to make sense (perhaps you can figure out what “bottomless linen” or an “asphalt sister” might be, but I can’t), but other times it is gloriously balanced on the poetic edge between sense and nonsense, as in “a screaming flower of the most drunken stars” and “the deformed womb of the burnt sacrifices”. Occasionally it produces phrases that make perfect sense, even if perhaps they happen not to refer to anything in reality, such as “legendary brother of an ancient horse”, “stony gate of a virtuous prison”, or “noble hand of valiant, fallen brethren.” Do not use this code in a context where you need inoffensive phrases. It runs to the other extreme — to the extent that it is possible with such a minimal model of English, it generates phrases designed to evoke our strongest emotions: those related to death, violence, crime, grief, spirituality and the sacred, beauty, honor and dishonor, purity and contamination, decay, ostracism, disease, and our bodies, especially the reproductive parts; and it combines them indiscriminately. This program would have been banned by the Comstock Act. It samples nonuniformly from a repertoire of well over a trillion possible phrases. Some of the phrases are as short as “Mere ash of rough fog”, while others are as long as “Their blinding prison within countless sanctified, crystalline, violent daughters.” Presumably it can produce “Countless crystalline prisons within countless crystalline, crystalline, crystalline daughters,” which would be even longer; perhaps this is the limit with its current vocabulary. By sorting lines by their endings (perl -lne 'print reverse(split //)' | LANG=C sort | perl -lne 'print reverse(split //)') and selecting lines with some semblance of scansion, we can even hack together a semblance of a sonnet: The dancing wisdom beneath the frozen tomb. Their immortal sacrifice upon a ringing son. The silent knowledge within her roaring womb. A stainless birth within their golden gun. The deserted crystal of the reddened mother. The laughing father of her monstrous flower. The singing kings of his deserted brother. An ivory thistle of the ancient tower. The dead lord of the elder, valiant sons. The monstrous monk beneath my secret waters. His smiling cedars within three elder nuns. The fallen place of her deserted daughters. The sparkling mountains of a joyous soul. Three haunted pools within the breathing skull. Or a limerick, though that’s considerably worse, since iambic pentameter is much more frequent, and I used all the good rhymes in the sonnet and in particular son/nun/gun would be a lot better here: The beneficent labyrinth of the evil birth. The blistered daughters of his atomic earth. Unchained flies of misty fog. Cold nuns of a quiet dog. Dreaming stars of their immortal, sanctified birth. Naturally they make little or no sense, and even imposing an interpretation on them seems quite challenging to my limited imagination. A less hardcore process of improvising from a rhyme-skeleton generated from overly dramatic phrases, filtered and edited for scansion, might work better. Start the sonnet by generating seven lines: The rough paradise of their deathless nuns. The screaming laughter of their secret harlot. The glorious prison of the beneficent birth. The secret skull of the burning, sparkling sword. The steel knowledge of the defiled lamb. Their resonating sister beneath the dead, haunted river. The bleeding field of the burnt raven. Fill out the sonnet skeleton with blank lines and editing for scansion: Rougher paradises of their deathless nuns; The screaming laughter of their secret harlot ...ʌnz ...aɹlət The glorious prison of a stony birth; The secret skull of burning, sparkling sword. ...ɚθ ...ɔɹd Steel-like knowledge of defiled lambs. Resonating sister beneath the river. ...æmz ...ɪvɚ The bleeding field of burning raven. ...eɪvən Then attempt to make some kind of nightmarish sense out of it: Rougher paradises of the deathless nuns; The screaming laughter of their secret harlot Who dies each night and morning with the ones Who can’t remain forever wrapped in scarlet. The glorious prison of a stony birth From secret skulls of burning, sparkling sword Which sends its victims deep beneath the Earth To keep the terms of Elkanah’s accord. Steely knowledge of defiled lambs —  Their resonating sister underneath the river, Soon stops all human diggings and programmes To understand the nuns who do not wither. Her bleeding field of burning ravens Proves the bravest men are cravens. It’s still only marginally coherent, but now it tells a story, even if a confusing and very dark one. """ import random import sys # muscle spider eye eyes mushroom coward women men spear spears silver morsel # vision servant head glory altar voice # chariots captain war vessel vessels ice claws prophet nouns = """weasels linen singers place cloud house king thistles universe hearts heart gate gates kings thistle temple city mountains father mother robes hands gaze oak hand gardens terrace blood fetters phallus womb soul abomination desert cedars bone book pools words flower spires paradise nightmare sword gun bullet bullets witch sea ship gold coin tattoo birth monk monks battle angels door stairway raven lord sacrifice sacrifices perfume priests throne river daughter son sons brethren body fire ash ashes flies tower sister brother villages fields village field earth waters fool scream bell harlot skull laughter stars sky valley crystal unicorn dragon breath lions lion forest goat fog tomb gates lightning prison hermit exile beast torture murder rape theft child giants nun nuns snow rain wind willows disease dog dogs horse horses daughters fetus teeth dove doves lamb lambs labyrinth miracle bomb tumor monster worms infection flute pustules lie knowledge wisdom handmaid handmaids countenance dunghill beggar dust darkness light iniquity covenant slaughter hemorrhoids fangs remains maggots seraphim """.split() # high pregnant tombs deep brave sick moaning enlarged vile slain hasty dim departed # great perverted subdued pure hideous # hermetic adjectives = """roaring sweaty evil sanctified violent mere filthy faithful drunken moist porcelain corrupted unchained steel brazen sodden raw mortal false stony ancient Greek darkened deserted legendary ruby glass bony faithless immortal purple shining fatal quiet silent peaceful frozen innocent weeping bleeding sandy wordless unspeakable golden burnt sweet young elder ringing singing dancing fiery dark humble avenging dreaming defiled dying dead bottomless ivory foolish wise maddened rotten blinding atomic secret electric sparkling crystalline living eternal deathless fallen asphalt haunted breathing diamond snoring valiant noble burning stainless anointed screaming crying laughing smiling bloody monstrous diseased infected seething deformed shattered upright beneficent virtuous alien joyous beautiful misty cold trembling exalted pulverized vaporized vast heroic shuddering smooth rough glorious blistered reddened true lovely resonating sorrowful drunken resplendent blackened shimmering magical monumental sacred """.split() singulars = {'congeries', 'phallus', 'fetus'} mass = {'brethren', 'gold', 'blood', 'sugar', 'ash', 'laughter', 'light', 'fog', 'lightning', 'snow', 'rain', 'salt', 'earth', 'dust', 'darkness', 'ashes', 'iniquity', 'remains'} plurals = {'men', 'women', 'teeth', 'seraphim'} def singular(n): return n in singulars or (n[-1] != 's' and n not in mass and n not in plurals) def plural(n): return (n[-1] == 's' and n not in singulars and n not in mass or n in plurals) def determiner(next_word, noun): if plural(noun) and not random.randrange(5): return random.choice(['two ', 'the two ', 'three ', 'countless ', 'a hundred ', 'a thousand ', 'ten thousand ']) elif singular(noun): objvowel = (next_word[0] in 'aeiou') a = 'an ' if objvowel else 'a ' return random.choice([a, a, 'the ', 'the ', 'the ', 'the ', 'the ', 'the ', 'my ', 'his ', 'her ', 'their ']) else: return random.choice(['the ', 'the ', '', '', '', '', 'my ', 'his ', 'her ', 'their ']) def generate(): obj = random.choice(nouns) objadj = random.choice(adjectives) if not random.randrange(4): objadj2 = random.choice(adjectives) objadj = objadj2 + ', ' + objadj if not random.randrange(4): objadj3 = random.choice(adjectives) objadj = objadj3 + ', ' + objadj objdet = determiner(objadj, obj) if objdet == 'the ' and not random.randrange(10): objadj = 'most ' + objadj prep = 'of' if not random.randrange(4): prep = random.choice(['upon', 'within', 'beneath']) subj = random.choice(nouns) subjadj = random.choice(adjectives) subjdet = determiner(subjadj, subj) if subjdet in ['my ', 'his ', 'her ', 'their '] and prep == 'of': # This is often a bad grammatical situation (“His living # daughter of my filthy sons” — whose daughter is it again?), # so let’s hack it: subjdet = 'the ' return (subjdet + subjadj + ' ' + subj + ' ' + prep + ' ' + objdet + objadj + ' ' + obj) if __name__ == '__main__': for i in range(1 if len(sys.argv) < 2 else int(sys.argv[1])): phrase = generate() print(phrase[0].capitalize() + phrase[1:] + '.')