Beispiel #1
0
        private void btnMubanHelper_Click(object sender, EventArgs e)
        {
            var country = new Entity();
            foreach ( var province in GlobalData.Provinces )
            {
                var provinceData = GlobalData.GetGeocodeList(province.geocode);
                country.entity.Add(provinceData);
            }
            var allEntities = country.FlatList();

            var romanizator = new Romanization();
            romanizator.Initialize(allEntities);
            var form = new MubanHelperForm();
            form.Romanizator = romanizator;
            form.Show();
        }
Beispiel #2
0
        private void btnCheckNames_Click(object sender, EventArgs e)
        {
            var romanizationMissing = new List<RomanizationEntry>();

            var country = new Entity();
            foreach ( var province in GlobalData.Provinces )
            {
                var provinceData = GlobalData.GetGeocodeList(province.geocode);
                country.entity.Add(provinceData);
            }
            var allEntities = country.FlatList();
            Int32 numberOfEntities = allEntities.Count();

            var romanizator = new Romanization();
            romanizator.Initialize(allEntities);
            var romanizations = romanizator.Romanizations;
            var romanizationMistakes = romanizator.RomanizationMistakes;
            var romanizationSuggestions = romanizator.FindRomanizationSuggestions(out romanizationMissing, allEntities);

            UInt32 provinceFilter = 0;
            //if ( cbxCheckNamesFiltered.Checked )
            //{
            //    provinceFilter = GetCurrentChangwat().Geocode;
            //}

            StringBuilder romanizationMistakesBuilder = new StringBuilder();
            Int32 romanizationMistakeCount = 0;
            foreach ( var entry in romanizationMistakes )
            {
                if ( GeocodeHelper.IsBaseGeocode(provinceFilter, entry.Key.Geocode) )
                {
                    romanizationMistakesBuilder.AppendLine(String.Format("{0} {1}: {2} vs. {3}", entry.Key.Geocode, entry.Key.Name, entry.Key.English, entry.Value));
                    romanizationMistakeCount++;
                }
            }

            if ( romanizationMistakeCount > 0 )
            {
                var displayForm = new StringDisplayForm(
                    String.Format("Romanization problems ({0})", romanizationMistakeCount),
                    romanizationMistakesBuilder.ToString());
                displayForm.Show();
            }

            StringBuilder romanizationSuggestionBuilder = new StringBuilder();
            Int32 romanizationSuggestionCount = 0;
            foreach ( var entry in romanizationSuggestions )
            {
                if ( GeocodeHelper.IsBaseGeocode(provinceFilter, entry.Geocode) )
                {
                    var entity = allEntities.FirstOrDefault(x => x.geocode == entry.Geocode);
                    var suggestedName = entry.English;
                    romanizationSuggestionBuilder.AppendLine(String.Format("<entity type=\"{0}\" geocode=\"{1}\" name=\"{2}\" english=\"{3}\" />",
                        entity.type, entity.geocode, entity.name, suggestedName));
                    romanizationSuggestionCount++;
                }
            }
            if ( romanizationSuggestionCount > 0 )
            {
                var form = new StringDisplayForm(
                    String.Format("Romanization suggestions ({0}", romanizationSuggestionCount),
                    romanizationSuggestionBuilder.ToString());
                form.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.Name);
                    if ( found == null )
                    {
                        counter.Add(Tuple.Create(entry.Name, entry.English, 1));
                    }
                    else
                    {
                        counter.Remove(found);
                        counter.Add(Tuple.Create(entry.Name, entry.English, 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 displayForm = new StringDisplayForm(
                        String.Format("Romanization suggestions ({0} of {1})", suggestionCounter, romanizationSuggestionCount),
                        sortedBuilder.ToString());
                    displayForm.Show();
                }
            }

            // show missing romanizations
            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.Name);
                    if ( found == null )
                    {
                        counter.Add(Tuple.Create(entry.Name, 1));
                    }
                    else
                    {
                        counter.Remove(found);
                        counter.Add(Tuple.Create(entry.Name, 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 displayForm = new StringDisplayForm(
                        String.Format("Romanization missing ({0} of {1})", romanizationMissing.Count, numberOfEntities),
                        sortedBuilder.ToString());
                    displayForm.Show();
                }
            }
        }