Git Product home page Git Product logo

haikufinder's Introduction

Build Status

Installation requires NLTK and its punkt package. First-time steps:

pip install nltk
python -m nltk.downloader punkt
python setup.py install

A script to begin processing is located in /scripts.

A Python hack to find "haikus" in English text. For the purposes of this module, a "haiku" is one or more complete sentences that, together, can be broken into groups of 5, 7, and 5 syllables. Each candidate haiku line, and then the entire haiku, has to make it through a few heuristics to filter out constructions that are likely to scan awkwardly (like verb phrases split across lines). Since this code doesn't really try to understand the texts, it might throw away a few legitimate phrases, and it certainly lets through some bad ones.

Any improvements would be welcomed.

The license, found in license.txt, is "modified BSD".

Example usage:

text = open("ulysses.txt", "r").read()
haikus = HaikuFinder(text).find_haikus()
for haiku in haikus:
    print haiku[0]
    print "    %s" % haiku[1]
    print haiku[2]
    print

If you find that the HaikuFinder doesn't seem to recognize some word you're using, or is counting its syllables incorrectly, you can say

HaikuFinder.add_word('shmeggegge', 3)
HaikuFinder.add_word('kvetch', 1)
haikus = HaikuFinder('''
	For this I should stay? To hear some shmeggegge kvetch about his lawsuit?
	''').find_haikus()

If you like, you can fork the project, modify the custom.dict, and submit a pull request. I'll accept all useful dictionary additions.

haikufinder's People

Contributors

stucka avatar crccheck avatar google-feinberg avatar marknenadov avatar

Watchers

 avatar James Cloos avatar  avatar

haikufinder's Issues

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.