Python ‘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.

More posts in this series:

Python ‘Found Poem’ Generator – Part 1 – Introduction

Python ‘Found Poem’ Generator – Part 2 – Adding Haikus

Python ‘Found Poem’ Generator – Part 3 – The Next Level

Python ‘Found Poem’ Generator – Part 4 – Outputting Text To A Graphical Screen

Python ‘Found Poem’ Generator – Part 5 – User Interaction – Adding Buttons

Python ‘Found Poem’ Generator – Part 6 – Loading Data From A File

–> This one –>Python ‘Found Poem’ Generator – Part 7 – Counting Syllables and Words

Thank you again to all my followers and regular readers, and hello to you if you are new to my blog!

There’s an eclectic mix of posts on here, from writing and poetry to banjos and guitars, art, photography and computing, so feel free to dive in and have a look around,

New to this site? Click here to visit my About Me section.

Follow me @ponyfolk on Instagram for my multi-medium art and @shadowthepoet on Twitter

Want to introduce yourself, your art, your blog or you world and discover all that is new in the world? Click here for my ‘Join the Revolution’ page.

Go well!

4 thoughts on “Python ‘Found Poem’ Generator – Counting Syllables and Words

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s