public void Similarity() { string text1 = "asldbcv3o9322lif;owq4o-u-4hf3fn4ofwh094f4qq43fqldadsa2GSUACUVAoo32g3f"; string text2 = "xsbadkvivuvsd;ojve;rieorqro8@O*ho848oq34floowahoOAGAGAODOWWOoq38aqo3af"; LettersDiffer differ = new LettersDiffer(); differ.AddTask(text1, 0); differ.AddTask(text2, 0); double diffSimilarity = differ.DoDiff(); double aseSimilarity = ASESimilarityAlgorithm.CalculateSimilarity(text1, text2); Assert.AreEqual(aseSimilarity, diffSimilarity, 0.05, "Incorrect similarity factor"); }
/// <summary> /// Checks is the value is equal. If not where applicable a collection of granular differences is outputed /// </summary> /// <param name="diffObject"></param> /// <param name="diffsForSelf"></param> /// <param name="diffsForArgument"></param> /// <param name="commonElements"></param> /// <returns></returns> public bool ValueMatches(IDiffObject diffObject, out IDiffObjectsCollection diffsForSelf, out IDiffObjectsCollection diffsForArgument, out IDiffObjectsCollection commonElements) { BaseTextDiffObject otherObject = diffObject as BaseTextDiffObject; diffsForSelf = null; diffsForArgument = null; commonElements = null; bool matches = false; if (otherObject != null) { matches = this.ValueHash == otherObject.ValueHash; if (!matches) { double simFactor = ASESimilarityAlgorithm.CalculateSimilarity(this.Value, otherObject.Value); LettersDiffer granularDiffer = InitGranularDiffer(); if (simFactor > 0 && granularDiffer != null) { //calculate granular differences granularDiffer.AddTask(Value, Position); //imports the current word into a letters collection starting from the position of the current element granularDiffer.AddTask(otherObject.Value, otherObject.Position); double diffRatio = granularDiffer.DoDiff(0, 1); diffsForSelf = granularDiffer.GetResultingDifferences(0); diffsForArgument = granularDiffer.GetResultingDifferences(1); commonElements = granularDiffer.GetResultingCommonElements(0); matches = diffRatio >= this.SimilarityFactor; } } } return(matches); }