# Finding the number of syllables in a string of text

To implement a readability algorithm, I need to find the number of symbols in a long string of text (almost 5000 words). There doesn't seem to be a built-in Mathematica function that can count the number of syllables in an English word or string of words. What is the fastest and most efficient way to find this value?

I think you should look at WordData.

WordData["hyphenation", "Hyphenation"]


{"hy", "phen", "a", "tion"}

The definition of what is a syllable in English is tricky. The algorithm used by WordData may give results that do not agree with the syllable division you will find in a particular dictionary (which may give more than one syllable division for a given word), but I think mapping WordData over the words in your text would be the easiest way to proceed in Mathematica.

• Thanks! I've implemented my function as such: wordSyllableCount[word_] := WordData[word, "Hyphenation"] // Length Apr 3, 2017 at 22:34

The Unified Syllable Theory for English is due shortly after the unification of the relativity and quantum theories and the cure for the common cold. Can I talk you into using a language with a simpler syllable definition? Esperanto, maybe? No?

Kidding aside, we could try using the built-in hyphenation functionality as a way to approximate syllable count:

WordData["antidisestablishmentarianism", "Hyphenation"]
(* {"an", "ti", "dis", "es", "tab", "lish", "men", "tar", "i", "an", "ism"} *)

% // Length
(* 11 *)


To try this out, let's take the first 20 unique words from Alice In Wonderland...

$words = ExampleData[{"Text","AliceInWonderland"}] // ToLowerCase // StringCases[#, LetterCharacter..]& // Union // Take[#, 20]&;  ... and review the hyphenation data: {#, WordData[#, "Hyphenation"]}& /@$words // Grid


Hmmm... a lot of missing data. Oh, right... English. We can replace the missing data with an approximation based upon letter count:

fixup[{w_, s_List}] := {w, Length[s]}
fixup[{w_, _Missing}] := {w, Ceiling[StringLength[w] / 3]}


So then...

fixup @ {#, WordData[#, "Hyphenation"]}& /@ \$words // Grid


This seems workable. Adjust fixup to taste.

• Just the first paragraph warranted a +1. :D Apr 2, 2017 at 4:46