1
아래 코드는 작업을 수행하지만 많은 시간이 걸립니다. 이미 MongoDB에서 문자열로 저장 한 두 HTML 파일의 내용을 비교하고 있습니다. 문자열의 길이는 약 30K +이고 비교할 레코드는 약 250K + 개입니다. 따라서 작업은 꽤 많은 시간이 걸립니다.두 문자열을 비교하고 유사도 백분율을 찾는 방법
사용하기 쉬운 방법이나 플러그인이 있습니까? 또한 매우 빠릅니다.
private int ComputeCost(string input1, string input2)
{
if (string.IsNullOrEmpty(input1))
return string.IsNullOrEmpty(input2) ? 0 : input2.Length;
if (string.IsNullOrEmpty(input2))
return string.IsNullOrEmpty(input1) ? 0 : input1.Length;
int input1Length = input1.Length;
int input2Length = input2.Length;
int[,] distance = new int[input1Length + 1, input2Length + 1];
for (int i = 0; i <= input1Length; distance[i, 0] = i++) ;
for (int j = 0; j <= input2Length; distance[0, j] = j++) ;
for (int i = 1; i <= input1Length; i++)
{
for (int j = 1; j <= input2Length; j++)
{
int cost = (input2[j - 1] == input1[i - 1]) ? 0 : 1;
distance[i, j] = Math.Min(
Math.Min(distance[i - 1, j] + 1, distance[i, j - 1] + 1),
distance[i - 1, j - 1] + cost);
}
}
return distance[input1Length, input2Length];
}
"[Soundex] (https://en.wikipedia.org/wiki/Soundex)"는 무엇입니까? –
당신은 * Edit Distance *, https://en.wikipedia.org/wiki/Edit_distance를 계산 중입니까? –
왜 데이터베이스 자체의 문자열을 비교하지 않습니까? 대개 더 빠르기 때문에 나는 그것을 시도해 볼 것입니다. – danny