public void TrustMap_Basics() { // Create a TrustMap for both of the Runs being compared TrustMap beforeMap = new TrustMap(); TrustMap afterMap = new TrustMap(); // All properties are unknown to start beforeMap.Trust(Set, NameGreat).Should().Be(TrustMap.DefaultTrust); for (int i = 0; i < 20; ++i) { // Add a fingerprint which is always unique and all of which match beforeMap.Add(new WhatComponent(Rule, Location1, Set, NameGreat, i.ToString())); afterMap.Add(new WhatComponent(Rule, Location2, Set, NameGreat, i.ToString())); // Add a fingerprint which is somewhat unique and always matches beforeMap.Add(new WhatComponent(Rule, Location1, Set, NameMedium, (i % 3).ToString())); afterMap.Add(new WhatComponent(Rule, Location2, Set, NameMedium, (i % 3).ToString())); // Add a fingerprint which is always unique but has no matches beforeMap.Add(new WhatComponent(Rule, Location1, Set, NameNoMatches, i.ToString())); afterMap.Add(new WhatComponent(Rule, Location2, Set, NameNoMatches, (100 + i).ToString())); // Add a fingerprint with constant value beforeMap.Add(new WhatComponent(Rule, Location1, Set, NameConstant, "Constant")); afterMap.Add(new WhatComponent(Rule, Location2, Set, NameConstant, "Constant")); } // Before comparing the runs, trust is based on uniqueness only beforeMap.Trust(Set, NameGreat).Should().Be(1.0f); beforeMap.Trust(Set, NameMedium).Should().Be(3.0f / 20.0f); beforeMap.Trust(Set, NameNoMatches).Should().Be(1.0f); beforeMap.Trust(Set, NameConstant).Should().Be(0.0f); // Match the two runs to allow trust scoring based on matches beforeMap.WasMatched.Should().BeFalse(); afterMap.WasMatched.Should().BeFalse(); afterMap.CountMatchesWith(beforeMap); beforeMap.WasMatched.Should().BeTrue(); afterMap.WasMatched.Should().BeTrue(); // After comparing runs, trust is based on uniqueness and number of matches // Note: Attributes with only one value (constants) have zero trust. // Note: Attributes which are unique but never match have low (default) trust. beforeMap.Trust(Set, NameGreat).Should().Be(1.0f); beforeMap.Trust(Set, NameMedium).Should().Be(3.0f / 20.0f); beforeMap.Trust(Set, NameNoMatches).Should().Be(TrustMap.DefaultTrust); beforeMap.Trust(Set, NameConstant).Should().Be(0.0f); // Same scores from both maps afterMap.Trust(Set, NameGreat).Should().Be(beforeMap.Trust(Set, NameGreat)); afterMap.Trust(Set, NameMedium).Should().Be(beforeMap.Trust(Set, NameMedium)); afterMap.Trust(Set, NameNoMatches).Should().Be(beforeMap.Trust(Set, NameNoMatches)); afterMap.Trust(Set, NameConstant).Should().Be(beforeMap.Trust(Set, NameConstant)); // Unknown properties are still unknown afterMap.Trust("Set2", NameConstant).Should().Be(TrustMap.DefaultTrust); }
/// <summary> /// Match enough of the 'What' properties of two ExtractedResults (Guid, Fingerprints, PartialFingerprints, Snippets, Message, Properties). /// A match in high-confidence identity properties is a match (Guid, Fingerprint, >= 50% of PartialFingerprint). /// A non-match in high-confidence identity properties is a non-match (Fingerprint, 0% of PartialFingerprints, Properties). /// Otherwise, Results match if Message and first Snippet match. /// </summary> /// <param name="other">ExtractedResult to match</param> /// <param name="trustMap">TrustMap for either Run being compared, to weight attributes selectively</param> /// <returns>True if *any* 'What' property matches, False otherwise</returns> internal bool MatchesAnyWhat(ExtractedResult other, TrustMap trustMap) { return(WhatComparer.MatchesWhat(this, other, trustMap)); }
/// <summary> /// Determine whether this ExtractedResult is 'sufficiently similar' to another. /// An ExtractedResult must have the same category and either match a 'What' property or all 'Where' properties. /// </summary> /// <param name="other">ExtractedResult to match</param> /// <param name="trustMap">TrustMap for either Run being compared, to weight attributes selectively</param> /// <returns>True if ExtractedResults are 'sufficiently similar', otherwise False.</returns> internal bool IsSufficientlySimilarTo(ExtractedResult other, TrustMap trustMap) { return(this.MatchesCategory(other) && (this.MatchesAnyWhat(other, trustMap) || this.MatchesAllWhere(other))); }