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
https://ijameslaurie.com/2018/11/03/found-poem-generator-introduction/

Python ‘Found Poem’ Generator – Part 2 – Adding Haikus
https://ijameslaurie.com/2018/11/13/found-poem-generator-adding-haikus/

Python ‘Found Poem’ Generator – Part 3 – The Next Level
https://ijameslaurie.com/2018/11/13/found-poem-generator-the-next-level/

Python ‘Found Poem’ Generator – Part 4 – Outputting Text To A Graphical Screen
https://ijameslaurie.com/2018/11/14/found-poem-generator-outputting-text-to-a-graphical-screen/

Python ‘Found Poem’ Generator – Part 5 – User Interaction – Adding Buttons
https://ijameslaurie.com/2018/11/16/found-poem-generator-user-interaction-adding-buttons/

Python ‘Found Poem’ Generator – Part 6 – Loading Data From A File
https://ijameslaurie.com/2018/11/21/found-poem-generator-loading-data-from-a-file/

–> This one –>Python ‘Found Poem’ Generator – Part 7 – Counting Syllables and Words
https://ijameslaurie.com/2018/12/03/found-poem-generator-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 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!

James

Leave a Reply

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

WordPress.com Logo

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

Google photo

You are commenting using your Google 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