Example #1
0
 /// <summary>
 /// Unload fuzzy match results prior to comparison.
 /// </summary>
 public void FuzzyUnloadDir(MatchingPairs matchingPairs, ref List <DirectoryEntry> entries)
 {
     foreach (DirectoryEntry entry in entries)
     {
         if (matchingPairs.ContainsKey(entry.StdFile))
         {
             MatchingPair matchingPair = matchingPairs[entry.StdFile];
             if (matchingPair.Matched)
             {
                 entry.FuzzFile = matchingPair.NewKey;
             }
         }
     }
 }
Example #2
0
        /// <summary>
        /// Find the best fuzzy match for the specified old key.
        /// </summary>
        /// <remarks>
        /// The old key is the key on the left hand side.
        /// </remarks>
        /// <param name="oldKey">Old key to fuzzy match.</param>
        /// <returns>Score for the best fuzzy match for the specified old key.</returns>
        public void BestMatch(string oldKey)
        {
            double       bestScore = 0;
            string       bestMatch = string.Empty;
            double       thisScore = 0;
            MatchingPair oldMatch;
            MatchingPair newMatch;
            string       newKey  = string.Empty;
            int          newRow  = 0;
            bool         matched = false;
            Match        match   = new Match();

            for (newRow = 0; newRow < NewRows.Count; newRow++)
            {
                newKey = NewRows[newRow];
                if (newKey.Trim() != string.Empty)
                {
                    thisScore = match.MatchFields(oldKey, newKey);
                    if (thisScore > bestScore)
                    {
                        bestScore = thisScore;
                        bestMatch = newKey;
                    }
                    if (thisScore == 100)
                    {
                        break;
                    }
                }
            }
            if (bestScore >= FuzzyFinalThresholdScore)
            {
                matched = true;
            }
            else
            {
                matched = false;
            }
            oldMatch         = new MatchingPair();
            oldMatch.OldKey  = oldKey;
            oldMatch.NewKey  = bestMatch;
            oldMatch.Score   = bestScore;
            oldMatch.Matched = matched;
            try
            {
                if (NewMatches.ContainsKey(bestMatch))
                {
                    newMatch = NewMatches[bestMatch];
                    if (!(newMatch == null))
                    {
                        if (oldMatch.Score > newMatch.Score)
                        {
                            OldMatches.Add(oldKey, oldMatch);
                            NewMatches.Remove(bestMatch);
                            NewMatches.Add(bestMatch, oldMatch);
                        }
                    }
                    else
                    {
                        OldMatches.Add(oldKey, oldMatch);
                        NewMatches.Add(bestMatch, oldMatch);
                    }
                }
                else
                {
                    OldMatches.Add(oldKey, oldMatch);
                    NewMatches.Add(bestMatch, oldMatch);
                }
            }
            catch (Exception ex)
            {
                OldMatches.Add(oldKey, oldMatch);
                NewMatches.Add(bestMatch, oldMatch);
            }
        }