Peter's Haiku Generator - Information



The Haiku generating Javascript program works by producing sentences using a predefined, limited vocabulary of up to 400 words, and a set of grammatical parsing rules.

The rules are given below. If you're not familiar with the format, then:

The Rules

<sentence> = <single sentence>[<conjunction><single sentence>]

<single sentence> = [<gerund phrase>]<simple sentence>

<simple sentence> = <noun phrase>[<adverb phrase>]<intransitive verb>[<preposition><noun phrase>]
                    <noun phrase><intransitive verb>[<preposition><noun phrase>][<adverb phrase>]
                    [<adverb phrase>]<noun phrase><intransitive verb>[<preposition><noun phrase>]
                    <noun phrase><transitive verb phrase><noun phrase>

<noun phrase> = "The "[<adjective phrase>]<improper noun>
                [<adjective phrase>]<proper noun>
                "A "[<adjective phrase>]<improper singular noun>

<gerund phrase> = [<adverb phrase>]<gerund>

<adverb phrase> = [<adverb>]<adverb>

<transitive verb phrase> = [<adverb phrase>]<transitive verb>

<adjective phrase> = <simple adjective>[" , "<simple adjective>]

<simple adjective> = <adjective>[<adjective>]
                     [<adverb>]<adjective>

Note that terms used in defining the rules are based on normal grammatical terms, but don't necessarily have exactly the conventional meanings.

These rules are the same as those used in my poetry engine. To make the haiku, I get the program to count syllables as it's making up the sentence. There are a few extra rules, so that the generator doesn't start making a simple sentence into a compound one if it's already close to the required syllable count for example. When it's finished, it sees if it has the right number. If it doesn't, it just throws the sentence away and tries again. If it doesn't get it right within ten goes, it gives up and just prints what it has anyway. (That's the reason for the nonsense about constraints on artistic expression - it's a bit of a kludge, but I thought the explanation rather endearing.)

I think the haiku are more successful than the tanka, but it was just a trivial addition to put in the option. The idea for adding the syllabics to the generator came from Jane Dorner, to whom I'm very grateful.

The Vocabularies

The program allows the user to select from a number of vocabularies. Those available at the moment include:

If you are interested in suggesting a new vocabulary, email me and we can discuss it.

The Javascript

If you wish to examine or make use of the code, please feel free. If you re-use or adapt my code, I would appreciate an acknowledgement. Only click on the following links if you want to load the files directly to examine or download them. You can't run the program by using these links.

Thank you for your interest. You may now return to the haiku generator, or go back to my home page.


This page is maintained by and copyright by Peter Howard (Contact Peter)