private void UpdateDisambiguationList() { lbxNames.Items.Clear(); UInt32 geocode = 0; if (cbxProvinces.SelectedItem != null) { geocode = (cbxProvinces.SelectedItem as Entity).geocode; } if (cbxEntityType.SelectedItem != null) { var selectedType = (EntityType)cbxEntityType.SelectedItem; var currentEntities = allEntities.Where(x => x.type == selectedType).ToList(); var names = currentEntities.GroupBy(x => x.name).Where(y => y.Count() > 1).OrderByDescending(z => z.Count()).ThenBy(z => z.First().english); var currentNames = names.Select(x => new EntityList(x.OrderBy(y => y.geocode))); if (geocode != 0) { currentNames = currentNames.Where(x => x.Entities.Any(y => GeocodeHelper.IsBaseGeocode(geocode, y.geocode))); } foreach (var x in currentNames) { lbxNames.Items.Add(x); } } }
private void btnThaiWikipedia_Click(Object sender, EventArgs e) { var item = lbxNames.SelectedItem as EntityList; if (item != null) { var provinces = allEntities.Where(x => x.type.IsCompatibleEntityType(EntityType.Changwat)); var allAmphoe = allEntities.Where(x => x.type.IsCompatibleEntityType(EntityType.Amphoe)); var provincesUsed = item.Entities.SelectMany(x => provinces.Where(y => GeocodeHelper.IsBaseGeocode(y.geocode, x.geocode))).ToList(); var builder = new StringBuilder(); builder.AppendFormat("'''{0}''' สามารถหมายถึง", item.Entities.First().FullName); builder.AppendLine(); foreach (var subItem in item.Entities) { var province = provinces.FirstOrDefault(x => GeocodeHelper.IsBaseGeocode(x.geocode, subItem.geocode)); var amphoe = allAmphoe.FirstOrDefault(x => GeocodeHelper.IsBaseGeocode(x.geocode, subItem.geocode)); if (amphoe == null && subItem.type.IsLocalGovernment()) { var firstTambonCode = subItem.LocalGovernmentAreaCoverage.First().geocode; amphoe = allAmphoe.FirstOrDefault(x => GeocodeHelper.IsBaseGeocode(x.geocode, firstTambonCode)); } var parentInfo = String.Format("{0} {1}", amphoe.FullName, province.FullName); String disambiguatedName = String.Format("{0} ({1})", subItem.FullName, province.FullName); if (provincesUsed.Count(x => x == province) > 1) { disambiguatedName = String.Format("{0} ({1})", subItem.FullName, amphoe.FullName); } builder.AppendFormat("* [[{0}|{1}]] {2}", disambiguatedName, subItem.FullName, parentInfo); builder.AppendLine(); } builder.AppendLine(); builder.AppendLine("{{แก้กำกวม}}"); Clipboard.Clear(); Clipboard.SetText(builder.ToString()); } }
private void btnLaoList_Click(object sender, EventArgs e) { StringBuilder result = new StringBuilder(); var codes = new List <String>(); foreach (var province in allEntities.Where(x => x.type == EntityType.Changwat)) { result.AppendFormat(CultureInfo.InvariantCulture, "* '''{0}''': ", province.EnglishFullName); codes.Clear(); var localGovernment = allEntities.Where(x => !x.IsObsolete && x.type.IsLocalGovernment() && GeocodeHelper.IsBaseGeocode(province.geocode, x.geocode)); foreach (var lao in localGovernment) { if (lao.wiki != null && !String.IsNullOrEmpty(lao.wiki.wikidata)) { // codes.Add(String.Format("{{{{Q|{0}}}}}", tambon.wiki.wikidata.Remove(0, 1))); codes.Add(String.Format(CultureInfo.InvariantCulture, "[[{0}]]", lao.wiki.wikidata)); } else { codes.Add(lao.english); } } result.AppendLine(String.Join(" - ", codes)); } edtCollisions.Text = result.ToString(); }