我需要找出1.不匹配(不正确播放的音符)、2.插入(附加播放的音符)和3.删除(遗漏的音符),在音乐片段(例如,存储在表中的音符音调字符串值)中相对于参考音乐片段。
这可以通过精确字符串匹配算法或动态编程/近似字符串匹配算法来实现。然而,我意识到,由于识别不匹配、插入或删除注释,近似字符串匹配更适合我的问题。或Boyer-moore的扩展版本,以支持约字符串匹配。
有没有我可以尝试近似字符串匹配的示例java代码的链接?我发现了复杂的解释和方程式--但我希望我能用一些示例代码和简单的解释做得很好。或者我能在boyer-moore extended上找到任何示例java代码吗?字符串匹配?我理解boyer-moore的概念,但在调整它以支持近似时遇到了麻烦。字符串匹配(即支持不匹配、插入、删除)。
还有什么是最有效的近似。字符串匹配算法(就像精确字符串匹配算法中的boyer-moore )?
非常感谢您的见解/建议。非常感谢你提前
发布于 2010-06-14 08:30:23
你可以从approximate string matching上的维基百科页面开始。
问题是,这是一个复杂的领域,简单地查看/复制一些示例代码可能不会帮助您理解所发生的事情。
编辑-此外,我看不出Boyer-Moore如何适应近似字符串匹配。
发布于 2014-01-25 15:30:46
这是BMH Boyer-More代码,可以将其推送到C#或近似匹配。
Dictionary<char, int> ShiftSizeTable = new Dictionary<char, int>();
//Calculate Shifit/Skip count for each element in pattern text. So that we can skip that many no of Characters in given text while searching.
public void PreProcessBMSBadMatchTable(char[] patternCharacters)
{
ShiftSizeTable.Clear();
int totalCharacters = patternCharacters.Length;
for (int lpIndex = 0; lpIndex < totalCharacters; lpIndex++)
{
//Calculate the shift size for each character in the string or char array.
int ShiftSize = Math.Max(1, (totalCharacters - 1) - lpIndex);
//If the charater is already exists in the ShiftSize table then replace it else add it to ShiftSize table.
if (ShiftSizeTable.ContainsKey(patternCharacters[lpIndex]))
{
ShiftSizeTable.Remove(patternCharacters[lpIndex]);
}
ShiftSizeTable.Add(patternCharacters[lpIndex], ShiftSize);
}
}
//Use the PreProcessed Shift/Skip table to find the pattern Characters in text and skip the bad Characters in the text.
public int BoyerMooreSearch1UsingDictionary(char[] textCharacters, char[] patternCharacters)
{
PreProcessBMSBadMatchTable(patternCharacters);
int SkipLength;
int patternCharactersLenght = patternCharacters.Length;
int textCharactersLenght = textCharacters.Length;
// Step2. Use Loop through each character in source text use ShiftArrayTable to skip the elements.
for (int lpTextIndex = 0; lpTextIndex <= (textCharactersLenght - patternCharactersLenght); lpTextIndex += SkipLength)
{
SkipLength = 0;
for (int lpPatIndex = patternCharactersLenght - 1; lpPatIndex >= 0; lpPatIndex--)
{
if (patternCharacters[lpPatIndex] != textCharacters[lpTextIndex + lpPatIndex])
{
SkipLength = Math.Max(1, lpPatIndex - ShiftSizeTable[patternCharacters[lpPatIndex]]);
break;
}
}
if (SkipLength == 0)
{
return lpTextIndex; // Found
}
}
return -1; // Not found
} https://stackoverflow.com/questions/3034351
复制相似问题