Estimating Syllables

The English language, unlike many other languages, has no set rules for what does and doesn’t make a syllable; the dictionary definition is ‘an uninterrupted sound’ that helps to form words. Some dictionaries go onto explain that they can estimated by counting the number of vowels that are surrounded on either side by a syllable.

This basic method actually works in about 75% of the cases that I tried with it. In fact, if you assume Y as a vowel it works with every word in the previous sentence. The problem, however, is that vowels can sometimes appear next to one another and in some cases they will form one continuous sound (such as the io in action) or form two separate sounds (such as the io in lion).

What, therefore, can we do to combat this? The first method is to look for sounds that contain multiple vowels and remove one of the vowels, so ome becomes om and ime becomes im – using the previous method sometime would have four syllables, however by replacing these two sounds we instead correctly identify somtim as having two syllables. I equally found that it was necessary to convert ine to in, ely to ly and ure to ur.

This then solves quite a few problems. Here are some example sentences using solely this method:

  • Shall I compare thee to a summer’s day? = 11
  • Thou art more lovely and more temperate = 13
  • The winds do shake the darling buds of may = 11

Clearly there are faults with this current algorithm, given that Shakespearean sonnets are set in iambic pentameter and therefore have 10 syllables per line (I did find examples, however, where the pronunciation of a word is completely different today, and so my algorithm doesn’t work as effectively on Shakespearean English). By outputting the number of syllables that the program thought was in each word I was able to identify a fault:

  • Compare = 3 syllables
  • More = 2 syllables
  • Temperate = 4 syllables

If the word ended in an e (and later I discovered that provided it didn’t end in le) then there was one fewer syllable than I had originally thought, so I simply adapted the program to subtract one at the end if appropriate, as well as handling plural words to (so compares has the s stripped off and e is considered its last letter).

-e wasn’t the only suffix that I’ve had problems with; -ing causes similar problems. For example, according to the current version walking has two syllables whereas going or flying have only one. Thankfully the rule for fixing this is relatively simple: if the word ends in -ing (or -ings) and the letter immediately before that is a vowel then one syllable should be added. I final suffix that causes problems in a similar fashion (there are others, I won’t discuss them all here) is -ed because happened only has two syllables but the program estimates 3. Despite this, fainted does have two syllables which are correctly found. Therefore I have to examine whether or not there is a proceeding t or d and if there is not then remove a syllable.

So how accurate is the algorithm in its current state? Let’s compare the lines of the sonnet again:

  • Shall I compare thee to a summer’s day? = 10
  • Thou art more lovely and more temperate = 10
  • Rough winds do shake the darling buds of may = 10
  • And summer’s lease hath all to short a date = 10

OK, this is a pretty significant improvement but the algorithm is still far from perfect. For example, taking the first sentence of this post incorrectly identifies didn’t as having only one syllable and languages as having only two, however gets everything else correct.

In my case I did not want to write a 100% accurate algorithm and I believe to do so would probably require a great number of defined ‘special cases’ that would lead to the algorithm becoming bloated, which is a shame because it currently occupies just over 20 lines of C# code.

This algorithm is suited to counting syllables however it is not yet capable of finding syllables. In some cases people may pronounce a word differently (such as long-er and lon-ger) and in some cases it is not clear which letter starts and ends a syllable. Furthermore, language (common use English especially) is slowly devolving towards using fewer syllables in words – missing out the letter t (a pet hate) significantly reduces the number of syllables in one’s speech.

You can check out the source code on GitHub.

Advertisements

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 )

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s