{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "## Sebastian HW Modifications\n", "Original code can be found on Allison Parrish [repo](https://github.com/aparrish/rwet/blob/master/some-poetry-generators.ipynb)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Love Letter Generator\n", "\n", "Original by Christopher Strachey, written for the Manchester Mark I in 1952. [Read more here](https://grandtextauto.soe.ucsc.edu/2005/08/01/christopher-strachey-first-digital-artist/).\n", "\n", "Vocabulary based on [this implementation](https://github.com/gingerbeardman/loveletter/blob/master/index.php)." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "collapsed": true }, "outputs": [], "source": [ "sal_adjs = [\n", " \"Delicious\",\n", " \"Exquisite\",\n", " \"My\",\n", " \"Juiciest\",\n", " \"Vibrant\",\n", " \"Sweetest\"]" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "collapsed": true }, "outputs": [], "source": [ "sal_nouns = [\n", " \"Pamplemousse\",\n", " \"Pear\",\n", " \"Guava\",\n", " \"Pommegranade\",\n", " \"Avocado\",\n", " \"Passion Fruit\"\n", "]" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "collapsed": true }, "outputs": [], "source": [ "adjsSelf = [\n", " 'affectionate',\n", " 'amorous',\n", " 'anxious',\n", " 'avid',\n", " 'beautiful',\n", " 'breathless',\n", " 'burning',\n", " 'covetous',\n", " 'craving',\n", " 'curious',\n", " 'eager',\n", " 'fervent',\n", " 'fondest',\n", " 'loveable',\n", " 'lovesick',\n", " 'loving',\n", " 'passionate',\n", " 'precious',\n", " 'seductive',\n", " 'sweet',\n", " 'sympathetic',\n", " 'tender',\n", " 'unsatisfied',\n", " 'winning',\n", " 'wistful'\n", "]" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "collapsed": true }, "outputs": [], "source": [ "nounsSelf = [\n", " 'appetite',\n", " 'craving',\n", " 'desire',\n", " 'fancy',\n", " 'intestines',\n", " 'fervour',\n", " 'hunger',\n", " 'taste',\n", " 'passion',\n", " 'tastebuds',\n", " 'thirst',\n", " 'lips',\n", " 'mouth'\n", "]" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "collapsed": true }, "outputs": [], "source": [ "nounsFruit=[\n", " 'shape',\n", " 'flavour',\n", " 'taste',\n", " 'texture',\n", " 'peal'\n", "]" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "collapsed": true }, "outputs": [], "source": [ "advsSelf = [\n", " 'affectionately',\n", " 'ardently',\n", " 'anxiously',\n", " 'beautifully',\n", " 'burningly',\n", " 'covetously',\n", " 'curiously',\n", " 'eagerly',\n", " 'fervently',\n", " 'fondly',\n", " 'impatiently',\n", " 'keenly',\n", " 'lovingly',\n", " 'passionately',\n", " 'seductively',\n", " 'tenderly',\n", " 'wistfully'\n", "]" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "collapsed": true }, "outputs": [], "source": [ "adjsFruit = [\n", " 'tomato',\n", " 'alien',\n", " 'delecius',\n", " 'perfect',\n", " 'bumpy',\n", " 'round',\n", " 'sweet',\n", " 'smooth',\n", " 'nectarous',\n", " 'crispy'\n", "]" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "collapsed": true }, "outputs": [], "source": [ "verbsSelf = [\n", " 'adores',\n", " 'attracts',\n", " 'devours',\n", " 'holds dear',\n", " 'eat for',\n", " 'hungers for',\n", " 'likes',\n", " 'longs for',\n", " 'loves',\n", " 'lusts after',\n", " 'pants for',\n", " 'pines for',\n", " 'sighs for',\n", " 'squeeze',\n", " 'thirsts for',\n", " 'treasures',\n", " 'yearns for',\n", " 'woos'\n", "]" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "collapsed": true }, "outputs": [], "source": [ "verbsFruit=[\n", " 'explossion',\n", " 'secretion' \n", "]" ] }, { "cell_type": "code", "execution_count": 22, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Juiciest Pamplemousse,\n", "\n", "My fervent fervour devours your bumpy flavour. You are my\n", "eager intestines. My amorous passion fervently holds dear\n", "your nectarous taste. My craving keenly devours your\n", "delecius shape. My loving passion longs for your peal.\n", "\n", "Yours fondly,\n", "Joe T.\n" ] } ], "source": [ "# textwrap library used to \"wrap\" the text at a particular length\n", "import textwrap\n", "import random\n", "\n", "# output begins with salutation\n", "output = random.choice(sal_adjs) + \" \" + random.choice(sal_nouns) + \",\\n\"\n", "output += \"\\n\"\n", "\n", "# inside this loop, build the phrases. strachey implemented \"short\" phrases\n", "# and \"long\" phrases; two or more \"short\" phrases in a row have special\n", "# formatting rules, so we need to know what the last phrase kind was in\n", "# order to generate the output.\n", "history = []\n", "body = \"\"\n", "for i in range(5):\n", " kind = random.choice([\"short\", \"long\"])\n", " if kind == \"long\":\n", " # adjectives and adverbs will be present only 50% of the time\n", " line = \" \".join([\n", " \"My\",\n", " random.choice([random.choice(adjsSelf), \"\"]),\n", " random.choice(nounsSelf),\n", " random.choice([random.choice(advsSelf), \"\"]),\n", " random.choice(verbsSelf),\n", " \"your\",\n", " random.choice([random.choice(adjsFruit), \"\"]),\n", " random.choice(nounsFruit)])\n", " body += line\n", " else:\n", " adj_noun = random.choice(adjsSelf) + \" \" + random.choice(nounsSelf)\n", " # if the last phrase was \"short,\" use truncated form\n", " if len(history) > 0 and history[-1] == \"short\":\n", " body += \": my \" + adj_noun\n", " else:\n", " body += \"You are my \" + adj_noun\n", " body += \". \"\n", " history.append(kind)\n", "# clean up output\n", "body = body.replace(\" \", \" \")\n", "body = body.replace(\". :\", \":\")\n", "# put everything together\n", "output += textwrap.fill(body, 60)\n", "output += \"\\n\\nYours \" + random.choice(advsSelf) + \",\\n\"\n", "output += \"Joe T.\"\n", "print(output)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.6.0" } }, "nbformat": 4, "nbformat_minor": 2 }