love, play & inquiry (trochee) wrote,
love, play & inquiry

twit haiku hacking

For those of you not following along on the Twitter thing, you may not know that I've built a bot:
Ohaihaiku1 is a twitterbot: a 'robot' (automated script) that identifies and retweets english language haikus. some of them are pretty good!:
Spring frock in warmth yesterday /
to tuque and snow today /
Oh Calgary

Here's how it works.
From time to time (at the moment, whenever I remember; I haven't automated this part completely yet) it looks at the twitterers it's following, and looks over all their tweets. Each tweet is cleaned up slightly, and then checked to see whether it's 17 syllables. If it is, they are reformatted as nearly as possible into 5/7/5, and retweeted.

Somewhat less often, ohaihaiku checks the twitter public timeline and pulls in a couple hundred tweets and puts them through the same process. If a haiku is found, it retweets it and "follows" that user.

Lastly, if another user 'follows' ohaihaiku, it will reciprocate2 -- and if a user 'unfollows' it, it will unfollow in return. I try to make it be polite like that.


  • There are a few challenges here still. It's not fully-automated -- I am not quite ready to put it on a server and leave it alone overnight, even though it runs all its checks with a one-word command.
  • I'd like to build out its English dictionary. It's currently based off marnanel's excellent Lingua::EN::Phoneme, which itself is built on the CMU dictionary, and when it cannot find a word's pronunciation there it falls back to some more robust hyphenation code for syllable counts. But there are lots of words (e.g. twittering) that these approaches are less than ideal for.
  • I'd like to look into some of the easier number and acronym normalizations: "lol" should be one syllable, but surely "OMG" should be three?
  • I'd like to put in some language-id. This is challenging for two reasons: (1) tweets are very short and (2) the usual approach -- character trigrams3 -- will be very sparse on such short tweets, but it will help with the occasional accidental processing of Polish or (more problematic) German. I could probably set a threshold for the percentage of words that are not in the dictionary, but I'd rather do this the Right Way with character trigrams.

Check it out! enjoy. let me know if you see things. Anybody wants to peek at the code, I can point you to some of my git repositories; several of the modules I built to support this will become CPAN distributions of their own in time.

1get it? it's like "O Hai - Haiku!"... well, I thought it was clever at the time, but the fact is, ohaihaiku does crap with mis-spellings.
2I reserve the right to un-follow and/or block spammers or people who post too many non-words.
3Character trigrams should probably be called tri-glyphs but what can you do?
  • Post a new comment


    default userpic
    When you submit the form an invisible reCAPTCHA check will be performed.
    You must follow the Privacy Policy and Google Terms of use.