是否有一个用于在Java中计算音节的工具?

时间:2013-05-28 16:20:49

标签: java

我正在制作一个计算给定单词/句子中音节数量的程序。有没有可以准确计算音节的工具?我在这里有我的代码,但我认为我需要一种更准确的方法来计算音节。

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");
    }
}

0 个答案:

没有答案