public Dictionary <int, int?> BackwardMatchChangeLinesAcrossDiff(Difference difference) { Dictionary <int, int?> Matches = new Dictionary <int, int?>(); SimilarityTool bigram = new SimilarityTool(); var skipIndexList = new List <int>(); for (int i = difference.Right.Start; i < difference.Right.Start + difference.Right.Length; i++) { // Need to rely on left to right mapping, otherwise need global search on all scores and lines. var entry = LeftToRightLineMap.Where(e => e.Value.HasValue && e.Value.Value == i).SingleOrDefault(); Matches[i] = null; // http://stackoverflow.com/questions/1641392/the-default-for-keyvaluepair if (!entry.Equals(default(KeyValuePair <int, int?>))) { Matches[i] = entry.Key; } } var matchCount = new HashSet <int?>(Matches.Values).Where(m => m != null).Count(); matchCount += Matches.Values.Where(m => m == null).Count(); if (matchCount != difference.Right.Length) { throw new Exception("Collision in Bitap algorithm: update to exclude, previously matched lines"); } return(Matches); }
public Dictionary <int, int?> ForwardMatchChangeLinesAcrossDiff(Difference difference) { Dictionary <int, int?> Matches = new Dictionary <int, int?>(); SimilarityTool bigram = new SimilarityTool(); var skipIndexList = new List <int>(); for (int i = difference.Left.Start; i < difference.Left.Start + difference.Left.Length; i++) { //DiffMatchPatch.diff_match_patch m = new DiffMatchPatch.diff_match_patch(); //var right = CollectRightDiffSide(difference); //var pos = m.match_main(right, this.LeftTextLines[i], 0); //int line = difference.Left.Start + GetLinePositionFromCharacter(pos, right); var scores = new List <double>(); for (int index = difference.Right.Start; index < difference.Right.Start + difference.Right.Length; index++) { if (skipIndexList.Contains(index)) { scores.Add(-1); } else { scores.Add(bigram.CompareStrings(this.LeftTextLines[i], this.RightTextLines[index])); } } if (scores.Count > 0 && scores.All(s => s > -1)) { Matches[i] = difference.Right.Start + scores.MaxIndex(); skipIndexList.Add(Matches[i].Value); } else { Matches[i] = null; } } var matchCount = new HashSet <int?>(Matches.Values).Where(m => m != null).Count(); matchCount += Matches.Values.Where(m => m == null).Count(); if (matchCount != difference.Left.Length) { throw new Exception("Collision in Bitap algorithm: update to exclude, previously matched lines"); } return(Matches); }