Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {
- "cells": [
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "# Harry Potter and Sorcerer's Stone\n",
- "\n",
- "The program generates critic about \"Harry Potter and Sorcerer's Stone\" book using Tracery. \n",
- "I used some Corpora data such as encouraging words, nouns, adjectives, moods and spells."
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 5,
- "metadata": {},
- "outputs": [],
- "source": [
- "import tracery\n",
- "import textwrap\n",
- "import json\n",
- "from tracery.modifiers import base_english\n",
- "from collections import Counter\n",
- "\n",
- "first_names = json.load(open(\"./firstNames.json\"))['firstNames']\n",
- "last_names = json.load(open(\"./authorLastNames.json\"))['authors']\n",
- "encouraging_words = json.load(open(\"./encouraging_words.json\"))['encouraging_words']\n",
- "harvard_sentences = json.load(open(\"./harvard_sentences.json\"))['data']\n",
- "nouns = json.load(open(\"./nouns.json\"))['nouns']\n",
- "adjs = json.load(open(\"./adjs.json\"))['adjs']\n",
- "moods = json.load(open(\"./moods.json\"))['moods']\n",
- "monsters = json.load(open(\"./monsters.json\"))['names']\n",
- "\n",
- "spells_raw = json.load(open(\"./spells.json\"))['spells']\n",
- "spells = [item['incantation'] for item in spells_raw];"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": 16,
- "metadata": {
- "scrolled": true
- },
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "text": [
- "Incendio! Harry, Ron and Hermione find themselves\n",
- "forgotten in a life-sized method, in which they\n",
- "become cyclopses. Two mastered things here: First,\n",
- "Harry recognizes that Ron is more rotating than\n",
- "he. Secondly, Ron proves himself to be such a low-\n",
- "budget workman to Harry. A brimstone textured\n",
- "first novel given lift-off by an bungling wit. As\n",
- "long as Sorcerer's Stone has the power to turn\n",
- "custard to prospectus and to give minor to humans.\n",
- " \n",
- "- Dylan Kosinski\n"
- ]
- }
- ],
- "source": [
- "rules = {\n",
- " \"origin\": [\n",
- " \"#spell#!\\n Harry, Ron and Hermione find themselves #mood# in a life-sized #noun#, in which they become #monster.s#.\\n\"+\n",
- " \"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",
- " \"A #adjective# textured first novel given lift-off by an #adjective# wit.\\n\"\n",
- " \"As long as Sorcerer's Stone has the power to turn #noun# to #noun# and to give #adjective# to humans.\\n\"\n",
- " ],\n",
- " \"author\": \"- #first_name# #last_name#\",\n",
- " \"harvard_sentence\": harvard_sentences,\n",
- " \"first_name\": first_names,\n",
- " \"last_name\": last_names,\n",
- " \"encouraging_word\": encouraging_words,\n",
- " \"spell\": spells,\n",
- " \"noun\": nouns,\n",
- " \"adjective\": adjs,\n",
- " \"mood\": moods,\n",
- " \"monster\": monsters\n",
- " \n",
- "}\n",
- "grammar = tracery.Grammar(rules)\n",
- "grammar.add_modifiers(base_english)\n",
- "\n",
- "print(textwrap.fill(grammar.flatten(\"#origin#\"), width = 50)) \n",
- " \n",
- "print(' \\n' + grammar.flatten(\"#author#\"))\n"
- ]
- },
- {
- "cell_type": "markdown",
- "metadata": {},
- "source": [
- "Reparo! Harry, Ron and Hermione find themselves\n",
- "antagonistic in a life-sized laborer, in which\n",
- "they become lamassus. Two gilded things here:\n",
- "First, Harry recognizes that Ron is more\n",
- "fallacious than he. Secondly, Ron proves himself\n",
- "to be such a disabling anthropology to Harry. A\n",
- "solid-state textured first novel given lift-off by\n",
- "an vaulting wit. As long as Sorcerer's Stone has\n",
- "the power to turn retention to endangerment and to\n",
- "give trying to humans.\n",
- " \n",
- "- Ashley Shapiro\n",
- "\n",
- "Liberacorpus! Harry, Ron and Hermione find\n",
- "themselves offended in a life-sized locality, in\n",
- "which they become imps. Two bounded things here:\n",
- "First, Harry recognizes that Ron is more inflate\n",
- "than he. Secondly, Ron proves himself to be such a\n",
- "garbled effectiveness to Harry. A uppity textured\n",
- "first novel given lift-off by an injurious wit. As\n",
- "long as Sorcerer's Stone has the power to turn\n",
- "oxygen to ranger and to give worst-case to humans.\n",
- " \n",
- "- Madison Dostoyevsky\n",
- "\n",
- "Incendio! Harry, Ron and Hermione find themselves\n",
- "forgotten in a life-sized method, in which they\n",
- "become cyclopses. Two mastered things here: First,\n",
- "Harry recognizes that Ron is more rotating than\n",
- "he. Secondly, Ron proves himself to be such a low-\n",
- "budget workman to Harry. A brimstone textured\n",
- "first novel given lift-off by an bungling wit. As\n",
- "long as Sorcerer's Stone has the power to turn\n",
- "custard to prospectus and to give minor to humans.\n",
- " \n",
- "- Dylan Kosinski"
- ]
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- },
- {
- "cell_type": "code",
- "execution_count": null,
- "metadata": {},
- "outputs": [],
- "source": []
- }
- ],
- "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.7.1"
- }
- },
- "nbformat": 4,
- "nbformat_minor": 2
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement