Exemplo n.º 1
0
 private void edit_MGRS_TextChanged(object sender, EventArgs e)
 {
     if (!_Changing)
     {
         String   value    = TambonHelper.ReplaceThaiNumerals(edt_MGRS.Text.ToUpper()).Trim();
         GeoPoint geoPoint = null;
         UtmPoint utmPoint = null;
         try
         {
             _Changing = true;
             if (!TambonHelper.IsNumeric(value.Substring(0, 2)))
             {
                 value = ZoneForThailandMgrs(value) + value;
             }
             utmPoint       = UtmPoint.ParseMgrsString(value);
             geoPoint       = new GeoPoint(utmPoint, (GeoDatum)cbx_datum.SelectedItem);
             geoPoint.Datum = GeoDatum.DatumWGS84();
         }
         catch
         {
             // invalid string
             utmPoint = null;
             geoPoint = null;
         }
         SetValues(geoPoint, utmPoint, sender);
         _Changing = false;
     }
 }
Exemplo n.º 2
0
        private void btnDoConvert_Click(object sender, EventArgs e)
        {
            String value = boxText.Text;

            value        = TambonHelper.ReplaceThaiNumerals(value);
            boxText.Text = value;
        }
Exemplo n.º 3
0
        private void AppendNameInfo(StringBuilder iBuilder)
        {
            iBuilder.AppendLine("Name equal: " + SuffixFrequency(String.Empty).ToString() + " times");
            List <String> lStandardSuffices = new List <String>()
            {
                "เหนือ", "ใต้", "พัฒนา", "ใหม่", "ทอง", "น้อย", "ใน"
            };

            foreach (String lSuffix in lStandardSuffices)
            {
                iBuilder.AppendLine("Suffix " + lSuffix + ": " + SuffixFrequency(lSuffix).ToString() + " times");
            }
            iBuilder.AppendLine("Suffix with number:" + SuffixFrequencyNumbers().ToString() + " times");

            List <String> lStandardPrefixes = new List <String>()
            {
                "ใหม่"
            };

            foreach (String lPrefix in lStandardPrefixes)
            {
                iBuilder.AppendLine("Prefix " + lPrefix + ": " + PrefixFrequency(lPrefix).ToString() + " times");
            }

            iBuilder.AppendLine();

            iBuilder.Append("Other suffices: ");
            List <KeyValuePair <String, Int32> > lSortedSuffices = new List <KeyValuePair <String, Int32> >();

            foreach (KeyValuePair <String, Int32> lKeyValuePair in mNewNameSuffix)
            {
                String lName = TambonHelper.ReplaceThaiNumerals(lKeyValuePair.Key);
                if (lStandardSuffices.Contains(lName))
                {
                }
                else if (String.IsNullOrEmpty(lKeyValuePair.Key))
                {
                }
                else if (TambonHelper.IsNumeric(lName))
                {
                }
                else
                {
                    lSortedSuffices.Add(lKeyValuePair);
                }
            }
            lSortedSuffices.Sort(delegate(KeyValuePair <String, Int32> x, KeyValuePair <String, Int32> y)
            {
                return(y.Value.CompareTo(x.Value));
            });
            foreach (KeyValuePair <String, Int32> lKeyValuePair in lSortedSuffices)
            {
                iBuilder.Append(lKeyValuePair.Key + " (" + lKeyValuePair.Value.ToString() + ") ");
            }
            iBuilder.AppendLine();
        }
Exemplo n.º 4
0
        private RoyalGazette ParseSingeItem(String value)
        {
            value = value.Replace("\t", "");
            RoyalGazette retval   = null;
            Int32        position = value.IndexOf(EntryURL);

            if (position >= 0)
            {
                retval   = new RoyalGazette();
                position = position + EntryURL.Length;
                Int32 position2 = value.IndexOf(EntryURLend);
                retval.URI   = value.Substring(position, position2 - position);
                value        = value.Substring(position2, value.Length - position2);
                position     = value.IndexOf(EntryTitle) + EntryTitle.Length;
                position2    = value.IndexOf(EntryTitleEnd);
                retval.Title = value.Substring(position, position2 - position).Trim();
                value        = value.Substring(position2, value.Length - position2);
                position     = value.IndexOf(EntryVolumeorPage) + EntryVolumeorPage.Length;
                position2    = value.IndexOf(ColumnEnd, position);
                String volume = value.Substring(position, position2 - position);
                retval.Volume = Convert.ToInt32(TambonHelper.ReplaceThaiNumerals(volume));
                value         = value.Substring(position2, value.Length - position2);
                position      = value.IndexOf(EntryIssue) + EntryIssue.Length;
                position2     = value.IndexOf(ColumnEnd, position);
                String Issue = TambonHelper.ReplaceThaiNumerals(value.Substring(position, position2 - position).Trim());
                value        = value.Substring(position2, value.Length - position2);
                retval.Issue = new RoyalGazetteIssue(Issue);
                position     = value.IndexOf(EntryDate) + EntryDate.Length;
                position2    = value.IndexOf(ColumnEnd, position);
                String Date = value.Substring(position, position2 - position);
                retval.Publication = TambonHelper.ParseThaiDate(Date);
                value     = value.Substring(position2, value.Length - position2);
                position  = value.IndexOf(EntryVolumeorPage) + EntryVolumeorPage.Length;
                position2 = value.IndexOf(ColumnEnd, position);
                String page = value.Substring(position, position2 - position);
                if (String.IsNullOrEmpty(page))
                {
                    retval.PageInfo.Page = 1;
                }
                else
                {
                    retval.PageInfo.Page = Convert.ToInt32(TambonHelper.ReplaceThaiNumerals(page));
                }

                if (retval.Title.Contains('[') && retval.Title.EndsWith("]"))
                {
                    var beginSubTitle = retval.Title.LastIndexOf('[');
                    retval.SubTitle = retval.Title.Substring(beginSubTitle + 1, retval.Title.Length - beginSubTitle - 2).Trim();
                    retval.Title    = retval.Title.Substring(0, beginSubTitle - 1).Trim();
                }
            }
            return(retval);
        }
Exemplo n.º 5
0
        protected Int32 SuffixFrequencyNumbers()
        {
            Int32 retval = 0;

            foreach (KeyValuePair <String, Int32> lKeyValue in mNewNameSuffix)
            {
                String lName = TambonHelper.ReplaceThaiNumerals(lKeyValue.Key);
                if ((!String.IsNullOrEmpty(lName)) && (TambonHelper.IsNumeric(lName)))
                {
                    retval = retval + lKeyValue.Value;
                }
            }
            return(retval);
        }
Exemplo n.º 6
0
 private void edit_UTM_TextChanged(object sender, EventArgs e)
 {
     if (!_Changing)
     {
         String   value    = TambonHelper.ReplaceThaiNumerals(edt_UTM.Text.ToUpper()).Replace(",", "").Trim();
         GeoPoint geoPoint = null;
         UtmPoint utmPoint = null;
         try
         {
             _Changing      = true;
             utmPoint       = UtmPoint.ParseUtmString(value);
             geoPoint       = new GeoPoint(utmPoint, (GeoDatum)cbx_datum.SelectedItem);
             geoPoint.Datum = GeoDatum.DatumWGS84();
         }
         catch
         {
             // invalid string
             utmPoint = null;
             geoPoint = null;
         }
         SetValues(geoPoint, utmPoint, sender);
         _Changing = false;
     }
 }
Exemplo n.º 7
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();
                }
            }
        }