public PopulationDataEntry FindByCode(Int32 code) { PopulationDataEntry retval = null; if (this.Geocode == code) { retval = this; } else { retval = SubEntities.FirstOrDefault(entry => (entry != null) && (entry.Geocode == code)); if (retval == null) { SubEntities.ForEach(delegate(PopulationDataEntry entity) { if ((retval == null) && (entity != null)) { if (TambonHelper.IsBaseGeocode(entity.Geocode, code)) { retval = entity.FindByCode(code); } } }); } } return(retval); }
internal List <PopulationDataEntry> InvalidGeocodeEntries() { List <PopulationDataEntry> lResult = new List <PopulationDataEntry>(); foreach (PopulationDataEntry lEntry in SubEntities) { if (!TambonHelper.IsBaseGeocode(this.Geocode, lEntry.Geocode)) { lResult.Add(lEntry); } Int32 lCount = 0; foreach (PopulationDataEntry lCountEntry in SubEntities) { if (lCountEntry.Geocode == lEntry.Geocode) { lCount++; } } if (lCount > 1) { lResult.Add(lEntry); } lResult.AddRange(lEntry.InvalidGeocodeEntries()); } return(lResult); }
/// <summary> /// Checks whether two geocodes are identical, or in case the sub entities are included /// if <paramref name="geocodeToCheck"/> is below <paramref name="geocodeToFind"/>. /// </summary> /// <param name="geocodeToFind">Code to find.</param> /// <param name="geocodeToCheck">Code to check.</param> /// <param name="includeSubEntities">Toggles whether codes under the main code are considered fitting as well.</param> /// <returns>True if both codes fit together, false otherwise.</returns> internal static Boolean IsSameGeocode(Int32 geocodeToFind, Int32 geocodeToCheck, Boolean includeSubEntities) { Boolean result = false; if (includeSubEntities) { result = TambonHelper.IsBaseGeocode(geocodeToFind, geocodeToCheck); } else { result = (geocodeToFind == geocodeToCheck); } return(result); }
private List <PopulationDataEntry> LoadGeocodeLists() { var lList = new List <PopulationDataEntry>(); foreach (PopulationDataEntry lEntry in TambonHelper.ProvinceGeocodes) { if (TambonHelper.IsBaseGeocode(BaseGeocode, lEntry.Geocode)) { PopulationData lEntities = TambonHelper.GetGeocodeList(lEntry.Geocode); lList.AddRange(lEntities.Data.FlatList(mEntityTypes)); } } return(lList); }
private List <PopulationDataEntry> NormalizeNames(List <PopulationDataEntry> iList) { List <PopulationDataEntry> lResult = new List <PopulationDataEntry>(); foreach (PopulationDataEntry lEntry in iList) { if (lEntry.Type == EntityType.Muban) { lEntry.Name = TambonHelper.StripBanOrChumchon(lEntry.Name); } if ((!lEntry.IsObsolete()) & (TambonHelper.IsBaseGeocode(BaseGeocode, lEntry.Geocode))) { lResult.Add(lEntry); } } lResult.Sort(delegate(PopulationDataEntry p1, PopulationDataEntry p2) { return(p1.Name.CompareTo(p2.Name)); }); return(lResult); }
private void btnCheckNames_Click(object sender, EventArgs e) { PopulationDataEntry masterDataEntry = new PopulationDataEntry(); Dictionary <String, String> romanizations = new Dictionary <String, String>(); var romanizationMistakes = new List <Tuple <Int32, String, String, String> >(); var romanizationSuggestions = new List <Tuple <Int32, String, String> >(); var romanizationMissing = new List <Tuple <Int32, String> >(); var provinceList = new List <PopulationDataEntry>(); foreach (PopulationDataEntry province in TambonHelper.ProvinceGeocodes) { PopulationData entities = TambonHelper.GetGeocodeList(province.Geocode); provinceList.Add(entities.Data); } masterDataEntry.SubEntities.AddRange(provinceList); foreach (var entityToCheck in masterDataEntry.FlatList(EntityTypeHelper.AllEntityTypes)) { if (!String.IsNullOrEmpty(entityToCheck.English)) { String name = entityToCheck.Name; String english = entityToCheck.English; if ((entityToCheck.Type == EntityType.Muban) | (entityToCheck.Type == EntityType.Chumchon)) { name = TambonHelper.StripBanOrChumchon(name); if (english.StartsWith("Ban ")) { english = english.Remove(0, "Ban ".Length).Trim(); } if (english.StartsWith("Chumchon ")) { english = english.Remove(0, "Chumchon ".Length).Trim(); } if (entityToCheck.Type == EntityType.Chumchon) { // Chumchon may have the name "Chumchon Ban ..." name = TambonHelper.StripBanOrChumchon(name); if (english.StartsWith("Ban ")) { english = english.Remove(0, "Ban ".Length).Trim(); } } } if (romanizations.Keys.Contains(name)) { if (romanizations[name] != english) { romanizationMistakes.Add(Tuple.Create(entityToCheck.Geocode, name, english, romanizations[name])); } } else { romanizations[name] = english; } } } foreach (var entityToCheck in masterDataEntry.FlatList(EntityTypeHelper.AllEntityTypes)) { if (String.IsNullOrEmpty(entityToCheck.English)) { String foundEnglishName = String.Empty; if (romanizations.Keys.Contains(entityToCheck.Name)) { foundEnglishName = entityToCheck.Name; } else { var searchName = TambonHelper.StripBanOrChumchon(entityToCheck.Name); if (romanizations.Keys.Contains(searchName)) { foundEnglishName = searchName; } else { // Chumchon may have the name "Chumchon Ban ..." searchName = TambonHelper.StripBanOrChumchon(searchName); if (romanizations.Keys.Contains(searchName)) { foundEnglishName = searchName; } } } if (!String.IsNullOrEmpty(foundEnglishName)) { romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, romanizations[foundEnglishName])); } else { Boolean found = false; String name = TambonHelper.StripBanOrChumchon(entityToCheck.Name); name = TambonHelper.ReplaceThaiNumerals(name); List <Char> numerals = new List <Char>() { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9' }; foreach (Char c in numerals) { name = name.Replace(c, ' '); } name = name.Trim(); foreach (var keyValuePair in TambonHelper.NameSuffixRomanizations) { if (entityToCheck.Name.EndsWith(keyValuePair.Key)) { String searchString = TambonHelper.StripBanOrChumchon(name.Substring(0, name.Length - keyValuePair.Key.Length)); if (String.IsNullOrEmpty(searchString)) { romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, keyValuePair.Value)); found = true; } else if (romanizations.Keys.Contains(searchString)) { romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, romanizations[searchString] + " " + keyValuePair.Value)); found = true; } } } if (!found) { var prefixes = TambonHelper.NamePrefixRomanizations.Union(TambonHelper.NameSuffixRomanizations); foreach (var keyValuePair in prefixes) { if (name.StartsWith(keyValuePair.Key)) { String searchString = name.Substring(keyValuePair.Key.Length); if (String.IsNullOrEmpty(searchString)) { romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, keyValuePair.Value)); found = true; } else if (romanizations.Keys.Contains(searchString)) { romanizationSuggestions.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name, keyValuePair.Value + " " + romanizations[searchString])); found = true; } } } } if (!found) { romanizationMissing.Add(Tuple.Create(entityToCheck.Geocode, entityToCheck.Name)); } } } } Int32 provinceFilter = 0; if (cbxCheckNamesFiltered.Checked) { provinceFilter = GetCurrentChangwat().Geocode; } StringBuilder romanizationMistakesBuilder = new StringBuilder(); Int32 romanizationMistakeCount = 0; foreach (var entry in romanizationMistakes) { if (TambonHelper.IsBaseGeocode(provinceFilter, entry.Item1)) { romanizationMistakesBuilder.AppendLine(String.Format("{0} {1}: {2} vs. {3}", entry.Item1, entry.Item2, entry.Item3, entry.Item4)); romanizationMistakeCount++; } } if (romanizationMistakeCount > 0) { var lForm = new StringDisplayForm("Romanization problems (" + romanizationMistakeCount.ToString() + ")", romanizationMistakesBuilder.ToString()); lForm.Show(); } StringBuilder romanizationSuggestionBuilder = new StringBuilder(); Int32 romanizationSuggestionCount = 0; foreach (var entry in romanizationSuggestions) { if (TambonHelper.IsBaseGeocode(provinceFilter, entry.Item1)) { romanizationSuggestionBuilder.AppendLine(String.Format("{0} {1}: {2}", entry.Item1, entry.Item2, entry.Item3)); romanizationSuggestionCount++; } } if (romanizationSuggestionCount > 0) { var lForm = new StringDisplayForm("Romanization suggestions (" + romanizationSuggestionCount.ToString() + ")", romanizationSuggestionBuilder.ToString()); lForm.Show(); List <Tuple <String, String, Int32> > counter = new List <Tuple <String, String, Int32> >(); foreach (var entry in romanizationSuggestions) { var found = counter.FirstOrDefault(x => x.Item1 == entry.Item2); if (found == null) { counter.Add(Tuple.Create(entry.Item2, entry.Item3, 1)); } else { counter.Remove(found); counter.Add(Tuple.Create(entry.Item2, entry.Item3, found.Item3 + 1)); } } counter.RemoveAll(x => x.Item3 < 2); if (counter.Any()) { counter.Sort(delegate(Tuple <String, String, Int32> p1, Tuple <String, String, Int32> p2) { return(p2.Item3.CompareTo(p1.Item3)); }); Int32 suggestionCounter = 0; StringBuilder sortedBuilder = new StringBuilder(); foreach (var entry in counter) { sortedBuilder.AppendLine(String.Format("{0}: {1} ({2})", entry.Item1, entry.Item2, entry.Item3)); suggestionCounter += entry.Item3; } var lForm2 = new StringDisplayForm( String.Format("Romanization suggestions ({0} of {1})", suggestionCounter, romanizationSuggestionCount), sortedBuilder.ToString()); lForm2.Show(); } } if (romanizationMissing.Any()) { List <Tuple <String, Int32> > counter = new List <Tuple <String, Int32> >(); foreach (var entry in romanizationMissing) { var found = counter.FirstOrDefault(x => x.Item1 == entry.Item2); if (found == null) { counter.Add(Tuple.Create(entry.Item2, 1)); } else { counter.Remove(found); counter.Add(Tuple.Create(entry.Item2, found.Item2 + 1)); } } // counter.RemoveAll(x => x.Item2 < 2); if (counter.Any()) { counter.Sort(delegate(Tuple <String, Int32> p1, Tuple <String, Int32> p2) { var result = p2.Item2.CompareTo(p1.Item2); if (result == 0) { result = p2.Item1.CompareTo(p1.Item1); } return(result); }); Int32 missingCounter = 0; StringBuilder sortedBuilder = new StringBuilder(); foreach (var entry in counter) { sortedBuilder.AppendLine(String.Format("{0}: {1}", entry.Item1, entry.Item2)); missingCounter += entry.Item2; } var lForm2 = new StringDisplayForm( String.Format("Romanization missing ({0} of {1})", missingCounter, romanizationMissing.Count), sortedBuilder.ToString()); lForm2.Show(); } } }