Giter Club home page Giter Club logo

quote_randomizer's Introduction

quote_randomizer

Randomizes an actual quote by switching 1-3 words with ones of matching type.

You must trust and believe in hardware or life becomes impossible.
--Anton Chekhov

original: You must trust and believe in people or life becomes impossible.

This script uses the Natural Language Toolkit (nltk) module to split an orginal quote to part-of-speech tags (POS tags), such as nouns and verbs. Randomization is then done by replacing randomly chosen words with new words of same POS tags. New words are chosen from an internal nltk dataset. Quotes are chosen from a local SQLite database collected from several sources, see below.

Since a word's POS tag is dependant on the context of the sentence around it, this script analyzes the quote in 3-grams, ie. replacing is done so that the new words orignally appeared in a context where the two adjacent words had the same POS tags as in the quote to randomize.

https://www.nltk.org/

Usage

First, install dependencies in a virtualenv with

python3 -m virtualenv venv
source venv/bin/activate
pip install -r requirements.txt

To utilize the nltk module, some additional data is needed:

python -m nltk.downloader book

This includes a corpora and tokenizer, see https://www.nltk.org/data.html.

Then, build a database of quotes with

python main.py --build-database

Finally, generate a randomized quote with

python main.py --quote

Unit tests

Unit tets can be run with

pytest

Quote sources

The quote database is buit from the quotes in data/quotes.txt. This file contains a collection of quotes from people, books, movies, games as well as facts, song lyrics, poem lines, proverbs and company slogans. These are collected from multiple online sources, including

quote_randomizer's People

Contributors

lajanki 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.