Need to count number of syllables in given text. Every contiguous sequence of one or more vowels, except for a lone “e” at the end of a word if the word has another vowel or set of contiguous vowels, makes up one syllable(Consider "y" as vowel)
public static void main(String[] args) {
// TODO Auto-generated method stub
int count =0;
String text = "This is a test. How many??? Senteeeeeeeeeences are here... there should be 5! Right?";
Pattern pat = Pattern.compile("[Ee]+(?!\\b)|[aiouyAIOUY]+");
Matcher m = pat.matcher(text);
while (m.find()) {
count++;
System.out.println(m.group());
}
System.out.println(count);
}
Output of above program is 15 It needs to be 16 It should to eliminate count of e's when it is last character in a word not containing any vowel i.e.., It should not eliminate count of e's in word(be) How to specify that condition in Pattern
15. You expect to have15. So what's the problem?Pattern.compile("[e]+(?!\\b)|[aiouy]+", Pattern.CASE_INSENSITIVE)