How can I Count every word with three or more syllables in each group of sentences, even if the same word appears more than once.

9 views (last 30 days)
Count every word with three or more syllables in each group of sentences, even if the same word appears more than once from a text file
syllables means a unit of pronunciation having one vowel sound, with or without surrounding consonants, forming the whole or a part of a word;
  8 Comments
Image Analyst
Image Analyst on 28 Sep 2017
What is a "sentence"? A text string, or an audio waveform? You'd have different solutions in the two cases.
Also, do you have a look up table of the number of syllables that each word you expect to encounter has? This would make it much easier of course.
The number of syllables can depend on the accent. For example English in the southern US often adds extra syllables. For example "well" might be pronounced "way-uhl" in the south. Sometimes (though I think rarely), they eliminate syllables, e.g. "you all" becomes a single syllable "yall".

Sign in to comment.

Accepted Answer

OCDER
OCDER on 28 Sep 2017
Edited: OCDER on 28 Sep 2017
The only way you can do this is by using a database of word-syllable. Here's one way using www.dictionary.com as the database.
FullText = 'This is a really arbitrary sentence.';
%'really' could be pronounced 'ree-uh-lee' (3 syl)
TextCell = regexp(FullText, '\w+', 'match');
TextSyl = cellfun(@(x) getSyllable(x), TextCell);
TextSyl =
1 1 1 3 4 2
OneSylWord = sum(TextSyl == 1);
OneSylWord =
3
Where getSyllable function is:
function Syl = getSyllable(Word)
if nargin == 0
Word = input('What word do you want? ', 's');
end
if isempty(Word)
Syl = 0;
return
end
Word = strrep(Word, ' ', '');
% Use dictionary.com to get the phonetic transcription of a word
% Ex: arbitrary
% [ahr-bi-trer-ee]
% WARNING: will not work for some words if dictionary.com does not have it
% listed as the main word. Example, 'awesomeness' returns 2 because
%' awesome' is the main word in the site.
try
SiteTxt = urlread(sprintf('http://www.dictionary.com/browse/%s?s=t', Word));
catch
warning('Could not determine syllable for "%s". Returning 0.', Word);
Syl = 0;
return
end
CodeSrch1 = '"pron spellpron"[\s\w\d\>]+\[\s*(?<InnerCode>[^\]]+)';
InnerCode = regexp(SiteTxt, CodeSrch1, 'tokens');
InnerCode = InnerCode{1};
CodeSrch2 = '>(?<Phonetics>[^\<]+)';
Phonetics = regexp(InnerCode, CodeSrch2, 'tokens');
Phonetics = [Phonetics{1}{:}];
if isempty(Phonetics)
Syl = 1;
else
Phonetics = cat(2, Phonetics{:});
MultWord = regexp(Phonetics, ',', 'split'); %Sometimes many ways to say a word - take 1st option
Syl = sum(MultWord{1} == '-') + 1;
end
  7 Comments
Walter Roberson
Walter Roberson on 8 Oct 2017
You will need to build in the error checking yourself, since it is your assignment; Donald has shown you the general method and put in a warning that it does not always work.

Sign in to comment.

More Answers (1)

Nipun
Nipun on 29 Sep 2017
Is there a way to use the word counter tool website to get all different types of Syllables count?
  2 Comments
Nipun
Nipun on 29 Sep 2017
Edited: Walter Roberson on 29 Sep 2017
for example https://wordcounttools.com this website calculates Syllables, Unique Words, Monosyllabic Words, Polysyllabic Words (≥3 syllables), Syllables per word, Difficult Words etc
OCDER
OCDER on 29 Sep 2017
Edited: OCDER on 29 Sep 2017
I checked the website and it seems to use some algorithm to count syllables. Even so, it states that it's not 100% accurate. You must use a word-syllable lookup table / database, because English is just one of those things you can't program via algorithms alone.
This is from the website you provided, https://wordcounttools.com/
"How is the number of syllable calculated? The number of syllables in a word is calculated based on the vowel pattern in the word. This number can not be guaranteed 100% accurate because there are many grammar rules and nuances, but it is pretty close. Thus, this metric is appropriate when the demand for accuracy is not very strict. "
Oh, and try to reserve the answer section ONLY for answers. I know it looks like a response section, but you had it right above writing in the comment section to the answers.

Sign in to comment.

Categories

Find more on Language Support in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!