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.

  • $\begingroup$ Thanks! I've implemented my function as such: wordSyllableCount[word_] := WordData[word, "Hyphenation"] // Length $\endgroup$ – jxmorris12 Apr 3 '17 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

syllable 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

fixed up syllable grid

This seems workable. Adjust fixup to taste.

  • $\begingroup$ Just the first paragraph warranted a +1. :D $\endgroup$ – J. M.'s torpor Apr 2 '17 at 4:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.