Пример #1
0
 public static NameEquivalenceDb LoadFile(string filename)
 {
     try
     {
         using (StreamReader r = new StreamReader(filename))
         {
             string            json   = r.ReadToEnd();
             NameEquivalenceDb fileDb = FromJson(json);
             if (fileDb != null)
             {
                 fileDb.PrintDb();
             }
             else
             {
                 trace.TraceInformation("Name db read from " + filename + " failed");
             }
             return(fileDb);
         }
     }
     catch (System.IO.FileNotFoundException e)
     {
         trace.TraceData(TraceEventType.Warning, 0, "File read fnfe " + filename + " failed" + e.ToString());
     }
     catch (System.Exception e)
     {
         trace.TraceData(TraceEventType.Warning, 0, "File read " + filename + " failed" + e.ToString());
     }
     finally
     {
         trace.TraceData(TraceEventType.Warning, 0, "File read " + filename + " failed maybe");
     }
     return(null);
 }
        static bool IsNamesEqual(string name1, string name2, NameEquivalenceDb nameEqDb)
        {
            name1 = NormalizeName(name1);
            name2 = NormalizeName(name2);

            if (nameEqDb != null)
            {
                name1 = nameEqDb.SimplifyName(name1);
                name2 = nameEqDb.SimplifyName(name2);
            }

            return(name1 == name2);
        }
        public static void CompareTrees(IFamilyTreeStoreBaseClass familyTree1, IFamilyTreeStoreBaseClass familyTree2, ReportCompareResult reportDuplicate, IProgressReporterInterface reporter = null)
        {
            IEnumerator <IndividualClass> iterator1;
            int cnt1 = 0;

            NameEquivalenceDb equivDb = NameEquivalenceDb.LoadFile(NameEquivalenceDb.GetDefaultFilePath());

            if (equivDb == null)
            {
                equivDb = new DefaultNameEquivalenceDb();
                equivDb.LoadDefault();
                bool result = NameEquivalenceDb.SaveFile(NameEquivalenceDb.GetDefaultFilePath(), equivDb);
                if (!result)
                {
                    trace.TraceData(TraceEventType.Warning, 0, "File db write failed");
                }
                else
                {
                    trace.TraceData(TraceEventType.Information, 0, "File db write ok");
                }
            }

            iterator1 = familyTree1.SearchPerson(null, reporter);

            trace.TraceData(TraceEventType.Information, 0, "CompareTrees() started");

            if (iterator1 != null)
            {
                do
                {
                    IndividualClass person1 = iterator1.Current;

                    cnt1++;
                    if (person1 != null)
                    {
                        trace.TraceData(TraceEventType.Information, 0, " 1:" + cnt1 + " " + person1.GetName());
                        SearchDuplicates(person1, familyTree1, familyTree2, reportDuplicate, reporter, equivDb);
                    }
                    else
                    {
                        trace.TraceData(TraceEventType.Warning, 0, " 1: person is null" + cnt1);
                    }
                } while (iterator1.MoveNext());
                iterator1.Dispose();
            }
            else
            {
                trace.TraceInformation("iter=null");
            }
            trace.TraceInformation("CompareTrees() done");
        }
Пример #4
0
 public static bool SaveFile(string filename, NameEquivalenceDb db)
 {
     try
     {
         using (StreamWriter wr = new StreamWriter(filename))
         {
             string dbJson = NameEquivalenceDb.ToJson(db);
             wr.Write(dbJson);
             wr.Close();
             trace.TraceData(TraceEventType.Information, 0, "File write " + filename + " done");
         }
         return(true);
     }
     catch (DirectoryNotFoundException e)
     {
         trace.TraceData(TraceEventType.Warning, 0, "File write dnfe " + filename + " failed" + e.ToString());
     }
     catch (System.Exception e)
     {
         trace.TraceData(TraceEventType.Warning, 0, "File write " + filename + " failed" + e.ToString());
     }
     return(false);
 }
        public static void SearchDuplicates(IndividualClass person1, IFamilyTreeStoreBaseClass familyTree1, IFamilyTreeStoreBaseClass familyTree2, ReportCompareResult reportDuplicate, IProgressReporterInterface reporter = null, NameEquivalenceDb nameEqDb = null)
        {
            IndividualEventClass birth = person1.GetEvent(IndividualEventClass.EventType.Birth);
            IndividualEventClass death = person1.GetEvent(IndividualEventClass.EventType.Death);

            if (reporter != null)
            {
                trace.TraceInformation(reporter.ToString());
            }
            if (((birth != null) && (birth.GetDate() != null) && (birth.GetDate().ValidDate())) ||
                ((death != null) && (death.GetDate() != null) && (death.GetDate().ValidDate())))
            {
                string searchString;

                if (familyTree2.GetCapabilities().jsonSearch)
                {
                    searchString = SearchDescriptor.ToJson(SearchDescriptor.GetSearchDescriptor(person1));
                }
                else
                {
                    searchString = person1.GetName().Replace("*", "");
                }

                IEnumerator <IndividualClass> iterator2 = familyTree2.SearchPerson(searchString);
                int cnt2 = 0;

                if (iterator2 != null)
                {
                    int cnt3 = 0;
                    do
                    {
                        IndividualClass person2 = iterator2.Current;

                        if (person2 != null)
                        {
                            cnt3++;
                            //trace.TraceInformation(reporter.ToString() + "   2:" + person2.GetName());
                            if ((familyTree1 != familyTree2) || (person1.GetXrefName() != person2.GetXrefName()))
                            {
                                if (ComparePerson(person1, person2, nameEqDb))
                                {
                                    trace.TraceData(TraceEventType.Information, 0, "   2:" + person2.GetName() + " " + person1.GetXrefName() + " " + person2.GetXrefName());
                                    reportDuplicate(familyTree1, person1.GetXrefName(), familyTree2, person2.GetXrefName());
                                }
                                cnt2++;
                            }
                        }
                    } while (iterator2.MoveNext());

                    iterator2.Dispose();
                    trace.TraceInformation(" " + searchString + " matched with " + cnt2 + "," + cnt3);
                }

                if (cnt2 == 0) // No matches found for full name
                {
                    if ((person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname).Length > 0) &&
                        (person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname).Length > 0) &&
                        !person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname).Equals(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname)))
                    {
                        String strippedName = person1.GetName().Replace("*", "");

                        if (strippedName.Contains(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname)))
                        {
                            String maidenName = strippedName.Replace(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.Surname), "").Replace("  ", " ");
                            IEnumerator <IndividualClass> iterator3 = familyTree2.SearchPerson(maidenName);
                            //trace.TraceInformation(" Searching Maiden name " + maidenName);

                            if (iterator3 != null)
                            {
                                int cnt3 = 0;
                                do
                                {
                                    IndividualClass person2 = iterator3.Current;

                                    if (person2 != null)
                                    {
                                        if ((familyTree1 != familyTree2) || (person1.GetXrefName() != person2.GetXrefName()))
                                        {
                                            cnt3++;
                                            if (ComparePerson(person1, person2, nameEqDb))
                                            {
                                                trace.TraceData(TraceEventType.Information, 0, "   2b:" + person2.GetName());
                                                reportDuplicate(familyTree1, person1.GetXrefName(), familyTree2, person2.GetXrefName());
                                            }
                                        }
                                    }
                                } while (iterator3.MoveNext());
                                iterator3.Dispose();
                                trace.TraceInformation(" Maiden name " + maidenName + " mathched with " + cnt3);
                            }
                        }
                        if (strippedName.Contains(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname)))
                        {
                            String marriedName = strippedName.Replace(person1.GetPersonalName().GetName(PersonalNameClass.PartialNameType.BirthSurname), "").Replace("  ", " ");
                            IEnumerator <IndividualClass> iterator3 = familyTree2.SearchPerson(marriedName);

                            //trace.TraceInformation(" Searching Married name " + marriedName);
                            if (iterator3 != null)
                            {
                                int cnt3 = 0;
                                do
                                {
                                    //IndividualClass person1 = iterator1.Current;
                                    IndividualClass person2 = iterator3.Current;

                                    if (person2 != null)
                                    {
                                        //trace.TraceInformation(reporter.ToString() + "   2:" + person2.GetName());
                                        if ((familyTree1 != familyTree2) || (person1.GetXrefName() != person2.GetXrefName()))
                                        {
                                            cnt3++;
                                            if (ComparePerson(person1, person2, nameEqDb))
                                            {
                                                trace.TraceData(TraceEventType.Information, 0, "   2c:" + person2.GetName());
                                                reportDuplicate(familyTree1, person1.GetXrefName(), familyTree2, person2.GetXrefName());
                                            }
                                        }
                                    }
                                } while (iterator3.MoveNext());
                                iterator3.Dispose();
                                trace.TraceInformation(" Married name " + marriedName + " matched to " + cnt3);
                            }
                        }
                    }
                }
            }
            else
            {
                trace.TraceData(TraceEventType.Information, 0, "No valid birth or death date for " + person1.GetName().ToString() + " skip duplicate search");
            }
        }
        public static bool ComparePerson(IndividualClass person1, IndividualClass person2, NameEquivalenceDb nameEqDb)
        {
            if (IsNamesEqual(person1.GetName(), person2.GetName(), nameEqDb))
            {
                IndividualEventClass birth1 = person1.GetEvent(IndividualEventClass.EventType.Birth);
                IndividualEventClass birth2 = person2.GetEvent(IndividualEventClass.EventType.Birth);
                IndividualEventClass death1 = person1.GetEvent(IndividualEventClass.EventType.Death);
                IndividualEventClass death2 = person2.GetEvent(IndividualEventClass.EventType.Death);

                DateMatch birthMatch = DateMatch.Unknown, deathMatch = DateMatch.Unknown;

                if ((birth1 != null) && (birth2 != null))
                {
                    birthMatch = MatchDates(birth1.GetDate(), birth2.GetDate());
                }
                if ((death1 != null) && (death2 != null))
                {
                    deathMatch = MatchDates(death1.GetDate(), death2.GetDate());
                }
                if ((birthMatch == DateMatch.Unknown) && (deathMatch == DateMatch.Unknown))
                {
                    return(false);
                }
                if ((birthMatch == DateMatch.Bad) || (deathMatch == DateMatch.Bad))
                {
                    return(false);
                }
                return((birthMatch == DateMatch.Good) || (deathMatch == DateMatch.Good));
            }
            return(false);
        }
Пример #7
0
 public static string ToJson(NameEquivalenceDb o)
 {
     return(JsonSerializer.Serialize(o));
 }