Haiku

Component ID

1552792

Component name

Haiku

Component type

module

Maintenance status

Development status

Component security advisory coverage

covered

Downloads

978

Component created

Component changed

Component body

Haiku is a silly module that provides a way for end-users and developers to parse haikus out of any arbitrary text. Likely it's not very useful or practical in any way, but hopefully it's at least a little fun.

Features

  • A page with a basic form (located at /parse-haikus) that returns haikus parsed from user-entered text.
  • A field formatter "Haiku" which prints a haiku parsed from a text fields' contents.
  • A simple, extendable interface for developers to parse any arbitrary text into haikus.

Developers

Here is some sample code to get you started.

  // Instantiating a HaikuSource object parses haikus from within text you pass in.
  $haiku_text = new HaikuSource($node->body[LANGUAGE_NONE][0]['value']);

  // The getHaikus method returns an array of Haiku objects.
  $haikus = $haiku_text->getHaikus();

  // Haiku objects have a toString method that takes a delimiter.
  echo $haikus[0]->toString('<br />');

  // Simply echo'ing a haiku also works, but it defaults to a newline delimiter.
  echo $haikus[0];

For more details, see /includes/haiku.inc. If you're interested in the algorithm itself, extending it, or implementing your own, in addition to haiku.inc, see haiku_default.inc for full implementation details.

The Pitfalls of Natural Language Processing

It's extremely difficult to accurately count syllables in a word (see this related, though slightly different dissertation on word hyphenation). It may be simpler in languages other than English (which this module currently does not support), but English happens to be a language riddled with many exceptions. I encourage you to propose additions/changes to the algorithm in the issue queues. If you have a completely different approach in mind, let's talk about a 2.x branch.