두 개체가 얼마나 유사한 지 결정하기 위해 기본적으로 수식을 만들어야합니다. 각 속성에 대한 가중치를 선택한 다음 간단한 비교를 사용하여 해당 속성을 같은 것으로 집계해야하는지 여부를 말하십시오. 일부 유형의 퍼지 매칭이 사용될 수 있지만 더 복잡 할 것입니다. 간단한
뭔가 수 :
I는 0 ~ 100 사이의 숫자를 반환 정의하고 간단한 방법이다
public byte Similarity(SomeType other)
{
byte similarity = 0;
if (this.Property1 == other.Property1)
similarity += 25;
if (this.Property2 == other.Property2)
similarity += 13;
if (this.Property3 == other.Property3)
similarity += 12;
if (SomeFuzzyComparisonReturnsVerySimilar(this.Property4, other.Property4))
similarity += 50;
return similarity;
}
; 100은 동일하고 0은 완전히 상이하다.
일단 그렇게했다면 고려해야 할 정도로 유사한 항목을 선택하는 것이 매우 간단합니다. 예 :
var similarObjects = ListOfSomeTypes.Where(s => s.Similarity(templateObject) > 75);
또는 그들을 정렬하려면 : 궁극적으로
var sortedBySimilarity = ListOfSomeTypes.OrderByDescending(s => s.Similarity(templateObject));
를 내 포인트는 것을 일단 당신이, "공통점 가장을 가진"자신 만의 정의를 마련 할 필요가 있다는 것입니다하지만 나머지는 아마 꽤 쉬울 것입니다. 그 일이 반드시 쉬워지는 것은 아닙니다. 귀하의 질문에 자세한 내용과 함께
는 가능한 공식은 다음과 같습니다
public byte Similarity(A other)
{
byte similarity = 0;
if (this.b == null | other.b == null)
similarity += 25;
else if (this.b == other.b)
similarity += 50;
if (this.c == null | other.c == null)
similarity += 25;
else if (this.c == other.c)
similarity += 50;
return similarity;
}
이 가중치는 정확히 하나의 객체 약간 덜에서 가장 높은, null 값을 일치와 차이가 전혀.
나는이 사실에 예의를 갖추기 전에 더 많은 세부 정보를 주어야 할 것 같아. – StriplingWarrior
이 기능을 사용하는 방법에 대한 코드 예제를 제공하여 구현해야 할 것을 더 잘 보여줄 수 있습니까? – David