Found Poem Generator – Adding Haikus


The wind blows in gusts
little pieces here and there
the fools in the hall

– Shadow The Poet aka James Laurie

Now that I had the Found Poem Generator working and creating poems with the number of lines asked for by the user I thought it was time to move on to the Haiku Generator idea. This would be a similar process but uses the syllable count property of each line of text. I also have the word count stored as a property which I may use later to create poems with lines of equal word length.

The Haiku has a fixed format of three lines, the first is five syllables, the second line is seven syllables, then back to five syllables for the last line.

I already had the code that generated a poem by lines, so I thought I could re-use this piece of code with some small modifications. This is always my methodology when coding – can I re-use something I’ve already done? It’s much easier to copy and paste something used in a previous project or something written in the current project rather than having to write a new section from scratch. 


When re-using code from the current project my second question is – can I modify the existing code to re-use it ‘in-situ’ rather than copying and pasting it out to the new location. What I mean by this is – can I make it a generic function? For example, we might have a piece of code that adds 1 and 1 together:

result = 1 + 1

If I needed to added two numbers together elsewhere in my program, ie 2 and 2, I could copy and paste the code above and update it to the new requirement:

result = 2 + 2

Nice and simple and works just fine, but, for me, the most elegant and de-buggable code always avoids duplication. Let’s suppose this was a more complex calculation, maybe 10 or 20 or 100 lines long, and I had used it hundreds of times in the program. Then imagine I found a bug in my calculation. Now I have to trawl though dozens or hundreds of lines of code to find and correct the problem wherever I found it. The risk being that I miss some and have now created for myself one of those annoying bugs that only appears under seemingly random circumstances and becomes harder and harder to track down. So, in circumstances like this I would always try to create a function from the original code rather than copy and paste it verbatim:

define adding_together_function(input:number1, number2, output:result):
result = number1 + number 2

Now this new function can be used whenever two numbers need adding together –

the_answer = adding_together_function (1,1)

Creating The Haiku Code

So with this in mind, I firstly updated the program to take the ‘doing’ code for the poem command out of the main loop of the program and put it into its own function. Once this was done I took a copy and changed the code so that it would select lines based on syllable count rather than just maintain a line count:

def output_by_syllable(no_of_syllables):
    found_line = 0
    while found_line == 0:
        random_num = random.randint(1,no_of_lines)
        phrase_meta = ("p" +str(random_num) )
        for phrase in Phrase._registry:
            if str( == str(phrase_meta):
                if phrase.get_used() == False:
                    if phrase.get_syllablecount() == no_of_syllables:
                        found_line = 1

With an eye to adding other syllabic poem forms to the program in the future, I then created a Haiku function that uses the ‘output_by_syllable’ function to create the Haiku:

def output_haiku():
#line 1 - 5 syllables
#line 2 - 7 syllables
#line 3 - 5 syllables

Finally I added a new menu option for generating the Haiku:

    elif command == "haiku":

I’ve added the updated code to my Dropbox share for this new feature.

the fools in the hall
little pieces here and there
The wind blows in gusts

– Shadow The Poet aka James Laurie


See a run through of progress so far:


Found Poem Generator – Introduction

“How do you go back to the beginning?
Short stories are the best,
It’s always one step behind me,
The fools in the hall.
When your life has already flown?
Our life, a wheel within a wheel.”

–  Shadow The Poet aka James Laurie

I recently undertook a course on learning Object Oriented Programming using Python. This is one of the many useful little courses provided by universities and hosted by the FutureLearn website which I occasionally frequent. I wrote about their Song Writing course featuring Martin Simpson a little while ago.

I spent a period of my life writing software using Borland Delphi, so I am familiar with Object Oriented Programming, or OOP as it is known using its TLA. My interest in this course was to get stuck into a language that is relevant to the hobbyist / creative and as pervasive as BASIC used to be back in the good old days of home computing. Python is built in to Linux, so features on many Raspberry Pi’s, and also is therefore MacOS and so fits the bill straight off. What also piqued my interest was that the course would teach using Python by using it to write a text-based adventure game, something I misspent an early part of my youth playing.

As I followed the course I had an idea of using what I had learnt so far to write a ‘Found Poem Generator’. Rather than creating dungeon rooms and items as Objects, I would create lines of a poem. These lines could then have attributes attached to them such as word count and syllable count, perhaps even metre or some other attribute. Once I had collected my lines, counted the words and syllables and fed them into the program I would then be able to generate poems. The results could then be edited and new poems would come into being. 

I felt there was precedent for this firstly as I sometimes do this anyway by looking at my book of fragments and pulling various lines out to create a new poem. Valerie Laws did something similar in 2002, although more organic than technological, by writing her lines on sheep and using the random wanderings and grouping of the sheep to create new poems.

Warm drift, graze gentle, White below the sky, Soft sheep, mirrors, Snow clouds.

– Valerie Law’s Sheep


At the moment the program can create a random poem based on my found lines which stored in one of its files. The command ‘poem’ followed by a number will cause it to generate a poem of that many random lines. I also store the number of words in the line and the number of syllables too as my next update will be to start incorporating standard poem forms into it. Haiku’s and other syllabic forms will probably be first.

The found lines are currently hardcoded into the program, as I still haven’t found out how to read data from a text file or spreadsheet yet using Python. In order to simplify things for myself I created a spreadsheet that I can use to hold my found lines. It has some text manipulation formulas in it that convert the lines I enter into the correct format for copying and pasting into the program file.

I have uploaded all this into a Dropbox folder here if you fancy a play with it, if you wouldn’t have a clue what to do with them then have a look at the FutureLearn course I did or look out for a future blog where I’ll try to explain.

“When your life has already flown?
Our life, a wheel within a wheel
The fools in the hall
The wind blows in gusts
Looking for that way home”

–  Shadow The Poet aka James Laurie


Incantation Number 7

Write something profound,
Write something meaningless,
Write for the joy of writing,
Write for the hate of writing,
Write for the ugly,
Write for the beautiful,
Write the way,
Write the time,
Write for the right now, the long goodbye and the happy ever after
Write for all the dark mornings and the long dark nights,
Write for the summer sun and the winter stars,
Write for the blazing heat, the bitter cold, the warm rain and the cold snow,
Write for the stark mountain peaks and the lush valleys depths below,
Write for rivers of ice, streams of crystal cool, gold filled, earth blood,
Write for the burning horizon an the nothing in-between,
Write for love,
Write to save your soul,
Write for peace,
Write for right and write to make the world whole,
Write to be read,
Write to be ignored,
Write to be indifferent,
Write, just write once more.

Front Room

Front room,
Drawing room or parlour.
Best room.
Now a store room.
I write at an old table,
With drawers and planks screwed down on top.
A phone, a mug and a crowbar
Are my companions.
The street is silent for a moment.
Unlike the time the neighbour’s dog
Barked for three nights long, three long nights.
The ink in my pen runs out
And as I return with a new cartridge
Aware of the headache arriving soon
I step on a splinter of wood
From the busted up wardrobe.
My bare foot bared,
The silence is over.


The Journey

‘Tell me, what is it you plan to do with your one wild and precious life?’

Mary Oliver asks of us in her poem ‘The Summer Day’. In a little over a month I’ll be heading back to Embercombe to volunteer on their ‘Journey’ programme and this question will once again be forefront in my mind.

“One day you finally knew what you had to do, and began”, again Mary Oliver guides us in her poem ‘The Journey’

A new circle will be drawn and thirty or so inquisitive, nervous, bemused and perhaps bewildered individuals will begin their Journey into themselves, and as in the ancient story of Iron John, they will serve their time in the forest, the ashes and the kitchens before finally coming triumphantly home to their own truths.

“You do not have to walk on your knees for a hundred miles through the desert, repenting”, Mary Oliver’s Wild Geese advises us. Of course, you can if you want to, we all seek redemption in our own ways but it doesn’t have to be that way.

The work has already started for me and for them, it started before I signed up, it continued as I made the space and time to participate in March and as I made the plans to leave my life here for a week, and it’s still happening now. A place and a time that had faded from my everyday thoughts was now back in them, the names, the places, the experiences. The breakdowns and breakthroughs I had taken part in, those I had witnessed and those that will take place in March.

The lake will be beckoning me, to sample its icy waters as it warms itself from its winter dreaming, the forest will call to me as it thrusts new green shoots into the coming spring, the stones will remember me, as they remember everybody. One day they may remember you as an old friend too.

And once again I will share a last goodbye before gathering up my experiences and memories of my week in the real world and taking them out there, out here, and finding my place in the world again.

“And when the sun rose

That, this morning

In your blue eyed sky

I knew my, our ending had come.

All that was left

Was to say goodbye.”