Code Monkey home page Code Monkey logo

textillating's Introduction

Textillating

This is my little project for National Novel Generation Month 2018. It is complete (for now).

About

Ever wished the novel you were reading was way more exciting? Try Textillating it!

The user inputs a .txt file (like a novel), and the script outputs a modified version of the file wherein most adjectives have been replaced by their most extreme synonyms. In other words, the affect has been amped up.

For example, here's a paragraph from Great Expectations, as it is originally written:

"Yes; but my dear Handel," Herbert went on, as if we had been talking, instead of silent, "its having been so strongly rooted in the breast of a boy whom nature and circumstances made so romantic, renders it very serious. Think of her bringing-up, and think of Miss Havisham. Think of what she is herself (now I am repulsive and you abominate me). This may lead to miserable things." "I know it, Herbert," said I, with my head still turned away, "but I can't help it." "You can't detach yourself?" "No. Impossible!" "You can't try, Handel?" "No. Impossible!"

And here's the same paragraph after being run through textillating.py:

"Yes; but my LOVE Handel," Herbert went on, as if we had been talking, instead of silent, "its having been so strongly rooted in the breast of a boy whom nature and circumstances made so ROMANTICIST, renders it very DANGEROUS! Think of her bringing-up, and think of Miss Havisham! Think of what she is herself (now I am EMINENTLY REPULSIVE and you abominate me)! This may lead to PATHETIC things!" "I know it, Herbert," said I, with my head still turned away, "but I can't help it!" "You can't detach yourself??!!" "No! SEVERELY IMPOSSIBLE!!!!!!!!!!!!!" "You can't try, Handel??!!" "No! ASTONISHINGLY IMPOSSIBLE!!!!!!!!!!!!!"

This project uses the VADER sentiment analysis tools and WordNet from NLTK (Natural Language Tool Kit). The SentimentIntensityAnalyzer quantifies how affective a word (or sentence) is, and WordNet finds a replacement. Here's what those scores look like:

Word Sentiment polarity score
awesome 0.6249
good 0.4404
fine 0.2023
terrible -0.4767
abhorrent -0.6249

When Textillating encounters an adjective, it finds its sentiment polarity score, then checks for any synonyms from WordNet that have more extreme scores. So fine might be replaced by awesome, and terrible might be replaced by abhorrent.

If the adjective's sentiment polarity score is 0, or if there are no viable synonyms, the adjective is modified by an additional adverb. For instance: necessary might be replaced by intensely necessary.

All replaced words are output in all caps. Some simple punctuation changes are also implemented.

How to use

To use Textillating, run in on the command line like so:

python textillating.py [filename you want to use.txt]

You'll need to pip install nltk and pip install wordfilter if you don't already have those.

Textillating needs a plain text .txt file. You can find lots of boring classic novels on Project Gutenberg.

I have included an example of a novel that I found so boring I did not finish it. (Sorry, 10th grade English teacher!) If there's a filename issue, it will use Great Expectations instead.

Issues

  • The NLTK part-of-speech tagger I'm using is not great and mislabels some adjectives.
  • The de-tokenizer currently has no idea what to do with quotation marks, so the output looks quite wonky.

See also

I became interested in this in the course of working on my Nondescript project, which guides a user in changing their writing "style" is it is computed by stylometric analyses. The 2010 paper "Automatic Synonym and Phrase Replacement Show Promise for Style Transformation" (Khosmood and Levinson) used WordNet and ranked possible synonyms by statistical popularity. It got me thinking about other ways to rank synonyms, like by affect!

textillating's People

Contributors

robincamille avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.