Пример #1
0
        public bool AddSpouse(GEDCOMIndividualRecord spouse)
        {
            if (spouse == null)
            {
                return(false);
            }

            GEDCOMSex sex = spouse.Sex;

            if (sex == GEDCOMSex.svNone || sex == GEDCOMSex.svUndetermined)
            {
                return(false);
            }

            switch (sex)
            {
            case GEDCOMSex.svMale:
                Husband.Value = spouse;
                break;

            case GEDCOMSex.svFemale:
                Wife.Value = spouse;
                break;
            }

            GEDCOMSpouseToFamilyLink spLink = new GEDCOMSpouseToFamilyLink(Owner, spouse, "", "");

            spLink.Family = this;
            spouse.SpouseToFamilyLinks.Add(spLink);

            return(true);
        }
Пример #2
0
        public void testAhnenblattDate()
        {
            string gedcom = "0 HEAD\n1 SOUR AHN\n0 @I1@ INDI\n1 BIRT\n2 DATE (20/12-1980)";

            // TODO this bit needs to go into utility class
            GEDCOMTree     tee = new GEDCOMTree();
            GEDCOMProvider gp  = new GEDCOMProvider(tee);

            try {
                gp.LoadFromString(gedcom);
            } catch (Exception) {
            }
            Assert.AreEqual(1, tee.RecordsCount);
            GEDCOMRecord rec = tee[0];

            Assert.IsTrue(rec is GEDCOMIndividualRecord);
            GEDCOMIndividualRecord rec2 = (GEDCOMIndividualRecord)rec;
            // end for utility class

            GEDCOMList <GEDCOMCustomEvent> events = rec2.Events;

            Assert.AreEqual(1, events.Count);
            GEDCOMCustomEvent birt = events.Extract(0);
            GEDCOMDateValue   dv   = birt.Date;

            Assert.AreEqual("20 DEC 1980", dv.StringValue);
        }
Пример #3
0
        public void Test_Names_02()
        {
            using (BaseContext ctx = new BaseContext(null)) {
                Assembly assembly = typeof(CoreTests).Assembly;
                using (Stream stmGed1 = assembly.GetManifestResourceStream("GKTests.Resources.test_names_02.ged")) {
                    var gedcomProvider = new GEDCOMProvider(ctx.Tree);
                    gedcomProvider.LoadFromStreamExt(stmGed1, stmGed1);

                    GEDCOMIndividualRecord iRec1 = ctx.Tree.XRefIndex_Find("I1") as GEDCOMIndividualRecord;
                    Assert.IsNotNull(iRec1);
                    Assert.AreEqual("Анна Сидоровна Иванова (Петрова)", iRec1.GetPrimaryFullName());
                    // std-surn exists and double, and sub-surn same
                    // sub-givn and sub-patn exists
                    var parts = GKUtils.GetNameParts(iRec1);
                    Assert.AreEqual("Иванова (Петрова)", parts.Surname);
                    Assert.AreEqual("Анна", parts.Name);
                    Assert.AreEqual("Сидоровна", parts.Patronymic);

                    GEDCOMIndividualRecord iRec2 = ctx.Tree.XRefIndex_Find("I2") as GEDCOMIndividualRecord;
                    Assert.IsNotNull(iRec2);
                    Assert.AreEqual("Аглая Федоровна Иванова", iRec2.GetPrimaryFullName());
                    // std-surn exists (maiden), and sub-surn same, and sub-marn exists (married)
                    // sub-givn and sub-patn exists
                    parts = GKUtils.GetNameParts(iRec2);
                    Assert.AreEqual("Иванова", parts.Surname);
                    Assert.AreEqual("Лескова", parts.MarriedSurname);
                    Assert.AreEqual("Аглая", parts.Name);
                    Assert.AreEqual("Федоровна", parts.Patronymic);
                }
            }
        }
Пример #4
0
        public void Test_Names_01()
        {
            using (BaseContext ctx = new BaseContext(null)) {
                Assembly assembly = typeof(CoreTests).Assembly;
                using (Stream stmGed1 = assembly.GetManifestResourceStream("GKTests.Resources.test_names_01.ged")) {
                    var gedcomProvider = new GEDCOMProvider(ctx.Tree);
                    gedcomProvider.LoadFromStreamExt(stmGed1, stmGed1);

                    GEDCOMIndividualRecord iRec1 = ctx.Tree.XRefIndex_Find("I1") as GEDCOMIndividualRecord;
                    Assert.IsNotNull(iRec1);
                    Assert.AreEqual("Александра Анатольевна Лазорева (Иванова)", iRec1.GetPrimaryFullName());
                    // std-surn exists and double, but sub-surn has only second part
                    // sub-givn exists, but sub-patn is not
                    var parts = GKUtils.GetNameParts(iRec1);
                    Assert.AreEqual("Иванова", parts.Surname);
                    Assert.AreEqual("Александра", parts.Name);
                    Assert.AreEqual("Анатольевна", parts.Patronymic);

                    GEDCOMIndividualRecord iRec2 = ctx.Tree.XRefIndex_Find("I2") as GEDCOMIndividualRecord;
                    Assert.IsNotNull(iRec2);
                    Assert.AreEqual("Петр Константинович Лазорев", iRec2.GetPrimaryFullName());
                    // std-surn exists, but sub-surn is not
                    // sub-givn exists, but sub-patn is not
                    parts = GKUtils.GetNameParts(iRec2);
                    Assert.AreEqual("Лазорев", parts.Surname);
                    Assert.AreEqual("Петр", parts.Name);
                    Assert.AreEqual("Константинович", parts.Patronymic);
                }
            }
        }
Пример #5
0
        public GEDCOMIndividualRecord GetSpouseBy(GEDCOMIndividualRecord spouse)
        {
            GEDCOMIndividualRecord husb = GetHusband();
            GEDCOMIndividualRecord wife = GetWife();

            return((spouse == husb) ? wife : husb);
        }
Пример #6
0
        private const int REP_COUNT = 1000; // 1000000; // for profile tests

        private static void GEDCOMListTest11(GEDCOMIndividualRecord iRec)
        {
            int hash;

            foreach (GEDCOMCustomEvent evt1 in iRec.Events)
            {
                hash = evt1.GetHashCode();
            }
        }
Пример #7
0
        public GEDCOMAssociation AddAssociation(string relation, GEDCOMIndividualRecord relPerson)
        {
            GEDCOMAssociation result = new GEDCOMAssociation(Owner, this, "", "");

            result.Relation   = relation;
            result.Individual = relPerson;
            Associations.Add(result);
            return(result);
        }
Пример #8
0
        private static void GEDCOMListTest21(GEDCOMIndividualRecord iRec)
        {
            int hash;

            for (int i = 0; i < iRec.Events.Count; i++)
            {
                GEDCOMCustomEvent evt1 = iRec.Events[i];
                hash = evt1.GetHashCode();
            }
        }
Пример #9
0
        public GEDCOMIndividualRecord CreateIndividual()
        {
            GEDCOMIndividualRecord result = new GEDCOMIndividualRecord(this, this, "", "");

            result.InitNew();
            result.ChangeDate.ChangeDateTime = DateTime.Now;

            AddRecord(result);
            return(result);
        }
Пример #10
0
        private static void GEDCOMListTest23(GEDCOMIndividualRecord iRec)
        {
            int hash;
            GEDCOMList <GEDCOMCustomEvent> events = iRec.Events;

            for (int i = 0, num = events.Count; i < num; i++)
            {
                GEDCOMCustomEvent evt1 = events[i];
                hash = evt1.GetHashCode();
            }
        }
Пример #11
0
        private static void GEDCOMListTest12(GEDCOMIndividualRecord iRec)
        {
            int hash;
            IGEDCOMListEnumerator <GEDCOMCustomEvent> enumer = iRec.Events.GetEnumerator();

            while (enumer.MoveNext())
            {
                GEDCOMCustomEvent evt1 = enumer.Current;
                hash = evt1.GetHashCode();
            }
        }
Пример #12
0
        //

        public bool DeleteIndividualRecord(GEDCOMIndividualRecord iRec)
        {
            if (iRec == null)
            {
                return(false);
            }

            iRec.Clear();
            DeleteRecord(iRec);
            return(true);
        }
Пример #13
0
        public bool RemoveChild(GEDCOMIndividualRecord child)
        {
            if (child == null)
            {
                return(false);
            }

            DeleteChild(child);
            child.DeleteChildToFamilyLink(this);

            return(true);
        }
Пример #14
0
        public bool RemoveMember(GEDCOMIndividualRecord member)
        {
            if (member == null)
            {
                return(false);
            }

            fMembers.DeleteAt(IndexOfMember(member));
            member.Groups.DeleteAt(member.IndexOfGroup(this));

            return(true);
        }
Пример #15
0
        private string GetFamilyString()
        {
            string result = "";

            GEDCOMIndividualRecord spouse = GetHusband();

            result += (spouse == null) ? "?" : spouse.GetPrimaryFullName();
            result += " - ";
            spouse  = GetWife();
            result += (spouse == null) ? "?" : spouse.GetPrimaryFullName();

            return(result);
        }
Пример #16
0
        public void Test_FTB6_ANSI_Win1251()
        {
            using (BaseContext ctx = new BaseContext(null)) {
                Assembly assembly = typeof(CoreTests).Assembly;
                using (Stream stmGed1 = assembly.GetManifestResourceStream("GKTests.Resources.test_ftb6_ansi(win1251).ged")) {
                    var gedcomProvider = new GEDCOMProvider(ctx.Tree);
                    gedcomProvider.LoadFromStreamExt(stmGed1, stmGed1);

                    GEDCOMIndividualRecord iRec1 = ctx.Tree.XRefIndex_Find("I1") as GEDCOMIndividualRecord;
                    Assert.IsNotNull(iRec1);

                    Assert.AreEqual("Иван Васильевич Петров", iRec1.GetPrimaryFullName());
                }
            }
        }
Пример #17
0
        public void Test_Common()
        {
            GEDCOMIndividualRecord iRec = fContext.Tree.XRefIndex_Find("I1") as GEDCOMIndividualRecord;

            Assert.IsNotNull(iRec);

            for (int k = 0; k < REP_COUNT; k++)
            {
                GEDCOMListTest11(iRec);
                GEDCOMListTest12(iRec);
                GEDCOMListTest21(iRec);
                GEDCOMListTest22(iRec);
                GEDCOMListTest23(iRec);
            }
        }
Пример #18
0
        public bool DeleteGroupRecord(GEDCOMGroupRecord groupRec)
        {
            if (groupRec == null)
            {
                return(false);
            }

            for (int i = groupRec.Members.Count - 1; i >= 0; i--)
            {
                GEDCOMIndividualRecord member = groupRec.Members[i].Value as GEDCOMIndividualRecord;
                groupRec.RemoveMember(member);
            }

            DeleteRecord(groupRec);
            return(true);
        }
Пример #19
0
        public override void Assign(GEDCOMTag source)
        {
            GEDCOMIndividualRecord sourceRec = source as GEDCOMIndividualRecord;

            if (sourceRec == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "source");
            }

            base.Assign(source);

            foreach (GEDCOMPersonalName srcName in sourceRec.fPersonalNames)
            {
                GEDCOMPersonalName copyName = (GEDCOMPersonalName)GEDCOMPersonalName.Create(Owner, this, "", "");
                copyName.Assign(srcName);
                AddPersonalName(copyName);
            }
        }
Пример #20
0
        public bool AddMember(GEDCOMIndividualRecord member)
        {
            if (member == null)
            {
                return(false);
            }

            GEDCOMPointer ptr = new GEDCOMPointer(Owner, this, "", "");

            ptr.SetNamedValue("_MEMBER", member);
            fMembers.Add(ptr);

            ptr = new GEDCOMPointer(Owner, member, "", "");
            ptr.SetNamedValue("_GROUP", this);
            member.Groups.Add(ptr);

            return(true);
        }
Пример #21
0
        public override void Clear()
        {
            base.Clear();

            // Special cleaning of Husband and Wife is not necessary,
            // because these are sub-tags and they will be cleared in the call base.Clear()

            int num = fChildren.Count;

            for (int i = 0; i < num; i++)
            {
                GEDCOMIndividualRecord child = (GEDCOMIndividualRecord)fChildren[i].Value;
                child.DeleteChildToFamilyLink(this);
            }
            fChildren.Clear();

            fSpouseSealings.Clear();
        }
Пример #22
0
        public int IndexOfMember(GEDCOMIndividualRecord member)
        {
            int result = -1;

            if (member != null)
            {
                int num = fMembers.Count;
                for (int i = 0; i < num; i++)
                {
                    if (fMembers[i].XRef == member.XRef)
                    {
                        result = i;
                        break;
                    }
                }
            }

            return(result);
        }
Пример #23
0
        public bool AddChild(GEDCOMIndividualRecord child)
        {
            if (child == null)
            {
                return(false);
            }

            GEDCOMPointer ptr = new GEDCOMPointer(Owner, this, "", "");

            ptr.SetNamedValue("CHIL", child);
            fChildren.Add(ptr);

            GEDCOMChildToFamilyLink chLink = new GEDCOMChildToFamilyLink(Owner, child, "", "");

            chLink.Family = this;
            child.ChildToFamilyLinks.Add(chLink);

            return(true);
        }
Пример #24
0
        public void RemoveSpouse(GEDCOMIndividualRecord spouse)
        {
            if (spouse == null)
            {
                return;
            }

            spouse.DeleteSpouseToFamilyLink(this);

            switch (spouse.Sex)
            {
            case GEDCOMSex.svMale:
                Husband.Value = null;
                break;

            case GEDCOMSex.svFemale:
                Wife.Value = null;
                break;
            }
        }
Пример #25
0
        // Support function. Parse GEDCOM string, returns ADDR object found
        private GEDCOMAddress AddrParse(string text)
        {
            // TODO should go into general utility class
            GEDCOMTree     tee = new GEDCOMTree();
            GEDCOMProvider gp  = new GEDCOMProvider(tee);

            try {
                gp.LoadFromString(text);
            } catch (Exception) {
            }
            Assert.AreEqual(1, tee.RecordsCount);
            GEDCOMRecord rec = tee[0];

            Assert.IsTrue(rec is GEDCOMIndividualRecord);
            GEDCOMIndividualRecord rec2 = (GEDCOMIndividualRecord)rec;
            // end for utility class

            GEDCOMList <GEDCOMCustomEvent> events = rec2.Events;

            Assert.AreEqual(1, events.Count);
            GEDCOMCustomEvent evt = events[0];

            return(evt.Address);
        }
Пример #26
0
        public override void MoveTo(GEDCOMRecord targetRecord, bool clearDest)
        {
            GEDCOMIndividualRecord toRec = targetRecord as GEDCOMIndividualRecord;

            if (toRec == null)
            {
                throw new ArgumentException(@"Argument is null or wrong type", "targetRecord");
            }

            if (!clearDest)
            {
                DeleteTag("SEX");
                DeleteTag("_UID");
            }

            base.MoveTo(targetRecord, clearDest);

            while (fPersonalNames.Count > 0)
            {
                GEDCOMPersonalName obj = fPersonalNames.Extract(0);
                obj.ResetParent(toRec);
                toRec.AddPersonalName(obj);
            }

            if (toRec.ChildToFamilyLinks.Count == 0 && ChildToFamilyLinks.Count != 0 && fChildToFamilyLinks != null)
            {
                GEDCOMChildToFamilyLink ctfLink = fChildToFamilyLinks.Extract(0);
                GEDCOMFamilyRecord      family  = ctfLink.Family;

                int num = family.Children.Count;
                for (int i = 0; i < num; i++)
                {
                    GEDCOMPointer childPtr = family.Children[i];

                    if (childPtr.StringValue == "@" + XRef + "@")
                    {
                        childPtr.StringValue = "@" + targetRecord.XRef + "@";
                    }
                }

                ctfLink.ResetParent(toRec);
                toRec.ChildToFamilyLinks.Add(ctfLink);
            }

            while (fSpouseToFamilyLinks.Count > 0)
            {
                GEDCOMSpouseToFamilyLink stfLink = fSpouseToFamilyLinks.Extract(0);
                GEDCOMFamilyRecord       family  = stfLink.Family;

                string targetXRef = "@" + targetRecord.XRef + "@";

                if (family.Husband.StringValue == "@" + XRef + "@")
                {
                    family.Husband.StringValue = targetXRef;
                }
                else if (family.Wife.StringValue == "@" + XRef + "@")
                {
                    family.Wife.StringValue = targetXRef;
                }

                stfLink.ResetParent(toRec);
                toRec.SpouseToFamilyLinks.Add(stfLink);
            }

            while (fIndividualOrdinances.Count > 0)
            {
                GEDCOMIndividualOrdinance ord = fIndividualOrdinances.Extract(0);
                ord.ResetParent(toRec);
                toRec.IndividualOrdinances.Add(ord);
            }

            while (fSubmittors.Count > 0)
            {
                GEDCOMPointer obj = fSubmittors.Extract(0);
                obj.ResetParent(toRec);
                toRec.Submittors.Add(obj);
            }

            while (fAssociations.Count > 0)
            {
                GEDCOMAssociation obj = fAssociations.Extract(0);
                obj.ResetParent(toRec);
                toRec.Associations.Add(obj);
            }

            while (fAliasses.Count > 0)
            {
                GEDCOMAlias obj = fAliasses.Extract(0);
                obj.ResetParent(toRec);
                toRec.Aliases.Add(obj);
            }

            while (fAncestorsInterest.Count > 0)
            {
                GEDCOMPointer obj = fAncestorsInterest.Extract(0);
                obj.ResetParent(toRec);
                toRec.AncestorsInterest.Add(obj);
            }

            while (fDescendantsInterest.Count > 0)
            {
                GEDCOMPointer obj = fDescendantsInterest.Extract(0);
                obj.ResetParent(toRec);
                toRec.DescendantsInterest.Add(obj);
            }

            while (fGroups.Count > 0)
            {
                GEDCOMPointer obj = fGroups.Extract(0);
                obj.ResetParent(toRec);
                toRec.Groups.Add(obj);
            }
        }
Пример #27
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);
        }