I am making a program that computes for the number of syllables in a given word/sentence. Is there a tool that can compute accurately the syllables? I have here my codes but I think I need a more accurate way of counting syllables.
import java.util.*;
public class Word
{
private String word;
private int syllableCount;
public void setWord(String word)
{
this.word = word;
}
public String getWord()
{
return word;
}
public int getSyllableCount()
{
Scanner sc = new Scanner(word);
sc.useDelimiter("[aeiouy]+");
while(sc.hasNext())
{
syllableCount++;
sc.next();
}
if (!word.endsWith("a") && !word.endsWith("e") && !word.endsWith("i") && !word.endsWith("o") &&
!word.endsWith("u") && !word.endsWith("y"))
syllableCount = syllableCount - 1;
return syllableCount;
}
public static void main (String [] args)
{
int syllables;
Word newWord = new Word();
newWord.setWord("The quick brown fox jumps over the lazy dog.");
syllables = newWord.getSyllableCount();
System.out.println(syllables + " " + "syllables");
}
}