【问题标题】:compare two phonemes/strings for similarity [duplicate]比较两个音素/字符串的相似性[重复]
【发布时间】:2013-05-26 22:04:30
【问题描述】:

我有一个字符串“The White Horse is hungry

现在,我需要将其与可能的发音相匹配。以下是示例。 (把这些当作音素,好吧,我的意思是用户可以发音的方式)

The White Horse is hungary
The White Horse is not hungry
The White Horse is very hungry
The Horse is hungry
The Horse is hungries
White Horse is hungry
star wars..clone wars

现在您可以看到发音的相似程度和差异程度。我可以申请Levenshtein distance 来找出不同之处。它给了我非常准确的结果。但是,我也发现如果我能找到一种方法来比较两个音素的相似度,例如,当用户说出错误的音素时,而不是添加或删除音素,我可以获得更好的结果。

有人知道这方面的好算法吗?以及 c# 实现的示例/链接?

【问题讨论】:

  • 反对的选民愿意发表评论

标签: c# .net string math speech-recognition


【解决方案1】:

您可能想在这里尝试该算法:http://www.catalysoft.com/articles/StrikeAMatch.html

它的示例实现。

string input = "The White Horse is hungry";
string[] toTest = new string[]{
    "The White Horse is hungary",
    "The White Horse is not hungry",
    "The White Horse is very hungry",
    "The Horse is hungry",
    "The Horse is hungries",
    "White Horse is hungry",
    "star wars..clone wars",
};

string closest = toTest
                .Select(s => new
                {
                    Str = s,
                    Distance = s.Distance(input)
                })
                .OrderByDescending(x => x.Distance)
                .First().Str;

public static class StringSimilarity
{
    public static float Distance(this string s1, string s2)
    {
        var p1 = GetPairs(s1);
        var p2 = GetPairs(s2);
        return (2f * p1.Intersect(p2).Count()) / (p1.Count + p2.Count);
    }

    static List<string> GetPairs(string s)
    {
        if (s == null) return new List<string>();
        if (s.Length < 3) return new List<string>() { s };

        List<string> result = new List<string>();
        for (int i = 0; i < s.Length - 1; i++)
        {
            result.Add(s.Substring(i, 2).ToLower(CultureInfo.InvariantCulture));
        }
        return result;
    }
}

【讨论】:

  • errr,您能将 tis 显示为一个代码吗?
  • wat is Distance = s.Distance(input) ?距离课程在哪里?
  • @System.Windows.Form 它是类StringSimilarity 中定义的扩展 方法。您也可以将其用作StringSimilarity.Distance(s,input)
  • 非常感谢这个算法。另一个问题,同样的代码是否适用于国际音标字符?
  • @System.Windows.Form 也许你可以使用this trick
【解决方案2】:

如果不是 Levenshtein 距离,那么 Fuzzy 接近或 LCS 怎么样。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-04-07
    • 1970-01-01
    • 2010-10-31
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 1970-01-01
    相关资源
    最近更新 更多