Last active
April 12, 2018 17:18
-
-
Save boblannon/c9e687de54a0bfbb846f65aecac2b9d9 to your computer and use it in GitHub Desktop.
alliterative_android.ipynb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"metadata": { | |
"toc": "true" | |
}, | |
"cell_type": "markdown", | |
"source": "# Table of Contents\n <p>" | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:32:48.877056-07:00", | |
"end_time": "2018-04-12T16:32:49.794960Z" | |
}, | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "import nltk", | |
"execution_count": 1, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T10:18:50.198746-07:00", | |
"end_time": "2018-04-12T17:18:50.201922Z" | |
}, | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "## if you don't have the corpora you need:\n# nltk.download('brown')\n# nltk.download('nps_chat')", | |
"execution_count": 91, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:53:18.487171-07:00", | |
"end_time": "2018-04-12T16:53:18.491495Z" | |
}, | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "from nltk.corpus import brown\nfrom nltk.corpus import nps_chat", | |
"execution_count": 43, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:54:25.140861-07:00", | |
"end_time": "2018-04-12T16:54:25.159363Z" | |
}, | |
"trusted": true, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "tw = nps_chat.tagged_words()", | |
"execution_count": 46, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:54:32.873409-07:00", | |
"end_time": "2018-04-12T16:54:33.796728Z" | |
}, | |
"trusted": true, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "tw_all = list(set(\n sorted([w for w in tw if w[0].isalpha() and (w[1].startswith('N') or w[1].startswith('J'))], key=lambda x: x[0].lower())\n))", | |
"execution_count": 49, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:54:35.147861-07:00", | |
"end_time": "2018-04-12T16:54:35.160858Z" | |
}, | |
"trusted": true, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "tw_nouns = [t for t in tw_all if t[1].startswith('N')]\ntw_adj = [t for t in tw_all if t[1].startswith('J')]\n", | |
"execution_count": 50, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:54:39.070374-07:00", | |
"end_time": "2018-04-12T16:54:39.073952Z" | |
}, | |
"trusted": true, | |
"collapsed": true | |
}, | |
"cell_type": "code", | |
"source": "import random\nimport string", | |
"execution_count": 51, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:54:40.353438-07:00", | |
"end_time": "2018-04-12T16:54:40.364350Z" | |
}, | |
"trusted": true, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "def get_random_alliteration(adjectives, nouns):\n letter = random.choice(string.ascii_lowercase)\n try:\n noun = random.choice([n for n in nouns if n[0].lower().startswith(letter)])\n adjective = random.choice([a for a in adjectives if a[0].lower().startswith(letter)])\n except:\n return (\"oops\", \"oops\")\n return (adjective, noun)", | |
"execution_count": 52, | |
"outputs": [] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T09:54:41.627620-07:00", | |
"end_time": "2018-04-12T16:54:41.638657Z" | |
}, | |
"trusted": true, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "get_random_alliteration(tw_adj, tw_nouns)", | |
"execution_count": 53, | |
"outputs": [ | |
{ | |
"output_type": "execute_result", | |
"data": { | |
"text/plain": "(('busy', 'JJ'), ('ban', 'NN'))" | |
}, | |
"metadata": {}, | |
"execution_count": 53 | |
} | |
] | |
}, | |
{ | |
"metadata": { | |
"ExecuteTime": { | |
"start_time": "2018-04-12T10:09:09.582008-07:00", | |
"end_time": "2018-04-12T17:09:09.659290Z" | |
}, | |
"trusted": true, | |
"collapsed": false | |
}, | |
"cell_type": "code", | |
"source": "for i in range(20):\n print(get_random_alliteration(tw_adj, tw_nouns))", | |
"execution_count": 90, | |
"outputs": [ | |
{ | |
"output_type": "stream", | |
"text": "(('sexi', 'JJ'), ('streetcar', 'NN'))\n(('dirty', 'JJ'), ('dolls', 'NNS'))\n(('younger', 'JJR'), ('yawnssss', 'NNS'))\n(('am', 'JJ'), ('apple', 'NN'))\n(('gold', 'JJ'), ('Guy', 'NNP'))\n(('scared', 'JJ'), ('shape', 'NN'))\n(('quiet', 'JJ'), ('quarrel', 'NN'))\n(('yucky', 'JJ'), ('yards', 'NNS'))\n(('best', 'JJS'), ('b', 'NNP'))\n(('important', 'JJ'), ('ice', 'NN'))\n(('quiet', 'JJ'), ('queen', 'NN'))\n(('crazy', 'JJ'), ('change', 'NN'))\n(('fat', 'JJ'), ('fraggle', 'NNP'))\n('oops', 'oops')\n(('empty', 'JJ'), ('emergency', 'NN'))\n(('mean', 'JJ'), ('mercedes', 'NNP'))\n(('cutes', 'JJ'), ('chatroom', 'NN'))\n(('holy', 'JJ'), ('Hill', 'NN'))\n(('addicted', 'JJ'), ('angel', 'NNP'))\n(('dd', 'JJ'), ('drug', 'NN'))\n", | |
"name": "stdout" | |
} | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"name": "python3", | |
"display_name": "Python 3", | |
"language": "python" | |
}, | |
"varInspector": { | |
"window_display": false, | |
"cols": { | |
"lenName": 16, | |
"lenType": 16, | |
"lenVar": 40 | |
}, | |
"kernels_config": { | |
"python": { | |
"library": "var_list.py", | |
"delete_cmd_prefix": "del ", | |
"delete_cmd_postfix": "", | |
"varRefreshCmd": "print(var_dic_list())" | |
}, | |
"r": { | |
"library": "var_list.r", | |
"delete_cmd_prefix": "rm(", | |
"delete_cmd_postfix": ") ", | |
"varRefreshCmd": "cat(var_dic_list()) " | |
} | |
}, | |
"types_to_exclude": [ | |
"module", | |
"function", | |
"builtin_function_or_method", | |
"instance", | |
"_Feature" | |
] | |
}, | |
"toc": { | |
"threshold": 4, | |
"number_sections": false, | |
"toc_cell": true, | |
"toc_window_display": true, | |
"toc_section_display": "block", | |
"sideBar": true, | |
"navigate_menu": true, | |
"moveMenuLeft": true, | |
"widenNotebook": false, | |
"colors": { | |
"hover_highlight": "#DAA520", | |
"selected_highlight": "#FFD700", | |
"running_highlight": "#FF0000" | |
}, | |
"nav_menu": { | |
"width": "252px", | |
"height": "12px" | |
} | |
}, | |
"language_info": { | |
"name": "python", | |
"version": "3.6.0", | |
"mimetype": "text/x-python", | |
"codemirror_mode": { | |
"name": "ipython", | |
"version": 3 | |
}, | |
"pygments_lexer": "ipython3", | |
"nbconvert_exporter": "python", | |
"file_extension": ".py" | |
}, | |
"gist": { | |
"id": "c9e687de54a0bfbb846f65aecac2b9d9", | |
"data": { | |
"description": "alliterative_android.ipynb", | |
"public": true | |
} | |
}, | |
"_draft": { | |
"nbviewer_url": "https://gist.github.com/c9e687de54a0bfbb846f65aecac2b9d9" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment