Example #1
0
        /// <summary>
        /// Checks if this instance is about the entity identified by the <paramref name="geocode"/>.
        /// If <paramref name="includeSubEntities"/> is <c>true</c>,
        /// </summary>
        /// <param name="geocode">Geocode to check.</param>
        /// <param name="includeSubEntities">Toggles whether codes under <paramref name="geocode"/> are considered fitting as well.</param>
        /// <returns><c>true</c> if instance is about the code, <c>false</c> otherwise.</returns>
        public Boolean IsAboutGeocode(UInt32 geocode, Boolean includeSubEntities)
        {
            Boolean result = false;

            if (geocodeSpecified)
            {
                result = result | GeocodeHelper.IsSameGeocode(geocode, this.geocode, includeSubEntities);
            }
            if (ownerFieldSpecified)
            {
                result = result | GeocodeHelper.IsSameGeocode(geocode, this.owner, includeSubEntities);
            }
            if (tambonFieldSpecified)
            {
                result = result | GeocodeHelper.IsSameGeocode(geocode, this.tambon, includeSubEntities);
            }

            foreach (var entry in Items)
            {
                var toTest = entry as IGeocode;
                if (toTest != null)
                {
                    result = result | toTest.IsAboutGeocode(geocode, includeSubEntities);
                }
            }
            return(result);
        }
Example #2
0
        public IEnumerable <Entity> InvalidGeocodeEntries()
        {
            var result = new List <Entity>();

            foreach (var subEntity in entity)
            {
                if (!GeocodeHelper.IsBaseGeocode(this.geocode, subEntity.geocode))
                {
                    result.Add(subEntity);
                }

                Int32 entitiesWithSameCode = 0;
                foreach (var subEntityForCount in entity)
                {
                    if (subEntityForCount.geocode == subEntity.geocode)
                    {
                        entitiesWithSameCode++;
                    }
                }
                if (entitiesWithSameCode > 1)
                {
                    result.Add(subEntity);
                }

                result.AddRange(subEntity.InvalidGeocodeEntries());
            }
            return(result);
        }
        public static Uri GetDisplayUrl(Int32 year, UInt32 geocode)
        {
            UInt32 changwatGeocode = GeocodeHelper.ProvinceCode(geocode);
            String url             = String.Format(CultureInfo.InvariantCulture, _urlShowChangwat, year + 543 - 2500, changwatGeocode);

            return(new Uri(url));
        }
        private void FixupWronglyPlacedAmphoe()
        {
            var invalidTambon = new List <Entity>();

            foreach (var amphoe in Data.entity.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe)))
            {
                foreach (var tambon in amphoe.entity.Where(x => !GeocodeHelper.IsBaseGeocode(amphoe.geocode, x.geocode)).ToList())
                {
                    invalidTambon.Add(tambon);
                    amphoe.entity.Remove(tambon);
                }
            }
            foreach (var tambon in invalidTambon)
            {
                var mainTambon = Data.FlatList().FirstOrDefault(x => GeocodeHelper.IsSameGeocode(x.geocode, tambon.geocode, false));
                if (mainTambon != null)
                {
                    foreach (var dataPoint in tambon.population.First().data)
                    {
                        mainTambon.population.First().AddDataPoint(dataPoint);
                    }
                }
            }
            var emptyAmphoe = Data.entity.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe) && !x.entity.Any()).ToList();

            foreach (var toRemove in emptyAmphoe)
            {
                Data.entity.Remove(toRemove);
            }
        }
Example #5
0
        public static Entity LookupGeocode(UInt32 geocode)
        {
            var provinceCode = GeocodeHelper.ProvinceCode(geocode);
            var changwat     = GetGeocodeList(provinceCode);
            var result       = changwat.FlatList().FirstOrDefault(x => x.geocode == geocode);

            return(result);
        }
Example #6
0
        private AmphoeDataForWikipediaExport CalculateAmphoeData(Entity entity, Language language)
        {
            if (entity.type.IsCompatibleEntityType(EntityType.Amphoe))
            {
                var result = new AmphoeDataForWikipediaExport();
                result.Province = _country.entity.FirstOrDefault(x => x.geocode == GeocodeHelper.ProvinceCode(entity.geocode));
                result.AllTambon.AddRange(entity.entity.Where(x => x.type.IsCompatibleEntityType(EntityType.Tambon) && !x.IsObsolete));
                result.LocalAdministrations.AddRange(entity.LocalGovernmentEntitiesOf(_localGovernments).Where(x => !x.IsObsolete));

                var allEntities = result.AllTambon.ToList();
                allEntities.AddRange(result.LocalAdministrations);
                if (CheckWikiData)
                {
                    foreach (var keyValuePair in RetrieveWikpediaLinks(allEntities, language))
                    {
                        result.WikipediaLinks[keyValuePair.Key] = keyValuePair.Value;
                    }
                }
                var counted = entity.CountAllSubdivisions(_localGovernments);
                if (!counted.ContainsKey(EntityType.Muban))
                {
                    counted[EntityType.Muban] = 0;
                }
                foreach (var keyValuePair in counted)
                {
                    result.CentralAdministrationCountByEntity[keyValuePair.Key] = keyValuePair.Value;
                }

                result.MaxPopulation = 0;
                foreach (var tambon in result.AllTambon)
                {
                    var populationData = tambon.population.FirstOrDefault(x => x.Year == PopulationReferenceYear && x.source == PopulationDataSourceType.DOPA);
                    if (populationData != null)
                    {
                        result.MaxPopulation = Math.Max(result.MaxPopulation, populationData.TotalPopulation.total);
                    }
                }

                foreach (var keyValuePair in Entity.CountSubdivisions(result.LocalAdministrations))
                {
                    result.LocalAdministrationCountByEntity[keyValuePair.Key] = keyValuePair.Value;
                }
                return(result);
            }
            else
            {
                return(null);
            }
        }
Example #7
0
        /// <summary>
        /// Gets an enumeration of all geocodes which are not set correctly.
        /// </summary>
        /// <returns></returns>
        public IEnumerable <UInt32> WrongGeocodes()
        {
            var result      = new List <UInt32>();
            var subGeocodes = entity.Select(x => x.geocode);

            result.AddRange(subGeocodes.Where(x => !GeocodeHelper.IsBaseGeocode(this.geocode, x)));
            var duplicates = subGeocodes.GroupBy(s => s).SelectMany(grp => grp.Skip(1));

            result.AddRange(duplicates);
            foreach (var subentity in entity)
            {
                result.AddRange(subentity.WrongGeocodes());
            }
            return(result);
        }
Example #8
0
        private List <Entity> LoadGeocodeLists()
        {
            var result = new List <Entity>();

            foreach (var entry in GlobalData.Provinces)
            {
                if (GeocodeHelper.IsBaseGeocode(BaseGeocode, entry.geocode))
                {
                    var entities           = GlobalData.GetGeocodeList(entry.geocode);
                    var allEntities        = entities.FlatList();
                    var allFittingEntities = allEntities.Where(x => _entityTypes.Contains(x.type));
                    result.AddRange(allFittingEntities);
                }
            }
            return(result);
        }
Example #9
0
        internal void AddTambonInThesabanToAmphoe(Entity tambon, Entity thesaban)
        {
            var allSubEntities = entity.SelectMany(x => x.entity).ToList();
            var mainTambon     = allSubEntities.SingleOrDefault(x => (GeocodeHelper.IsSameGeocode(x.geocode, tambon.geocode, false)) & (x.type == tambon.type));
            var mainAmphoe     = entity.FirstOrDefault(x => (x.geocode == tambon.geocode / 100));

            if (mainTambon == null)
            {
                if (mainAmphoe != null)
                {
                    mainTambon = XmlManager.MakeClone <Entity>(tambon);
                    mainAmphoe.entity.Add(mainTambon);
                }
            }
            else
            {
                if (mainTambon.population.Any())
                {
                    mainTambon.population.First().data.AddRange(tambon.population.First().data);
                }
                else
                {
                    mainTambon.population.Add(tambon.population.First());
                }
            }
            if (mainAmphoe != null)
            {
                var population = tambon.population.First();
                foreach (var dataPoint in population.data)
                {
                    var amphoePopulation = mainAmphoe.population.FirstOrDefault();
                    if (amphoePopulation == null)
                    {
                        amphoePopulation = new PopulationData();
                        amphoePopulation.referencedate          = population.referencedate;
                        amphoePopulation.referencedateSpecified = population.referencedateSpecified;
                        amphoePopulation.source = population.source;
                        amphoePopulation.year   = population.year;
                        mainAmphoe.population.Add(amphoePopulation);
                    }
                    amphoePopulation.AddDataPoint(dataPoint);
                }
            }
        }
 /// <summary>
 /// Synchronizes the calculated data with the global geocode list.
 /// </summary>
 private void GetGeocodes()
 {
     if (Data != null)
     {
         var geocodes = GlobalData.GetGeocodeList(Data.geocode);
         // _invalidGeocodes = geocodes.InvalidGeocodeEntries();
         foreach (var amphoe in geocodes.entity.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe)))
         {
             if (!Data.entity.Any(x => GeocodeHelper.IsSameGeocode(x.geocode, amphoe.geocode, false)))
             {
                 // make sure all Amphoe will  be in the result list, in case of a Amphoe which has only Thesaban it will be missing in the DOPA data
                 var newAmphoe = new Entity();
                 newAmphoe.population.Add(CreateEmptyPopulationEntry());
                 newAmphoe.CopyBasicDataFrom(amphoe);
                 Data.entity.Add(newAmphoe);
             }
         }
         Data.SynchronizeGeocodes(geocodes);
     }
 }
Example #11
0
        private List <String> NormalizeNameList(IEnumerable <Entity> entities)
        {
            var result = new List <String>();

            foreach (var entry in entities)
            {
                var name = entry.name;
                if (entry.type == EntityType.Muban)
                {
                    if (!String.IsNullOrEmpty(entry.name))
                    {
                        name = name.StripBanOrChumchon();
                    }
                }
                if ((!entry.IsObsolete) & (GeocodeHelper.IsBaseGeocode(BaseGeocode, entry.geocode)))
                {
                    result.Add(name);
                }
            }
            return(result);
        }
Example #12
0
        internal void SynchronizeGeocodes(Entity geocodeSource)
        {
            var missedEntities = new List <Entity>();

            if (geocodeSource != null)
            {
                var sourceFlat = geocodeSource.FlatList();
                foreach (var entity in this.FlatList())
                {
                    var source = sourceFlat.FirstOrDefault(x => GeocodeHelper.IsSameGeocode(x.geocode, entity.geocode, false));
                    if (source == null)
                    {
                        missedEntities.Add(entity);
                    }
                    else
                    {
                        entity.CopyBasicDataFrom(source);
                    }
                }
            }
        }
Example #13
0
        public static void LoadPopulationData(PopulationDataSourceType source, Int16 year)
        {
            if (!GlobalData.CountryEntity.population.Any(x => x.Year == year && x.source == source))
            {
                String filename = String.Empty;
                switch (source)
                {
                case PopulationDataSourceType.Census:
                    filename = BaseXMLDirectory + "\\population\\census{0}.xml";
                    break;

                case PopulationDataSourceType.DOPA:
                    filename = BaseXMLDirectory + "\\population\\DOPA{0}.xml";
                    break;
                }
                filename = String.Format(CultureInfo.InvariantCulture, filename, year);
                if (!string.IsNullOrWhiteSpace(filename))
                {
                    LoadPopulationData(filename);
                }
            }

            var geocodeToRecalculate = new List <UInt32>();
            var allEntities          = GlobalData.CompleteGeocodeList().FlatList();

            foreach (var item in allEntities.Where(x =>
                                                   x.newgeocode.Any() &&
                                                   x.population.Any(y => y.Year == year && y.source == source)).ToList())
            {
                foreach (var newGeocode in item.newgeocode)
                {
                    var newItem = allEntities.FirstOrDefault(x => x.geocode == newGeocode);
                    if (newItem != null)
                    {
                        if (!newItem.IsObsolete)
                        {
                            newItem.population.Add(item.population.First(y => y.Year == year && y.source == source));
                            geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(newItem.geocode));
                        }
                    }
                }
                geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(item.geocode));
            }
            foreach (var recalculate in geocodeToRecalculate.Distinct())
            {
                var entityToRecalculate = allEntities.FirstOrDefault(x => x.geocode == recalculate);
                if (entityToRecalculate != null)
                {
                    var data = entityToRecalculate.population.FirstOrDefault(y => y.Year == year && y.source == source);
                    if (data != null)
                    {
                        data.data.Clear();
                        foreach (var subentity in entityToRecalculate.entity.Where(x => !x.IsObsolete))
                        {
                            var subData = subentity.population.FirstOrDefault(y => y.Year == year && y.source == source);
                            if (subData != null)
                            {
                                foreach (var subDataPoint in subData.data)
                                {
                                    data.AddDataPoint(subDataPoint);
                                }
                            }
                        }
                        data.CalculateTotal();
                    }
                }
            }
        }
Example #14
0
        public static void LoadPopulationData(PopulationDataSourceType source, Int16 year)
        {
            var populationData = LoadPopulationDataUnprocessed(source, year);

            if (populationData != null)
            {
                MergePopulationData(populationData);
            }

            var geocodeToRecalculate = new List <UInt32>();
            var allEntities          = GlobalData.CompleteGeocodeList().FlatList();

            foreach (var item in allEntities.Where(x =>
                                                   x.newgeocode.Any() &&
                                                   x.population.Any(y => y.Year == year && y.source == source)).ToList())
            {
                foreach (var newGeocode in item.newgeocode)
                {
                    var newItem = allEntities.FirstOrDefault(x => x.geocode == newGeocode);
                    if (newItem != null)
                    {
                        if (!newItem.IsObsolete)
                        {
                            newItem.population.Add(item.population.First(y => y.Year == year && y.source == source));
                            geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(newItem.geocode));
                        }
                    }
                }
                geocodeToRecalculate.AddRange(GeocodeHelper.ParentGeocodes(item.geocode));
            }
            if (source == PopulationDataSourceType.Census)
            {
                // For DOPA need to be done with CalculateLocalGovernmentPopulation
                Entity.FillExplicitLocalGovernmentPopulation(allEntities.Where(x => x.type.IsLocalGovernment()).ToList(), allEntities, source, year);
            }

            foreach (var recalculate in geocodeToRecalculate.Distinct())
            {
                var entityToRecalculate = allEntities.FirstOrDefault(x => x.geocode == recalculate);
                if (entityToRecalculate != null)
                {
                    var data = entityToRecalculate.population.FirstOrDefault(y => y.Year == year && y.source == source);
                    if (data != null)
                    {
                        data.data.Clear();
                        foreach (var subentity in entityToRecalculate.entity.Where(x => !x.IsObsolete))
                        {
                            var subData = subentity.population.FirstOrDefault(y => y.Year == year && y.source == source);
                            if (subData != null)
                            {
                                foreach (var subDataPoint in subData.data)
                                {
                                    data.AddDataPoint(subDataPoint);
                                }
                            }
                        }
                        data.CalculateTotal();
                    }
                }
            }
        }
Example #15
0
        /// <summary>
        /// Creates an Wikipedia article stub for a Tambon.
        /// </summary>
        /// <param name="entity">Entity to export.</param>
        /// <param name="language">Language to use.</param>
        /// <returns>Wikipedia text.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="entity"/> is <c>null</c>.</exception>
        /// <exception cref="ArgumentException"><paramref name="entity"/> has wrong <see cref="Entity.type"/>.</exception>
        /// <exception cref="NotImplementedException"><paramref name="language"/> is not yet implemented.</exception>
        public String TambonArticle(Entity entity, Language language)
        {
            if (entity == null)
            {
                throw new ArgumentNullException("entity");
            }

            if (!entity.type.IsCompatibleEntityType(EntityType.Tambon))
            {
                throw new ArgumentException(String.Format(CultureInfo.InvariantCulture, "Entity type {0} not compatible with Tambon", entity.type));
            }
            if (language != Language.English)
            {
                throw new NotImplementedException(String.Format(CultureInfo.InvariantCulture, "Unsupported language {0}", language));
            }

            var englishCulture  = new CultureInfo("en-US");
            var province        = _country.entity.FirstOrDefault(x => x.geocode == GeocodeHelper.ProvinceCode(entity.geocode));
            var amphoe          = province.entity.FirstOrDefault(x => GeocodeHelper.IsBaseGeocode(x.geocode, entity.geocode));
            var muban           = entity.entity.Where(x => x.type == EntityType.Muban && !x.IsObsolete);
            var lao             = _localGovernments.Where(x => x.LocalGovernmentAreaCoverage.Any(y => y.geocode == entity.geocode));
            var parentTambon    = new List <Entity>();
            var creationHistory = entity.history.Items.FirstOrDefault(x => x is HistoryCreate) as HistoryCreate;

            if (creationHistory != null)
            {
                var allTambon = _country.FlatList().Where(x => x.type.IsCompatibleEntityType(EntityType.Tambon));
                parentTambon.AddRange(creationHistory.splitfrom.Select(x => allTambon.FirstOrDefault(y => x == y.geocode)));
            }
            var tempList = new List <Entity>()
            {
                province, amphoe
            };

            tempList.AddRange(muban);
            tempList.AddRange(lao);
            tempList.AddRange(parentTambon);
            var   links          = RetrieveWikpediaLinks(tempList, language);
            var   populationData = entity.population.FirstOrDefault(x => x.Year == PopulationReferenceYear && x.source == PopulationDataSourceType.DOPA);
            Int32 population     = 0;

            if (populationData != null)
            {
                population = populationData.TotalPopulation.total;
            }

            StringBuilder builder = new StringBuilder();

            builder.AppendLine("{{Infobox settlement");
            builder.AppendLine("<!--See the Table at Infobox Settlement for all fields and descriptions of usage-->");
            builder.AppendLine("<!-- Basic info  ---------------->");
            builder.AppendFormat(englishCulture, "|official_name          = {0}", entity.english);
            builder.AppendLine();
            builder.AppendFormat(englishCulture, "|native_name            = {0}", entity.name);
            builder.AppendLine();
            builder.AppendLine("|settlement_type        = [[Tambon]]");
            builder.AppendLine("|motto                  =");
            builder.AppendLine("<!-- Location ------------------>");
            builder.AppendLine("|subdivision_type      = Country ");
            builder.AppendLine("|subdivision_name      ={{flag|Thailand}} ");
            builder.AppendLine("|subdivision_type2      = [[Provinces of Thailand|Province]]");
            builder.AppendFormat(englishCulture, "|subdivision_name2      = {0}", WikiLink(links[province], province.english));
            builder.AppendLine();
            builder.AppendLine("|subdivision_type3      = [[Amphoe]]");
            builder.AppendFormat(englishCulture, "|subdivision_name3      = {0}", WikiLink(links[amphoe], amphoe.english));
            builder.AppendLine();
            builder.AppendLine("<!-- Politics ----------------->");
            builder.AppendLine("|established_title      = ");
            builder.AppendLine("|established_date       = ");
            builder.AppendLine("<!-- Area    --------------------->");
            builder.AppendLine("|area_total_km2           = ");
            builder.AppendLine("|area_water_km2           =");
            builder.AppendLine("<!-- Population   ----------------------->");
            builder.AppendFormat(englishCulture, "|population_as_of               = {0}", PopulationReferenceYear);
            builder.AppendLine();
            builder.AppendLine("|population_footnotes           = ");
            builder.AppendLine("|population_note                = ");
            builder.AppendFormat(englishCulture, "|population_total               = {0:#,###,###}", population);
            builder.AppendLine();
            builder.AppendLine("|population_density_km2         = ");
            builder.AppendLine("<!-- General information  --------------->");
            builder.AppendLine("|timezone               = [[Thailand Standard Time|TST]]");
            builder.AppendLine("|utc_offset             = +7");
            builder.AppendLine("|latd= |latm= |lats= |latNS=N");
            builder.AppendLine("|longd= |longm= |longs= |longEW=E");
            builder.AppendLine("|elevation_footnotes    =  ");
            builder.AppendLine("|elevation_m            = ");
            builder.AppendLine("<!-- Area/postal codes & others -------->");
            builder.AppendLine("|postal_code_type       = Postal code");
            builder.AppendLine("|postal_code            = {{#property:P281}}");
            builder.AppendLine("|area_code              = ");
            builder.AppendLine("|blank_name             = [[TIS 1099]]");
            builder.AppendLine("|blank_info             = {{#property:P1067}}");
            builder.AppendLine("|website                = ");
            builder.AppendLine("|footnotes              = ");
            builder.AppendLine("}}");
            builder.AppendLine();

            String nativeName;

            if (!String.IsNullOrEmpty(entity.ipa))
            {
                nativeName = String.Format(englishCulture, "{{{{lang-th|{0}}}}}; {{{{IPA-th|{1}|IPA}}}}", entity.name, entity.ipa);
            }
            else
            {
                nativeName = String.Format(englishCulture, "{{{{lang-th|{0}}}}}", entity.name);
            }

            builder.AppendFormat(englishCulture,
                                 "'''{0}''' ({1}) is a ''[[tambon]]'' (subdistrict) of {2}, in {3}, [[Thailand]]. In {4} it had a total population of {5:#,###,###} people.{6}",
                                 entity.english,
                                 nativeName,
                                 WikiLink(links[amphoe], amphoe.english + " District"),
                                 WikiLink(links[province], province.english + " Province"),
                                 PopulationReferenceYear,
                                 population,
                                 PopulationDataDownloader.WikipediaReference(GeocodeHelper.ProvinceCode(entity.geocode), PopulationReferenceYear, language)
                                 );
            builder.AppendLine();
            builder.AppendLine();

            if (creationHistory != null)
            {
                builder.AppendLine("==History==");

                var parents = String.Join(", ", parentTambon.Select(x => links.Keys.Contains(x) ? WikiLink(links[x], x.english) : x.english));
                if (!parentTambon.Any())
                {
                    builder.AppendFormat(englishCulture, "The subdistrict was created effective {0:MMMM d, yyyy}.", creationHistory.effective);
                }
                else if (creationHistory.subdivisions > 0)
                {
                    builder.AppendFormat(englishCulture, "The subdistrict was created effective {0:MMMM d, yyyy} by splitting off {1} administrative villages from {2}.", creationHistory.effective, creationHistory.subdivisions, parents);
                }
                else
                {
                    builder.AppendFormat(englishCulture, "The subdistrict was created effective {0:MMMM d, yyyy} by splitting off from {1}.", creationHistory.effective, parents);
                }
                var gazetteRef = creationHistory.Items.FirstOrDefault(x => x is GazetteRelated) as GazetteRelated;
                if (gazetteRef != null)
                {
                    var gazette = GlobalData.AllGazetteAnnouncements.FindAnnouncement(gazetteRef);
                    if (gazette != null)
                    {
                        builder.AppendFormat("<ref>{0}</ref>", gazette.WikipediaReference(language));
                    }
                    builder.AppendLine();
                }
            }

            builder.AppendLine("==Administration==");
            builder.AppendLine();
            builder.AppendLine("===Central administration===");
            if (muban.Any())
            {
                builder.AppendFormat(englishCulture, "The ''tambon'' is subdivided into {0} administrative villages (''[[muban]]'').", muban.Count());
                builder.AppendLine();
                builder.AppendLine("{| class=\"wikitable sortable\"");
                builder.AppendLine("! No.");
                builder.AppendLine("! Name");
                builder.AppendLine("! Thai");
                foreach (var mu in muban)
                {
                    builder.AppendLine("|-");
                    var muEnglish = mu.english;
                    if (links.Keys.Contains(mu))
                    {
                        muEnglish = WikiLink(links[mu], mu.english);
                    }
                    var muNumber = mu.geocode % 100;
                    if (muNumber < 10)
                    {
                        builder.AppendFormat(englishCulture, "||{{{{0}}}}{0}.||{1}||{2}", muNumber, muEnglish, mu.name);
                    }
                    else
                    {
                        builder.AppendFormat(englishCulture, "||{0}.||{1}||{2}", muNumber, mu.english, mu.name);
                    }
                    builder.AppendLine();
                }
                builder.AppendLine("|}");
                builder.AppendLine();
            }
            else
            {
                builder.AppendLine("The ''tambon'' has no administrative villages (''[[muban]]'').");
                builder.AppendLine();
            }
            if (lao.Any())
            {
                var enWikipediaLink = new Dictionary <EntityType, String>()
                {
                    { EntityType.ThesabanNakhon, "city (''[[Thesaban#City municipality|Thesaban Nakhon]]'')" },
                    { EntityType.ThesabanMueang, "town (''[[Thesaban#Town municipality|Thesaban Mueang]]'')" },
                    { EntityType.ThesabanTambon, "subdistrict municipality (''[[Thesaban#Subdistrict municipality|Thesaban Tambon]]'')" },
                    { EntityType.TAO, "[[Subdistrict administrative organization|subdistrict administrative organization (SAO)]]" },
                };

                builder.AppendLine("===Local administration===");
                var laoTupel = new List <Tuple <String, String, String> >();
                foreach (var laoEntity in lao)
                {
                    var laoEnglish = laoEntity.english;
                    if (links.Keys.Contains(laoEntity))
                    {
                        laoEnglish = WikiLink(links[laoEntity], laoEnglish);
                    }
                    laoTupel.Add(new Tuple <String, String, String>(enWikipediaLink[laoEntity.type], laoEnglish, laoEntity.FullName));
                }

                if (lao.Count() == 1)
                {
                    var firstLao = laoTupel.First();

                    builder.AppendFormat(englishCulture, "The whole area of the subdistrict is covered by the {0} {1} ({2}).", firstLao.Item1, firstLao.Item2, firstLao.Item3);
                    builder.AppendLine();
                }
                else
                {
                    builder.AppendFormat(englishCulture, "The area of the subdistrict is shared by {0} local governments.", lao.Count());
                    builder.AppendLine();
                    foreach (var tupel in laoTupel)
                    {
                        builder.AppendFormat(englishCulture, "*the {0} {1} ({2})", tupel.Item1, tupel.Item2, tupel.Item3);
                        builder.AppendLine();
                    }
                }
                builder.AppendLine();
            }

            builder.AppendLine("==References==");
            builder.AppendLine("{{reflist}}");
            builder.AppendLine();
            builder.AppendLine("==External links==");
            builder.AppendFormat(CultureInfo.InvariantCulture, "*[http://www.thaitambon.com/tambon/{0} Thaitambon.com on {1}]", entity.geocode, entity.english);
            builder.AppendLine();
            // {{coord|19.0625|N|98.9396|E|source:wikidata-and-enwiki-cat-tree_region:TH|display=title}}
            builder.AppendLine();

            builder.AppendFormat(CultureInfo.InvariantCulture, "[[Category:Tambon of {0} Province]]", province.english);
            builder.AppendLine();
            builder.AppendFormat(CultureInfo.InvariantCulture, "[[Category:Populated places in {0} Province]]", province.english);
            builder.AppendLine();
            builder.AppendLine();
            builder.AppendFormat(CultureInfo.InvariantCulture, "{{{{{0}-geo-stub}}}}", province.english.ToCamelCase());

            return(builder.ToString());
        }
Example #16
0
        /// <summary>
        /// Creates the administration section for German Wikipedia.
        /// </summary>
        /// <param name="entity">Entity to export.</param>
        /// <returns>German Wikipedia text of administration section.</returns>
        private String AmphoeToWikipediaGerman(Entity entity)
        {
            var numberStrings = new Dictionary <Int32, String>()
            {
                { 1, "eine" },
                { 2, "zwei" },
                { 3, "drei" },
                { 4, "vier" },
                { 5, "fünf" },
                { 6, "sechs" },
                { 7, "sieben" },
                { 8, "acht" },
                { 9, "neun" },
                { 10, "zehn" },
                { 11, "elf" },
                { 12, "zwölf" },
            };
            var wikipediaLink = new Dictionary <EntityType, String>()
            {
                { EntityType.ThesabanNakhon, "[[Thesaban#Großstadt|Thesaban Nakhon]]" },
                { EntityType.ThesabanMueang, "[[Thesaban#Stadt|Thesaban Mueang]]" },
                { EntityType.ThesabanTambon, "[[Thesaban#Kleinstadt|Thesaban Tambon]]" },
                { EntityType.TAO, "[[Verwaltungsgliederung Thailands#Tambon-Verwaltungsorganisationen|Tambon-Verwaltungsorganisationen]]" },
            };

            var amphoeData    = CalculateAmphoeData(entity, Language.German);
            var germanCulture = new CultureInfo("de-DE");

            String headerBangkok     = "== Verwaltung ==" + Environment.NewLine;
            String textBangkok       = "Der Bezirk {0} ist in {1} ''[[Khwaeng]]'' („Unterbezirke“) eingeteilt." + Environment.NewLine + Environment.NewLine;
            String headerAmphoe      = "== Verwaltung ==" + Environment.NewLine + "=== Provinzverwaltung ===" + Environment.NewLine;
            String textAmphoe        = "Der Landkreis {0} ist in {1} ''[[Tambon]]'' („Unterbezirke“ oder „Gemeinden“) eingeteilt, die sich weiter in {2} ''[[Muban]]'' („Dörfer“) unterteilen." + Environment.NewLine + Environment.NewLine;
            String textAmphoeSingle  = "Der Landkreis {0} ist in genau einen ''[[Tambon]]'' („Unterbezirk“ oder „Gemeinde“) eingeteilt, der sich weiter in {2} ''[[Muban]]'' („Dörfer“) unterteilt." + Environment.NewLine + Environment.NewLine;
            String tableHeaderAmphoe =
                "{{| class=\"wikitable\"" + Environment.NewLine +
                "! Nr." + Environment.NewLine +
                "! Name" + Environment.NewLine +
                "! Thai" + Environment.NewLine +
                "! Muban" + Environment.NewLine +
                "! Einw.{0}" + Environment.NewLine;
            String tableHeaderBangkok =
                "{{| class=\"wikitable\"" + Environment.NewLine +
                "! Nr." + Environment.NewLine +
                "! Name" + Environment.NewLine +
                "! Thai" + Environment.NewLine +
                "! Einw.{0}" + Environment.NewLine;
            String tableEntryAmphoe = "|-" + Environment.NewLine +
                                      "||{0}.||{1}||{{{{lang|th|{2}}}}}||{3}||{4}" + Environment.NewLine;
            String tableEntryBangkok = "|-" + Environment.NewLine +
                                       "||{0}.||{1}||{{{{lang|th|{2}}}}}||{4}" + Environment.NewLine;
            String tableFooter = "|}" + Environment.NewLine;

            String headerLocal             = "=== Lokalverwaltung ===" + Environment.NewLine;
            String textLocalSingular       = "Es gibt eine Kommune mit „{0}“-Status ''({1})'' im Landkreis:" + Environment.NewLine;
            String textLocalPlural         = "Es gibt {0} Kommunen mit „{1}“-Status ''({2})'' im Landkreis:" + Environment.NewLine;
            String taoWithThesaban         = "Außerdem gibt es {0} „[[Verwaltungsgliederung Thailands#Tambon-Verwaltungsorganisationen|Tambon-Verwaltungsorganisationen]]“ ({{{{lang|th|องค์การบริหารส่วนตำบล}}}} – Tambon Administrative Organizations, TAO)" + Environment.NewLine;
            String taoWithoutThesaban      = "Im Landkreis gibt es {0} „[[Verwaltungsgliederung Thailands#Tambon-Verwaltungsorganisationen|Tambon-Verwaltungsorganisationen]]“ ({{{{lang|th|องค์การบริหารส่วนตำบล}}}} – Tambon Administrative Organizations, TAO)" + Environment.NewLine;
            String entryLocal              = "* {0} (Thai: {{{{lang|th|{1}}}}})";
            String entryLocalCoverage      = " bestehend aus {0}.";
            String entryLocalCoverageTwo   = " bestehend aus {0} und {1}.";
            String tambonCompleteSingular  = "dem kompletten Tambon {0}";
            String tambonPartiallySingular = "Teilen des Tambon {0}";
            String tambonCompletePlural    = "den kompletten Tambon {0}";
            String tambonPartiallyPlural   = "den Teilen der Tambon {0}";

            CountAsString countAsString = delegate(Int32 count)
            {
                String countAsStringResult;
                if (!numberStrings.TryGetValue(count, out countAsStringResult))
                {
                    countAsStringResult = count.ToString(germanCulture);
                }
                return(countAsStringResult);
            };

            var result = String.Empty;

            if (entity.type == EntityType.Khet)
            {
                result = headerBangkok +
                         String.Format(germanCulture, textBangkok, entity.english, countAsString(amphoeData.CentralAdministrationCountByEntity[EntityType.Khwaeng])) +
                         String.Format(germanCulture, tableHeaderBangkok, PopulationDataDownloader.WikipediaReference(GeocodeHelper.ProvinceCode(entity.geocode), PopulationReferenceYear, Language.German));
            }
            else if (amphoeData.CentralAdministrationCountByEntity[EntityType.Tambon] == 1)
            {
                result = headerAmphoe +
                         String.Format(germanCulture, textAmphoeSingle, entity.english, countAsString(amphoeData.CentralAdministrationCountByEntity[EntityType.Tambon]), countAsString(amphoeData.CentralAdministrationCountByEntity[EntityType.Muban])) +
                         String.Format(germanCulture, tableHeaderAmphoe, PopulationDataDownloader.WikipediaReference(GeocodeHelper.ProvinceCode(entity.geocode), PopulationReferenceYear, Language.German));
            }
            else
            {
                result = headerAmphoe +
                         String.Format(germanCulture, textAmphoe, entity.english, countAsString(amphoeData.CentralAdministrationCountByEntity[EntityType.Tambon]), countAsString(amphoeData.CentralAdministrationCountByEntity[EntityType.Muban])) +
                         String.Format(germanCulture, tableHeaderAmphoe, PopulationDataDownloader.WikipediaReference(GeocodeHelper.ProvinceCode(entity.geocode), PopulationReferenceYear, Language.German));
            }

            foreach (var tambon in amphoeData.AllTambon)
            {
                if (entity.type == EntityType.Khet)
                {
                    result += WikipediaTambonTableEntry(tambon, amphoeData, tableEntryBangkok, germanCulture);
                }
                else
                {
                    result += WikipediaTambonTableEntry(tambon, amphoeData, tableEntryAmphoe, germanCulture);
                }
            }
            result += tableFooter + Environment.NewLine;

            if (amphoeData.LocalAdministrationCountByEntity.Any())
            {
                result += headerLocal;
                var check = new List <EntityType>()
                {
                    EntityType.ThesabanNakhon,
                    EntityType.ThesabanMueang,
                    EntityType.ThesabanTambon,
                    EntityType.TAO,
                };
                foreach (var entityType in check)
                {
                    Int32 count = 0;
                    if (amphoeData.LocalAdministrationCountByEntity.TryGetValue(entityType, out count))
                    {
                        if (entityType == EntityType.TAO)
                        {
                            if (amphoeData.LocalAdministrationCountByEntity.Keys.Count == 1)
                            {
                                result += String.Format(germanCulture, taoWithoutThesaban, countAsString(count));
                            }
                            else
                            {
                                result += String.Format(germanCulture, taoWithThesaban, countAsString(count));
                            }
                        }
                        else
                        {
                            if (count == 1)
                            {
                                result += String.Format(germanCulture, textLocalSingular, entityType.Translate(Language.German), wikipediaLink[entityType]);
                            }
                            else
                            {
                                result += String.Format(germanCulture, textLocalPlural, countAsString(count), entityType.Translate(Language.German), wikipediaLink[entityType]);
                            }
                        }
                        foreach (var localEntity in amphoeData.LocalAdministrations.Where(x => x.type == entityType))
                        {
                            result += WikipediaLocalAdministrationTableEntry(
                                localEntity,
                                amphoeData,
                                entryLocal,
                                tambonCompleteSingular,
                                tambonCompletePlural,
                                tambonPartiallySingular,
                                tambonPartiallyPlural,
                                entryLocalCoverage,
                                entryLocalCoverageTwo,
                                germanCulture);
                        }
                        result += Environment.NewLine;
                    }
                }
            }

            return(result);
        }
Example #17
0
        /// <summary>
        /// Creates the administration section for English Wikipedia.
        /// </summary>
        /// <param name="entity">Entity to export.</param>
        /// <returns>English Wikipedia text of administration section.</returns>
        private String AmphoeToWikipediaEnglish(Entity entity)
        {
            var englishCulture = new CultureInfo("en-US");
            var amphoeData     = CalculateAmphoeData(entity, Language.English);

            String headerBangkok          = "== Administration ==" + Environment.NewLine;
            String textBangkok            = "The district {0} is subdivided into {1} subdistricts (''[[Khwaeng]]'')." + Environment.NewLine + Environment.NewLine;
            String headerAmphoe           = "== Administration ==" + Environment.NewLine + "=== Central administration ===" + Environment.NewLine;
            String textAmphoe             = "The district {0} is subdivided into {1} subdistricts (''[[Tambon]]''), which are further subdivided into {2} administrative villages (''[[Muban]]'')." + Environment.NewLine + Environment.NewLine;
            String textAmphoeSingleTambon = "The district {0} is subdivided into {1} subdistrict (''[[Tambon]]''), which is further subdivided into {2} administrative villages (''[[Muban]]'')." + Environment.NewLine + Environment.NewLine;
            String tableHeaderAmphoe      =
                "{{| class=\"wikitable sortable\"" + Environment.NewLine +
                "! No." + Environment.NewLine +
                "! Name" + Environment.NewLine +
                "! Thai" + Environment.NewLine +
                "! Villages" + Environment.NewLine +
                "! [[Population|Pop.]]{0}" + Environment.NewLine;
            String tableHeaderBangkok =
                "{{| class=\"wikitable sortable\"" + Environment.NewLine +
                "! No." + Environment.NewLine +
                "! Name" + Environment.NewLine +
                "! Thai" + Environment.NewLine +
                "! [[Population|Pop.]]{0}" + Environment.NewLine;
            String tableEntryAmphoe = "|-" + Environment.NewLine +
                                      "||{0}.||{1}||{{{{lang|th|{2}}}}}||{3}||{4}" + Environment.NewLine;
            String tableEntryBangkok = "|-" + Environment.NewLine +
                                       "||{0}.||{1}||{{{{lang|th|{2}}}}}||{3}" + Environment.NewLine;
            String tableFooter = "|}" + Environment.NewLine;

            String headerLocal             = "=== Local administration ===" + Environment.NewLine;
            String textLocalSingular       = "There is one {0} in the district:" + Environment.NewLine;
            String textLocalPlural         = "There are {0} {1} in the district:" + Environment.NewLine;
            String entryLocal              = "* {0} (Thai: {{{{lang|th|{1}}}}})";
            String entryLocalCoverage      = " consisting of {0}.";
            String entryLocalCoverageTwo   = " consisting of {0} and {1}.";
            String tambonCompleteSingular  = "the complete subdistrict {0}";
            String tambonPartiallySingular = "parts of the subdistrict {0}";
            String tambonCompletePlural    = "the complete subdistrict {0}";
            String tambonPartiallyPlural   = "parts of the subdistricts {0}";

            var enWikipediaLink = new Dictionary <EntityType, String>()
            {
                { EntityType.ThesabanNakhon, "city (''[[Thesaban#City municipality|Thesaban Nakhon]]'')" },
                { EntityType.ThesabanMueang, "town (''[[Thesaban#Town municipality|Thesaban Mueang]]'')" },
                { EntityType.ThesabanTambon, "subdistrict municipality (''[[Thesaban#Subdistrict municipality|Thesaban Tambon]]'')" },
                { EntityType.TAO, "[[Subdistrict administrative organization|subdistrict administrative organization (SAO)]]" },
            };
            var enWikipediaLinkPlural = new Dictionary <EntityType, String>()
            {
                { EntityType.ThesabanNakhon, "cities (''[[Thesaban#City municipality|Thesaban Nakhon]]'')" },
                { EntityType.ThesabanMueang, "towns (''[[Thesaban#Town municipality|Thesaban Mueang]]'')" },
                { EntityType.ThesabanTambon, "subdistrict municipalities (''[[Thesaban#Subdistrict municipality|Thesaban Tambon]]'')" },
                { EntityType.TAO, "[[Subdistrict administrative organization|subdistrict administrative organizations (SAO)]]" },
            };

            var result = String.Empty;

            if (entity.type == EntityType.Khet)
            {
                result = headerBangkok +
                         String.Format(englishCulture, textBangkok, entity.english, amphoeData.CentralAdministrationCountByEntity[EntityType.Khwaeng]) +
                         String.Format(englishCulture, tableHeaderBangkok, PopulationDataDownloader.WikipediaReference(GeocodeHelper.ProvinceCode(entity.geocode), PopulationReferenceYear, Language.English));
            }
            else if (amphoeData.CentralAdministrationCountByEntity[EntityType.Tambon] == 1)
            {
                result = headerAmphoe +
                         String.Format(englishCulture, textAmphoeSingleTambon, entity.english, amphoeData.CentralAdministrationCountByEntity[EntityType.Tambon], amphoeData.CentralAdministrationCountByEntity[EntityType.Muban]) +
                         String.Format(englishCulture, tableHeaderAmphoe, PopulationDataDownloader.WikipediaReference(GeocodeHelper.ProvinceCode(entity.geocode), PopulationReferenceYear, Language.English));
            }
            else
            {
                result = headerAmphoe +
                         String.Format(englishCulture, textAmphoe, entity.english, amphoeData.CentralAdministrationCountByEntity[EntityType.Tambon], amphoeData.CentralAdministrationCountByEntity[EntityType.Muban]) +
                         String.Format(englishCulture, tableHeaderAmphoe, PopulationDataDownloader.WikipediaReference(GeocodeHelper.ProvinceCode(entity.geocode), PopulationReferenceYear, Language.English));
            }
            foreach (var tambon in amphoeData.AllTambon)
            {
                if (entity.type == EntityType.Khet)
                {
                    result += WikipediaTambonTableEntry(tambon, amphoeData, tableEntryBangkok, englishCulture);
                }
                else
                {
                    result += WikipediaTambonTableEntry(tambon, amphoeData, tableEntryAmphoe, englishCulture);
                }
            }
            result += tableFooter + Environment.NewLine;

            if (amphoeData.LocalAdministrationCountByEntity.Any())
            {
                result += headerLocal;
                var check = new List <EntityType>()
                {
                    EntityType.ThesabanNakhon,
                    EntityType.ThesabanMueang,
                    EntityType.ThesabanTambon,
                    EntityType.TAO,
                };
                foreach (var entityType in check)
                {
                    Int32 count = 0;
                    if (amphoeData.LocalAdministrationCountByEntity.TryGetValue(entityType, out count))
                    {
                        if (count == 1)
                        {
                            result += String.Format(englishCulture, textLocalSingular, enWikipediaLink[entityType]);
                        }
                        else
                        {
                            result += String.Format(englishCulture, textLocalPlural, count, enWikipediaLinkPlural[entityType]);
                        }
                        foreach (var localEntity in amphoeData.LocalAdministrations.Where(x => x.type == entityType))
                        {
                            result += WikipediaLocalAdministrationTableEntry(
                                localEntity,
                                amphoeData,
                                entryLocal,
                                tambonCompleteSingular,
                                tambonCompletePlural,
                                tambonPartiallySingular,
                                tambonPartiallyPlural,
                                entryLocalCoverage,
                                entryLocalCoverageTwo,
                                englishCulture);
                        }
                        result += Environment.NewLine;
                    }
                }
            }
            return(result);
        }