Advertisement
Guest User

Untitled

a guest
Mar 19th, 2019
169
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.76 KB | None | 0 0
  1. {
  2. "cells": [
  3. {
  4. "cell_type": "markdown",
  5. "metadata": {},
  6. "source": [
  7. "# Harry Potter and Sorcerer's Stone\n",
  8. "\n",
  9. "The program generates critic about \"Harry Potter and Sorcerer's Stone\" book using Tracery. \n",
  10. "I used some Corpora data such as encouraging words, nouns, adjectives, moods and spells."
  11. ]
  12. },
  13. {
  14. "cell_type": "code",
  15. "execution_count": 5,
  16. "metadata": {},
  17. "outputs": [],
  18. "source": [
  19. "import tracery\n",
  20. "import textwrap\n",
  21. "import json\n",
  22. "from tracery.modifiers import base_english\n",
  23. "from collections import Counter\n",
  24. "\n",
  25. "first_names = json.load(open(\"./firstNames.json\"))['firstNames']\n",
  26. "last_names = json.load(open(\"./authorLastNames.json\"))['authors']\n",
  27. "encouraging_words = json.load(open(\"./encouraging_words.json\"))['encouraging_words']\n",
  28. "harvard_sentences = json.load(open(\"./harvard_sentences.json\"))['data']\n",
  29. "nouns = json.load(open(\"./nouns.json\"))['nouns']\n",
  30. "adjs = json.load(open(\"./adjs.json\"))['adjs']\n",
  31. "moods = json.load(open(\"./moods.json\"))['moods']\n",
  32. "monsters = json.load(open(\"./monsters.json\"))['names']\n",
  33. "\n",
  34. "spells_raw = json.load(open(\"./spells.json\"))['spells']\n",
  35. "spells = [item['incantation'] for item in spells_raw];"
  36. ]
  37. },
  38. {
  39. "cell_type": "code",
  40. "execution_count": 16,
  41. "metadata": {
  42. "scrolled": true
  43. },
  44. "outputs": [
  45. {
  46. "name": "stdout",
  47. "output_type": "stream",
  48. "text": [
  49. "Incendio! Harry, Ron and Hermione find themselves\n",
  50. "forgotten in a life-sized method, in which they\n",
  51. "become cyclopses. Two mastered things here: First,\n",
  52. "Harry recognizes that Ron is more rotating than\n",
  53. "he. Secondly, Ron proves himself to be such a low-\n",
  54. "budget workman to Harry. A brimstone textured\n",
  55. "first novel given lift-off by an bungling wit. As\n",
  56. "long as Sorcerer's Stone has the power to turn\n",
  57. "custard to prospectus and to give minor to humans.\n",
  58. " \n",
  59. "- Dylan Kosinski\n"
  60. ]
  61. }
  62. ],
  63. "source": [
  64. "rules = {\n",
  65. " \"origin\": [\n",
  66. " \"#spell#!\\n Harry, Ron and Hermione find themselves #mood# in a life-sized #noun#, in which they become #monster.s#.\\n\"+\n",
  67. " \"Two #adjective# things here: First, Harry recognizes that Ron is more #adjective# than he. Secondly, Ron proves himself to be such a #adjective# #noun# to Harry.\\n\"+\n",
  68. " \"A #adjective# textured first novel given lift-off by an #adjective# wit.\\n\"\n",
  69. " \"As long as Sorcerer's Stone has the power to turn #noun# to #noun# and to give #adjective# to humans.\\n\"\n",
  70. " ],\n",
  71. " \"author\": \"- #first_name# #last_name#\",\n",
  72. " \"harvard_sentence\": harvard_sentences,\n",
  73. " \"first_name\": first_names,\n",
  74. " \"last_name\": last_names,\n",
  75. " \"encouraging_word\": encouraging_words,\n",
  76. " \"spell\": spells,\n",
  77. " \"noun\": nouns,\n",
  78. " \"adjective\": adjs,\n",
  79. " \"mood\": moods,\n",
  80. " \"monster\": monsters\n",
  81. " \n",
  82. "}\n",
  83. "grammar = tracery.Grammar(rules)\n",
  84. "grammar.add_modifiers(base_english)\n",
  85. "\n",
  86. "print(textwrap.fill(grammar.flatten(\"#origin#\"), width = 50)) \n",
  87. " \n",
  88. "print(' \\n' + grammar.flatten(\"#author#\"))\n"
  89. ]
  90. },
  91. {
  92. "cell_type": "markdown",
  93. "metadata": {},
  94. "source": [
  95. "Reparo! Harry, Ron and Hermione find themselves\n",
  96. "antagonistic in a life-sized laborer, in which\n",
  97. "they become lamassus. Two gilded things here:\n",
  98. "First, Harry recognizes that Ron is more\n",
  99. "fallacious than he. Secondly, Ron proves himself\n",
  100. "to be such a disabling anthropology to Harry. A\n",
  101. "solid-state textured first novel given lift-off by\n",
  102. "an vaulting wit. As long as Sorcerer's Stone has\n",
  103. "the power to turn retention to endangerment and to\n",
  104. "give trying to humans.\n",
  105. " \n",
  106. "- Ashley Shapiro\n",
  107. "\n",
  108. "Liberacorpus! Harry, Ron and Hermione find\n",
  109. "themselves offended in a life-sized locality, in\n",
  110. "which they become imps. Two bounded things here:\n",
  111. "First, Harry recognizes that Ron is more inflate\n",
  112. "than he. Secondly, Ron proves himself to be such a\n",
  113. "garbled effectiveness to Harry. A uppity textured\n",
  114. "first novel given lift-off by an injurious wit. As\n",
  115. "long as Sorcerer's Stone has the power to turn\n",
  116. "oxygen to ranger and to give worst-case to humans.\n",
  117. " \n",
  118. "- Madison Dostoyevsky\n",
  119. "\n",
  120. "Incendio! Harry, Ron and Hermione find themselves\n",
  121. "forgotten in a life-sized method, in which they\n",
  122. "become cyclopses. Two mastered things here: First,\n",
  123. "Harry recognizes that Ron is more rotating than\n",
  124. "he. Secondly, Ron proves himself to be such a low-\n",
  125. "budget workman to Harry. A brimstone textured\n",
  126. "first novel given lift-off by an bungling wit. As\n",
  127. "long as Sorcerer's Stone has the power to turn\n",
  128. "custard to prospectus and to give minor to humans.\n",
  129. " \n",
  130. "- Dylan Kosinski"
  131. ]
  132. },
  133. {
  134. "cell_type": "code",
  135. "execution_count": null,
  136. "metadata": {},
  137. "outputs": [],
  138. "source": []
  139. },
  140. {
  141. "cell_type": "code",
  142. "execution_count": null,
  143. "metadata": {},
  144. "outputs": [],
  145. "source": []
  146. }
  147. ],
  148. "metadata": {
  149. "kernelspec": {
  150. "display_name": "Python 3",
  151. "language": "python",
  152. "name": "python3"
  153. },
  154. "language_info": {
  155. "codemirror_mode": {
  156. "name": "ipython",
  157. "version": 3
  158. },
  159. "file_extension": ".py",
  160. "mimetype": "text/x-python",
  161. "name": "python",
  162. "nbconvert_exporter": "python",
  163. "pygments_lexer": "ipython3",
  164. "version": "3.7.1"
  165. }
  166. },
  167. "nbformat": 4,
  168. "nbformat_minor": 2
  169. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement