我有一個正則表達式/同音類型的方法:.NET實施同音對整個句子
public static string SoundEx(string word)
{
if (word.All(char.IsDigit))
{
//sentenceParts = words;
return word;
}
word = word.ToUpper();
word = word[0] +
Regex.Replace(
Regex.Replace(
Regex.Replace(
Regex.Replace(
Regex.Replace(
Regex.Replace(
Regex.Replace(word.Substring(1), "[AEIOUYHW]", ""), "[BFPV]+", "1"), "[CGJKQSXZ]+", "2"), "[DT]+", "3"), "[L]+", "4"), "[MN]+", "5"), "[R]+", "6");
return word;//word.PadRight(4, '0').Substring(0, 4);
}
這部作品用一個詞串不錯,但只要你轉儲它的句子可以開始行動滑稽。
「大棕貓。」 和 「大棕狗」。
來作爲匹配。現在我知道它保留了第一個單詞的第一個字符,然後開始使用正則表達式將數字與元音匹配等等。但是,我怎樣才能在整個句子上實現它,使其更加準確?
它應該做什麼? –
在出現輕微拼寫錯誤的情況下,對答案進行「測驗」並對其進行索引。它適用於單個詞,如: 追溯與Ritroactive 將返回匹配 但 追溯VS Metroactive 將不會返回匹配等 – VinnyGuitara
我還是不明白這一點。什麼「追溯」返回? –