0

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");
    }
}
Kevin Brown-Silva
  • 40,873
  • 40
  • 203
  • 237
  • 1
    I agree - I think you need a much more accurate way of counting syllables. This isn't it. Here are the other rules you'll need: http://english.glendale.cc.ca.us/phonics.rules.html – duffymo May 28 '13 at 16:22
  • Not sure if there exists one. At least, I know that in Spanish letter `y` is not considered as a vowel. Also, you're just counting the ASCII syllables. – Luiggi Mendoza May 28 '13 at 16:23
  • 1
    possible duplicate of [Detecting syllables in a word](http://stackoverflow.com/questions/405161/detecting-syllables-in-a-word) or http://stackoverflow.com/questions/9154027/java-writing-a-syllable-counter-based-on-specifications?rq=1 or ... a bunch of others – Brian Roach May 28 '13 at 16:24
  • Did you try exploring the translation/transliteration APIs ? There could be some apis which will help you find syllables in English AND other languages. Otherwise if you follow http://www.howmanysyllables.com/howtocountsyllables.html it seems pretty straight forward. – happybuddha May 28 '13 at 16:28
  • 1
    Unfortunately, English is messier than most other languages. I'm not sure if there is a set of rules that fully define syllabification for it. Fortunately, you can take on English major interns for free, and just have them count out the syllables. It's a bit slower, but it's free. Also they can fetch your coffee. – Reinstate Monica -- notmaynard May 28 '13 at 16:29
  • It sort of depends on what you need the count for. You could try your algorithm on a paragraph or two for which you know the count. Use text similar to what you expect in real life. Then assume if its 90% accurate on that text, same applies to real life text and report your results as a range. Your code will count two for `pike` and 3 for `baseball`. Maybe it will average out. – Lee Meador May 28 '13 at 16:34
  • @duffymo Those rules are pretty worthless on a computer. They assume you can tell when two vowels are a diphthong and when the 'e' at the end of a word is silent. How does a computer tell `Nike` and `like` have 2 and 1 syllable respectively? How does it know `reanimate` and `real` treat the `rea` on the front as 2 or 1 syllable? – Lee Meador May 28 '13 at 16:43

0 Answers0