Exemplo n.º 1
0
        protected void ProcessContentForName(RoyalGazetteContentCreate iCreate)
        {
            Int32  lTambonGeocode = iCreate.Geocode / 100;
            String lName          = TambonHelper.StripBanOrChumchon(iCreate.Name);

            if (!String.IsNullOrEmpty(lName))
            {
                String lParentName = String.Empty;
                foreach (RoyalGazetteContent lSubEntry in iCreate.SubEntries)
                {
                    if (lSubEntry is RoyalGazetteContentAreaChange)
                    {
                        lParentName = lSubEntry.Name;
                        // Debug.Assert(lTambonGeocode == (lSubEntry.Geocode / 100), "Parent muban as a different geocode");
                    }
                }
                lParentName = TambonHelper.StripBanOrChumchon(lParentName);
                if (!String.IsNullOrEmpty(lParentName))
                {
                    if (lName.StartsWith(lParentName))
                    {
                        String lSuffix = lName.Remove(0, lParentName.Length).Trim();
                        if (mNewNameSuffix.ContainsKey(lSuffix))
                        {
                            mNewNameSuffix[lSuffix]++;
                        }
                        else
                        {
                            mNewNameSuffix.Add(lSuffix, 1);
                        }
                    }
                    if (lName.EndsWith(lParentName))
                    {
                        String lPrefix = lName.Replace(lParentName, "").Trim();

                        if (mNewNamePrefix.ContainsKey(lPrefix))
                        {
                            mNewNamePrefix[lPrefix]++;
                        }
                        else
                        {
                            mNewNamePrefix.Add(lPrefix, 1);
                        }
                    }
                }
                else
                {
                    mCreationsWithoutParentName++;
                }
            }
        }
Exemplo n.º 2
0
        public string Information(PopulationDataEntry changwat)
        {
            StringBuilder builder = new StringBuilder();

            builder.AppendLine(StatisticsText(changwat));
            builder.AppendLine();

            foreach (KeyValuePair <PopulationDataEntry, PopulationDataEntry> keyValuePair in DifferentMubanNames(changwat))
            {
                builder.Append(keyValuePair.Key.Geocode.ToString());
                builder.Append(' ');
                builder.Append(TambonHelper.StripBanOrChumchon(keyValuePair.Key.Name));
                builder.Append(" instead of ");
                builder.AppendLine(TambonHelper.StripBanOrChumchon(keyValuePair.Value.Name));
            }

            String result = builder.ToString();

            return(result);
        }
Exemplo n.º 3
0
        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);
        }
Exemplo n.º 4
0
        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();
                }
            }
        }