예제 #1
0
 public Age(Individual ind, FactDate when)
     : this()
 {
     if (when.IsAfter(ind.DeathDate))
     {
         when = ind.DeathDate;
     }
     log.Debug("Calculating Age for " + ind.Name + " on " + when.ToString());
     log.Debug("Min age: birth enddate:" + ind.BirthDate.EndDate + " to startdate:" + when.StartDate);
     log.Debug("Max age: birth startdate:" + ind.BirthDate.StartDate + " to enddate:" + when.EndDate);
     MinAge = GetAge(ind.BirthDate.EndDate, when.StartDate);
     MaxAge = GetAge(ind.BirthDate.StartDate, when.EndDate);
     log.Debug("Calculated minage:" + MinAge + " calculated maxage:" + MaxAge);
     if (MinAge == FactDate.MINYEARS)
     {
         if (MaxAge == FactDate.MAXYEARS)
         {
             age = "Unknown";
         }
         else
         {
             age = MaxAge == 0 ? "< 1" : "<=" + MaxAge;
         }
     }
     else if (MaxAge < FactDate.MAXYEARS)
     {
         age = MinAge == MaxAge?MinAge.ToString() : MinAge + " to " + MaxAge;
     }
     else
     {
         // if age over maximum return maximum
         age = ">=" + MinAge;
     }
 }
예제 #2
0
 public void UpdateFactDate(FactDate date)
 {
     if (!FactDate.IsKnown && date != null && date.IsKnown)
     {
         FactDate = date;
     }
 }
예제 #3
0
        public Age(Individual ind, FactDate when)
            : this()
        {
            if (when.IsAfter(ind.DeathDate))
            {
                when = ind.DeathDate;
            }

            //Logger.Debug($"Calculating Age for {ind.Name} on {when}");
            //Logger.Debug($"Min age: birth enddate: {ind.BirthDate.EndDate} to startdate: {when.StartDate}");
            //Logger.Debug($"Max age: birth startdate: {ind.BirthDate.StartDate} to enddate: {when.EndDate}");

            MinAge = GetAge(ind.BirthDate.EndDate, when.StartDate);
            MaxAge = GetAge(ind.BirthDate.StartDate, when.EndDate);

            //Logger.Debug($"Calculated minage: {MinAge} calculated maxage: {MaxAge}");
            if (MinAge == FactDate.MINYEARS)
            {
                _age = (MaxAge == FactDate.MAXYEARS) ? "Unknown" : MaxAge == 0 ? "< 1" : $"<= {MaxAge}";
            }
            else if (MaxAge < FactDate.MAXYEARS)
            {
                _age = MinAge == MaxAge ? $"{MinAge}" : $"{MinAge} to {MaxAge}";
            }
            else
            {
                _age = $">= {MinAge}"; // if age over maximum return maximum
            }
        }
예제 #4
0
 public bool BothParentsAlive(FactDate when)
 {
     if (Husband == null || Wife == null || FamilyID == SOLOINDIVIDUAL)
     {
         return(false);
     }
     return(Husband.IsAlive(when) && Wife.IsAlive(when) && Husband.GetAge(when).MinAge > 13 && Wife.GetAge(when).MinAge > 13);
 }
예제 #5
0
 public bool BothParentsAlive(FactDate when)
 {
     if (Husband is null || Wife is null || FamilyType.Equals(SOLOINDIVIDUAL))
     {
         return(false);
     }
     return(Husband.IsAlive(when) && Wife.IsAlive(when) && Husband.GetAge(when).MinAge > 13 && Wife.GetAge(when).MinAge > 13);
 }
예제 #6
0
        private int sortBirthdate(Individual i1, Individual i2)
        {
            Fact     b1 = i1.BirthFact;
            Fact     b2 = i2.BirthFact;
            FactDate d1 = (b1 == null) ? FactDate.UNKNOWN_DATE : b1.FactDate;
            FactDate d2 = (b2 == null) ? FactDate.UNKNOWN_DATE : b2.FactDate;

            return(d1.CompareTo(d2));
        }
예제 #7
0
 public Fact(string factRef, string factType, FactDate date, FactLocation loc, string comment = "", bool preferred = true, bool createdByFTA = false)
     : this(factRef, preferred)
 {
     this.FactType = factType;
     this.FactDate = date;
     this.Comment  = comment;
     this.Created  = createdByFTA;
     this.Place    = string.Empty;
     this.Location = loc;
 }
예제 #8
0
        public FactDate GetBirthDate(FactDate when)
        {
            if (CalculatedBirthDate.IsKnown)
            {
                return(CalculatedBirthDate);
            }
            DateTime startDate = when.StartDate.TryAddYears(-MaxAge);
            DateTime endDate   = when.EndDate.TryAddYears(-MinAge);

            return(new FactDate(startDate, endDate));
        }
예제 #9
0
        public static bool IsCensusCountry(FactDate fd, FactLocation location)
        {
            List <CensusDate> matches = SUPPORTED_CENSUS.Where(cd => cd.Country.Equals(location.CensusCountry)).ToList();

            foreach (CensusDate cd in matches)
            {
                if (fd.YearMatches(cd))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #10
0
        public static bool IsCensusYear(FactDate fd, string Country, bool exactYear)
        {
            switch (Country)
            {
            case Countries.UNITED_STATES:
                return(US_FEDERAL_CENSUS.Any(cd => fd.Overlaps(cd)));

            case Countries.CANADA:
                return(CANADIAN_CENSUS.Any(cd => fd.Overlaps(cd)));

            default:
                return(SUPPORTED_CENSUS.Any(cd =>
                                            (exactYear && fd.CensusYearMatches(cd)) || (!exactYear && fd.Overlaps(cd))));
            }
        }
예제 #11
0
 public static CensusDate GetLostCousinsCensusYear(FactDate fd, bool exactYear)
 {
     foreach (CensusDate cd in LOSTCOUSINS_CENSUS)
     {
         if (exactYear && fd.YearMatches(cd))
         {
             return(cd);
         }
         if (!exactYear && fd.Overlaps(cd))
         {
             return(cd);
         }
     }
     return(null);
 }
예제 #12
0
 public static bool IsUKCensusYear(FactDate fd, bool exactYear)
 {
     foreach (CensusDate cd in UK_CENSUS)
     {
         if (exactYear && fd.YearMatches(cd))
         {
             return(true);
         }
         if (!exactYear && fd.Overlaps(cd))
         {
             return(true);
         }
     }
     return(false);
 }
예제 #13
0
        public Age(string gedcomAge, FactDate when)
            : this()
        {
            // parse ages from gedcom
            Match matcher = ydm.Match(gedcomAge);

            if (matcher.Success)
            {
                GEDCOM_Age = gedcomAge;

                string year  = matcher.Groups["year"].ToString().TrimEnd('y');
                string month = matcher.Groups["month"].ToString().TrimEnd('m');
                string day   = matcher.Groups["day"].ToString().TrimEnd('d');

                DateTime startDate = when.StartDate;
                DateTime endDate   = when.EndDate;
                if (int.TryParse(year, out int yearno))
                {
                    if (startDate != FactDate.MINDATE && startDate.Year > yearno + 1)
                    {
                        startDate = startDate.TryAddYears(-yearno);
                    }
                    endDate = endDate.TryAddYears(-yearno);
                }
                if (int.TryParse(month, out int monthno))
                {
                    if (startDate != FactDate.MINDATE && startDate.Year > 1)
                    {
                        startDate = startDate.AddMonths(-monthno);
                    }
                    endDate = endDate.AddMonths(-monthno);
                }
                if (int.TryParse(day, out int dayno))
                {  // -dayno + 1 as date will be at time 00:00 and subtraction is one day too much.
                    if (startDate != FactDate.MINDATE && startDate.Year > 1)
                    {
                        startDate = startDate.AddDays(-dayno);
                    }
                    endDate = endDate.AddDays(-dayno);
                }
                CalculatedBirthDate = new FactDate(startDate, endDate);
            }
        }
예제 #14
0
 private void ScoreDates(FactDate dateA, FactDate dateB)
 {
     if (dateA.IsKnown && dateB.IsKnown)
     {
         double distance = dateA.Distance(dateB);
         if (dateA.Equals(dateB))
         {
             Score += 50;
         }
         else if (distance <= .25)
         {
             Score += 50;
         }
         else if (distance <= .5)
         {
             Score += 20;
         }
         else if (distance <= 1)
         {
             Score += 10;
         }
         else if (distance <= 2)
         {
             Score += 5;
         }
         else if (distance > 5 && distance < 20)
         {
             Score -= (int)(distance * distance);
         }
         else
         {
             Score = -10000;  // distance is too big so set score to large negative
         }
         if (dateA.IsExact && dateB.IsExact)
         {
             Score += 100;
         }
     }
 }
예제 #15
0
 public bool IsValidCensus(FactDate when)
 {
     return(FactDate.IsKnown && IsCensusFact && FactDate.YearMatches(when) && FactDate.IsNotBEForeOrAFTer && FactErrorLevel == Fact.FactError.GOOD);
 }
예제 #16
0
 public bool IsValidLostCousins(FactDate when)
 {
     return(FactDate.IsKnown && (FactType == Fact.LOSTCOUSINS || FactType == Fact.LC_FTA) &&
            FactDate.YearMatches(when) && FactDate.IsNotBEForeOrAFTer && FactErrorLevel == Fact.FactError.GOOD);
 }
예제 #17
0
 public static CensusDate GetLostCousinsCensusYear(FactDate fd, bool exactYear) =>
 LOSTCOUSINS_CENSUS.FirstOrDefault(
     cd => (exactYear && fd.CensusYearMatches(cd)) || (!exactYear && fd.Overlaps(cd))
     );
예제 #18
0
 public static bool IsCensusCountry(FactDate fd, FactLocation location) =>
 SUPPORTED_CENSUS.Any(cd => cd.Country == location.CensusCountry && fd.CensusYearMatches(cd));
예제 #19
0
 public static bool IsLostCousinsCensusYear(FactDate fd, bool exactYear) =>
 GetLostCousinsCensusYear(fd, exactYear) != null;
예제 #20
0
 public static bool IsUKCensusYear(FactDate fd, bool exactYear) =>
 UK_CENSUS.Any(cd =>
               (exactYear && fd.CensusYearMatches(cd)) || (!exactYear && fd.Overlaps(cd))
               );
예제 #21
0
        private void CreateFact(XmlNode node, string reference, bool preferred)
        {
            if (node != null)
            {
                FamilyTree ft = FamilyTree.Instance;
                try
                {
                    FactType = FixFactTypes(node.Name);
                    string factDate = FamilyTree.GetText(node, "DATE", false);
                    this.FactDate  = new FactDate(factDate, reference);
                    this.Preferred = preferred;
                    if (FactType.Equals(CUSTOM_EVENT) || FactType.Equals(CUSTOM_FACT))
                    {
                        string tag = FamilyTree.GetText(node, "TYPE", false).ToUpper();
                        string factType;
                        if (CUSTOM_TAGS.TryGetValue(tag, out factType))
                        {
                            FactType = factType;
                            CheckCensusDate(tag);
                        }
                        else
                        {
                            FactType = Fact.UNKNOWN;
                            FamilyTree.Instance.CheckUnknownFactTypes(tag);
                            Tag = tag;
                        }
                    }
                    SetCommentAndLocation(FactType, FamilyTree.GetText(node, false), FamilyTree.GetText(node, "PLAC", false),
                                          FamilyTree.GetText(node, "PLAC/MAP/LATI", false), FamilyTree.GetText(node, "PLAC/MAP/LONG", false));
                    if (Location.IsBlank)
                    {
                        SetAddress(FactType, node);
                    }

                    // only check UK census dates for errors as those are used for colour census
                    if (FactType.Equals(CENSUS) && Location.IsUnitedKingdom)
                    {
                        CheckCensusDate("Census");
                    }

                    // need to check residence after setting location
                    if (FactType.Equals(RESIDENCE) && Properties.GeneralSettings.Default.UseResidenceAsCensus)
                    {
                        CheckResidenceCensusDate();
                    }

                    // check Children Status is valid
                    if (FactType.Equals(CHILDREN1911))
                    {
                        CheckValidChildrenStatus(node);
                    }

                    // now iterate through source elements of the fact finding all sources
                    XmlNodeList list = node.SelectNodes("SOUR");
                    foreach (XmlNode n in list)
                    {
                        if (n.Attributes["REF"] != null)
                        {   // only process sources with a reference
                            string     srcref = n.Attributes["REF"].Value;
                            FactSource source = ft.GetSourceID(srcref);
                            if (source != null)
                            {
                                Sources.Add(source);
                                source.AddFact(this);
                            }
                            else
                            {
                                ft.XmlErrorBox.AppendText("Source " + srcref + " not found." + "\n");
                            }
                        }
                        if (IsCensusFact)
                        {
                            this.CensusReference = new CensusReference(this, n);
                        }
                    }
                    // if we have checked the sources and no census ref see if its been added as a comment to this fact
                    if (FactType.Equals(CENSUS) || FactType.Equals(CENSUS_FTA) || FactType.Equals(RESIDENCE))
                    {
                        CheckForSharedFacts(node);
                        if (this.CensusReference == CensusReference.UNKNOWN)
                        {
                            this.CensusReference = new CensusReference(this, node);
                        }
                        else if (!this.CensusReference.IsKnownStatus)
                        {
                            CensusReference pageRef = this.CensusReference;
                            this.CensusReference = new CensusReference(this, node, pageRef);
                        }
                    }
                    if (FactType == DEATH)
                    {
                        Comment = FamilyTree.GetText(node, "CAUS", true);
                        if (node.FirstChild != null && node.FirstChild.Value == "Y" && !FactDate.IsKnown)
                        {
                            FactDate = new FactDate(FactDate.MINDATE, DateTime.Now); // if death flag set as Y then death before today.
                        }
                    }
                    string age = FamilyTree.GetText(node, "AGE", false);
                    if (age.Length > 0)
                    {
                        this.GedcomAge = new Age(age, FactDate);
                    }
                    this.CertificatePresent = SetCertificatePresent();
                }
                catch (Exception ex)
                {
                    string message = (node == null) ? string.Empty : node.InnerText + ". ";
                    throw new InvalidXMLFactException(message + "\n            Error " + ex.Message + "\n");
                }
            }
        }
예제 #22
0
        private void CheckCensusDate(string tag)
        {
            FactDate yearAdjusted = FactDate;

            // check if census fails to overlaps a census date
            if ((tag == "Census 1841" && !FactDate.Overlaps(CensusDate.UKCENSUS1841)) ||
                (tag == "Census 1851" && !FactDate.Overlaps(CensusDate.UKCENSUS1851)) ||
                (tag == "Census 1861" && !FactDate.Overlaps(CensusDate.UKCENSUS1861)) ||
                (tag == "Census 1871" && !FactDate.Overlaps(CensusDate.UKCENSUS1871)) ||
                (tag == "Census 1881" && !FactDate.Overlaps(CensusDate.UKCENSUS1881)) ||
                (tag == "Census 1891" && !FactDate.Overlaps(CensusDate.UKCENSUS1891)) ||
                (tag == "Census 1901" && !FactDate.Overlaps(CensusDate.UKCENSUS1901)) ||
                (tag == "Census 1911" && !FactDate.Overlaps(CensusDate.UKCENSUS1911)) ||
                (tag == "Census 1939" && !FactDate.Overlaps(CensusDate.UKCENSUS1939)) ||
                (tag == "Census" && !CensusDate.IsUKCensusYear(FactDate, false)) ||
                ((tag == "Lost Cousins" || tag == "LostCousins") && !CensusDate.IsLostCousinsCensusYear(FactDate, false)) &&
                FactDate.DateString.Length >= 4)
            {
                // if not a census overlay then set date to year and try that instead
                string year   = FactDate.DateString.Substring(FactDate.DateString.Length - 4);
                int    result = 0;
                if (Int32.TryParse(year, out result))
                {
                    yearAdjusted = new FactDate(year);
                    if (Properties.GeneralSettings.Default.TolerateInaccurateCensusDate)
                    {
                        //                        this.FactErrorNumber = (int)FamilyTree.Dataerror.RESIDENCE_CENSUS_DATE;
                        this.FactErrorMessage = "Warning: Inaccurate Census date '" + FactDate + "' treated as '" + yearAdjusted + "'";
                        this.FactErrorLevel   = Fact.FactError.WARNINGALLOW;
                    }
                    else
                    {
                        //                        this.FactErrorNumber = (int)FamilyTree.Dataerror.RESIDENCE_CENSUS_DATE;
                        this.FactErrorLevel   = Fact.FactError.WARNINGIGNORE;
                        this.FactErrorMessage = "Inaccurate Census date '" + FactDate + "' fact ignored in strict mode. Check for incorrect date entered or try Tolerate slightly inaccurate census date option.";
                    }
                }
            }
            if ((tag == "Census 1841" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1841)) ||
                (tag == "Census 1851" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1851)) ||
                (tag == "Census 1861" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1861)) ||
                (tag == "Census 1871" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1871)) ||
                (tag == "Census 1881" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1881)) ||
                (tag == "Census 1891" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1891)) ||
                (tag == "Census 1901" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1901)) ||
                (tag == "Census 1911" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1911)) ||
                (tag == "Census 1939" && !yearAdjusted.Overlaps(CensusDate.UKCENSUS1939)))
            {
                this.FactErrorMessage = "UK Census fact error date '" + FactDate + "' doesn't match '" + tag + "' tag. Check for incorrect date entered.";
                this.FactErrorLevel   = FactError.ERROR;
                //                this.FactErrorNumber = (int)FamilyTree.Dataerror.CENSUS_COVERAGE;
                return;
            }
            if (tag == "Census" || tag == "LostCousins" || tag == "Lost Cousins")
            {
                TimeSpan ts = FactDate.EndDate - FactDate.StartDate;
                if (ts.Days > 3650)
                {
                    //                    this.FactErrorNumber = (int)FamilyTree.Dataerror.CENSUS_COVERAGE;
                    this.FactErrorLevel   = FactError.ERROR;
                    this.FactErrorMessage = "Date covers more than one census.";
                    return;
                }
            }
            if (tag == "Census")
            {
                if (!CensusDate.IsCensusYear(yearAdjusted, false))
                {
                    //                    this.FactErrorNumber = (int)FamilyTree.Dataerror.CENSUS_COVERAGE;
                    this.FactErrorMessage = "Census fact error date '" + FactDate + "' isn't a supported census date. Check for incorrect date entered or try Tolerate slightly inaccurate census date option.";
                    this.FactErrorLevel   = FactError.ERROR;
                    return;
                }
                if (Properties.GeneralSettings.Default.TolerateInaccurateCensusDate && yearAdjusted.IsKnown && !CensusDate.IsCensusYear(yearAdjusted, true))
                {
                    //                    this.FactErrorNumber = (int)FamilyTree.Dataerror.CENSUS_COVERAGE;
                    this.FactErrorMessage = "Warning : Census fact error date '" + FactDate + "' overlaps census date but is vague. Check for incorrect date entered.";
                    this.FactErrorLevel   = FactError.WARNINGALLOW;
                }
                if (!FactDate.Equals(yearAdjusted))
                {
                    FactDate = yearAdjusted;
                }
            }
            if (tag == "Lost Cousins" || tag == "LostCousins")
            {
                if (Properties.GeneralSettings.Default.TolerateInaccurateCensusDate && yearAdjusted.IsKnown && !CensusDate.IsLostCousinsCensusYear(yearAdjusted, true))
                {
                    //                    this.FactErrorNumber = (int)FamilyTree.Dataerror.CENSUS_COVERAGE;
                    this.FactErrorMessage = "Lost Cousins fact error date '" + FactDate + "' overlaps Lost Cousins census year but is vague. Check for incorrect date entered.";
                    this.FactErrorLevel   = Fact.FactError.WARNINGALLOW;
                }
                if (!CensusDate.IsLostCousinsCensusYear(yearAdjusted, false))
                {
                    //                    this.FactErrorNumber = (int)FamilyTree.Dataerror.CENSUS_COVERAGE;
                    this.FactErrorMessage = "Lost Cousins fact error date '" + FactDate + "' isn't a supported Lost Cousins census year. Check for incorrect date entered or try Tolerate slightly inaccurate census date option.";
                    this.FactErrorLevel   = Fact.FactError.ERROR;
                }
                if (!FactDate.Equals(yearAdjusted))
                {
                    FactDate = yearAdjusted;
                }
            }
        }