예제 #1
0
        public void Test_Common()
        {
            int res1, res2;

            res1 = IndistinctMatching.LevenshteinDistance("", "");
            Assert.AreEqual(0, res1);
            res1 = IndistinctMatching.LevenshteinDistance("Ivanov", "");
            Assert.AreEqual(6, res1);
            res1 = IndistinctMatching.LevenshteinDistance("", "Petroff");
            Assert.AreEqual(7, res1);
            res1 = IndistinctMatching.LevenshteinDistance("Ivanov", "Ivanov");
            Assert.AreEqual(0, res1);
            res1 = IndistinctMatching.LevenshteinDistance("Ivanov", "IvanovTest");
            Assert.AreEqual(4, res1);
            res1 = IndistinctMatching.LevenshteinDistance("Ivanvo", "Ivanov");
            Assert.AreEqual(2, res1);
            res1 = IndistinctMatching.LevenshteinDistance("Petroff", "Pterov");
            Assert.AreEqual(4, res1); // permutation -fail

            res1 = IndistinctMatching.DamerauLevenshteinDistance("", "");
            Assert.AreEqual(0, res1);
            res1 = IndistinctMatching.DamerauLevenshteinDistance("Ivanov", "");
            Assert.AreEqual(6, res1);
            res1 = IndistinctMatching.DamerauLevenshteinDistance("", "Petroff");
            Assert.AreEqual(7, res1);
            res2 = IndistinctMatching.DamerauLevenshteinDistance("Ivanov", "Ivanov");
            Assert.AreEqual(0, res2);
            res1 = IndistinctMatching.DamerauLevenshteinDistance("Ivanov", "IvanovTest");
            Assert.AreEqual(4, res1);
            res2 = IndistinctMatching.DamerauLevenshteinDistance("Ivanvo", "Ivanov");
            Assert.AreEqual(1, res2);
            res1 = IndistinctMatching.DamerauLevenshteinDistance("Petroff", "Pterov");
            Assert.AreEqual(3, res1); // permutation -ok

            Assert.Throws(typeof(ArgumentNullException), () => { IndistinctMatching.GetSimilarity("Ivanvo", null); });
            Assert.Throws(typeof(ArgumentNullException), () => { IndistinctMatching.GetSimilarity(null, "Ivanov"); });

            Assert.GreaterOrEqual(IndistinctMatching.GetSimilarity("Ivanov", "Ivanov"), 1.0f);
            Assert.GreaterOrEqual(IndistinctMatching.GetSimilarity("Ivanvo", "Ivanov"), 0.833f);
        }
예제 #2
0
        protected virtual float GetStrMatch(string str1, string str2, MatchParams matchParams)
        {
            float match = 0.0f;

            if (matchParams.NamesIndistinctThreshold >= 0.99f)
            {
                if (string.Compare(str1, str2, true) == 0)
                {
                    match = 100.0f;
                }
            }
            else
            {
                double sim = IndistinctMatching.GetSimilarity(str1, str2);
                if (sim >= matchParams.NamesIndistinctThreshold)
                {
                    match = 100.0f;
                }
            }

            return(match);
        }
예제 #3
0
        public override float IsMatch(GEDCOMTag tag, MatchParams matchParams)
        {
            GEDCOMIndividualRecord indi = tag as GEDCOMIndividualRecord;

            if (indi == null)
            {
                return(0.0f);
            }

            if (Sex != indi.Sex)
            {
                return(0.0f);
            }

            bool womanMode = (Sex == GEDCOMSex.svFemale);

            float matchesCount = 0.0f;
            float nameMatch    = 0.0f;
            float birthMatch   = 0.0f;
            float deathMatch   = 0.0f;

            // check name

            /*for (int i = 0; i < indi.PersonalNames.Count; i++)
             *          {
             *                  for (int k = 0; k < fPersonalNames.Count; k++)
             *                  {
             *                          float currentNameMatch = fPersonalNames[k].IsMatch(indi.PersonalNames[i]);
             *                          nameMatch = Math.Max(nameMatch, currentNameMatch);
             *                  }
             *          }*/

            string iName = GetComparableName(womanMode);
            string kName = indi.GetComparableName(womanMode);

            if (!string.IsNullOrEmpty(iName) && !string.IsNullOrEmpty(kName))
            {
                if (matchParams.NamesIndistinctThreshold >= 0.99f)
                {
                    if (iName == kName)
                    {
                        nameMatch = 100.0f;
                    }
                }
                else
                {
                    double sim = IndistinctMatching.GetSimilarity(iName, kName);
                    if (sim >= matchParams.NamesIndistinctThreshold)
                    {
                        nameMatch = 100.0f;
                    }
                }
                matchesCount++;
            }

            // 0% name match would be pointless checking other details
            if (nameMatch != 0.0f && matchParams.DatesCheck)
            {
                var dates     = GetLifeDates();
                var indiDates = indi.GetLifeDates();

                if (dates.BirthEvent != null && indiDates.BirthEvent != null)
                {
                    birthMatch = dates.BirthEvent.IsMatch(indiDates.BirthEvent, matchParams);
                    matchesCount++;
                }
                else if (dates.BirthEvent == null && indiDates.BirthEvent == null)
                {
                    birthMatch = 100.0f;
                    matchesCount++;
                }
                else
                {
                    matchesCount++;
                }

                /*if (death != null && indiDeath != null) {
                 *                      deathMatch = death.IsMatch(indiDeath, matchParams);
                 *                      matches++;
                 *              } else if (death == null && indiDeath == null) {
                 *                      deathMatch = 100.0f;
                 *                      matches++;
                 *              } else {
                 *                      matches++;
                 *              }*/
            }

            float match = (nameMatch + birthMatch + deathMatch) / matchesCount;

            return(match);
        }