‘Found Poem’ Generator – Counting Syllables and Words

I was thinking about future possibilities for the ‘Found Poem’ Generator to make it a much more interactive experience or at least requiring less hassle in setting up the phrases csv file. Where I’d left the last version anyone could customise an installation by adding their own phrases to the csv file but they would still then have to provide a syllable count and word count for each phrase line. On the face of it, if doesn’t sound too much hassle, after all it only needs doing once. But what if we were dealing with hundreds or even thousands of lines? What if we were crowd-sourcing the phrases or reading them in from a Twitter feed or other automation possibilities? 

I did a quick internet search and was surprised to find that syllable counting actually breaks down to a very simple set of rules.

Syllable Counting

Another search found some sample code which I was able to bolt into the program to count the number of syllables of any phrases where the syllable count hasn’t been supplied in the csv file. Having played with it for a while I’m not overlay happy with some of the numbers it comes up with, for example this phrase:

“When your hopes and fears are drowned”

I count this to have 7 syllables, with a stretch I could turn ‘drowned’ into ‘drown-ed’ and give it two syllables. The code I have used counts it as 10. I can easily overcome this by having the correct syllable count in the csv file but I will be looking at the code further to try to improve it.

Word Counting


A further search uncovered some code that counts the number of words in a phrase. I also added this into the program to count the number of words where the word count hasn’t been provided in the phrases cvs file.

Tidying Up


One last little update was to start making the csv file import more robust. At the moment I am in complete control of the csv import file so I know it will work, looking ahead to the future again this import mechanism needs to be much more robust to handle any issues in a csv file created by other people.

An updated version of the source code is here in my Dropbox.