我正在尝试为一个程序计算该问题,该程序将计算文本块的flesch-kincaid和flesch阅读分数。我的算法使用的是我在以下网站上找到的内容: http : //www.howmanysyllables.com/howtocountsyllables.html ,它的访问范围相当接近。它仍然难以处理诸如隐形和断字之类的复杂单词,但是我发现它出于我的目的而进入了球场。
它具有易于实现的优点。我发现“ es”可以是音节,也可以不是。这是一场赌博,但我决定在算法中删除es。
private int CountSyllables(string word)
{
char[] vowels = { 'a', 'e', 'i', 'o', 'u', 'y' };
string currentWord = word;
int numVowels = 0;
bool lastWasVowel = false;
foreach (char wc in currentWord)
{
bool foundVowel = false;
foreach (char v in vowels)
{
//don't count diphthongs
if (v == wc && lastWasVowel)
{
foundVowel = true;
lastWasVowel = true;
break;
}
else if (v == wc && !lastWasVowel)
{
numVowels++;
foundVowel = true;
lastWasVowel = true;
break;
}
}
//if full cycle and no vowel found, set lastWasVowel to false;
if (!foundVowel)
lastWasVowel = false;
}
//remove es, it's _usually? silent
if (currentWord.Length > 2 &&
currentWord.Substring(currentWord.Length - 2) == "es")
numVowels--;
// remove silent e
else if (currentWord.Length > 1 &&
currentWord.Substring(currentWord.Length - 1) == "e")
numVowels--;
return numVowels;
}
0
我需要找到一种相当有效的方法来检测单词中的音节。例如,
看不见-> in-vi-sib-le
有一些音节化规则可以使用:
V CV VC CVC CCV CCCV CVCC
*其中V是元音,C是辅音。例如,
发音(5个专业名词; CV-CVC-CV-V-CVC)
我尝试了几种方法,其中包括使用正则表达式(仅当您要计算音节时才有用)或硬编码规则定义(被证明是效率很低的蛮力方法),最后使用有限状态自动机(没有任何有用的结果)。
我的应用程序的目的是创建给定语言的所有音节的字典。该词典稍后将用于拼写检查应用程序(使用贝叶斯分类器)和文本到语音合成。
如果能在我以前的方法之外给我提示另一种解决此问题的方法,我将不胜感激。
我使用Java,但是使用C / C ++,C#,Python,Perl的任何技巧都可以为我工作。