Function Repository Resource:

RandomEnglishHaiku

Source Notebook

Generate a haiku

Contributed by: Bob Sandheinrich

ResourceFunction["RandomEnglishHaiku"][]

generates a random English-language haiku.

ResourceFunction["RandomEnglishHaiku"][words]

generates the haiku using the provided word list.

Details and Options

A haiku consists of three lines with syllable lengths of 5-7-5.
The default set of words is provided by WordList.
Words are not repeated within a line, but may be repeated in a haiku.
No punctuation or capitalization is added.
Syllables are determined using the resource function WordSyllables.

Examples

Basic Examples (2) 

Generate a haiku:

In[1]:=
ResourceFunction["RandomEnglishHaiku"][]
Out[1]=

Create a haiku using words from Hamlet:

In[2]:=
ResourceFunction["RandomEnglishHaiku"][
 TextWords[ResourceData["Hamlet"]]]
Out[2]=

Scope (1) 

Generate many haikus:

In[3]:=
Column@Table[Framed@ResourceFunction["RandomEnglishHaiku"][], {10}]
Out[3]=

Possible Issues (3) 

Some word lists can not create haikus:

In[4]:=
ResourceFunction[
 "RandomEnglishHaiku"][{"supercalifragilisticexpialidocious", "superpolysyllabic"}]
Out[4]=

Because words are not repeated within a line, small lists also will not produce results:

In[5]:=
ResourceFunction["RandomEnglishHaiku"][{"a"}]
Out[5]=

Include enough words to fill each line:

In[6]:=
ResourceFunction[
 "RandomEnglishHaiku"][{"bob", "make", "poem", "thing", "not", "fancy"}]
Out[6]=

Neat Examples (2) 

Highlight syllables in a haiku:

In[7]:=
StringRiffle[
 Row /@ (Map[
    ResourceFunction["HighlightText"][#, _, "DefaultColor" -> RandomColor[
        RGBColor[1, RandomReal[{.5, 1}], _]]] &, (ResourceFunction[
       "WordSyllables"] /@ StringSplit@ResourceFunction["RandomEnglishHaiku"][]), {2}])]
Out[7]=

Create a haiku for a bird:

In[8]:=
ResourceFunction["BirdSay"][
 ResourceFunction["RandomEnglishHaiku"][
  TextWords[WikipediaData["Bird vocalization"]]]]
Out[8]=

Publisher

Bob

Version History

  • 1.0.0 – 06 February 2020

Related Resources

License Information