def set_adm_location(self): """ Set the Admin Location. Use external lists, as they are not linked. Try to match the Municipality first (actually a hamaynk), and if that doesn't work, the Province via its ISO code. """ com_dic = self.data_files["communities"] prov_dic = self.data_files["provinces"] adm_q = None adm_match = utils.get_item_from_dict_by_key( dict_name=com_dic, search_in="itemLabel", search_term=self.municipality) if len(adm_match) == 1: adm_q = adm_match[0] if adm_q is None and self.has_non_empty_attribute("prov_iso"): prov_match = utils.get_item_from_dict_by_key( dict_name=prov_dic, search_in="iso", search_term=self.prov_iso) if len(prov_match) == 1: adm_q = prov_match[0] if adm_q is not None: self.add_statement("located_adm", adm_q) else: self.add_to_report( "municipality", self.municipality, "located_adm")
def set_location(self): """ Set the Location. Use the linked Localidad if available, and if it's not linked, try and see if there's an article anyway. Compare against external list of settlements. """ loc_dic = self.data_files["settlements"] loc_q = None if self.has_non_empty_attribute("localidad"): loc_raw = self.localidad if utils.count_wikilinks(loc_raw) == 1: loc_try = utils.q_from_first_wikilink("es", loc_raw) loc_match = utils.get_item_from_dict_by_key( dict_name=loc_dic, search_term=loc_try, search_in="item") if len(loc_match) == 1: loc_q = loc_try else: loc_try = utils.q_from_wikipedia("es", loc_raw) loc_match = utils.get_item_from_dict_by_key( dict_name=loc_dic, search_term=loc_try, search_in="item") if len(loc_match) == 1: loc_q = loc_try if loc_q: self.add_statement("location", loc_q) else: self.add_to_report("localidad", self.localidad, "location")
def set_adm_location(self): """ Set administrative location. If possible, match district / municipality. Not wikilinked, and contain a mix of various types, so match against list of all administrative units. If that doesn't work, resort to okrug via iso. """ adm_q = None adm_dic = self.data_files["admin"] okr_dic = self.data_files["okruzi"] municip_try = utils.get_item_from_dict_by_key( dict_name=adm_dic, search_in="itemLabel", search_term=self.district) if len(municip_try) == 1: adm_q = municip_try[0] else: self.add_to_report("district", self.district, "located_adm") if not adm_q and self.has_non_empty_attribute("iso_okrug"): iso_try = utils.get_item_from_dict_by_key( dict_name=okr_dic, search_in="iso", search_term=self.iso_okrug) if len(iso_try) == 1: adm_q = iso_try[0] else: self.add_to_report("iso_okrug", self.iso_okrug, "located_adm") if adm_q: self.add_statement("located_adm", adm_q)
def set_adm_location(self): """ Set the Admin Location. Use the linked Municipality first, checking against external list. If failed, use the Region iso code, which is a bigger unit. """ adm_q = None municip_dic = self.data_files["municipalities"] region_dict = self.data_files["regions"] municip_q = utils.q_from_first_wikilink("es", self.comuna) if utils.get_item_from_dict_by_key(dict_name=municip_dic, search_term=municip_q, search_in="item"): adm_q = municip_q else: self.add_to_report("comuna", self.comuna, "located_adm") if adm_q is None: iso_match = utils.get_item_from_dict_by_key(dict_name=region_dict, search_term=self.ISO, search_in="iso") if len(iso_match) == 1: adm_q = iso_match[0] else: self.add_to_report("ISO", self.ISO, "located_adm") if adm_q: self.add_statement("located_adm", adm_q)
def set_from_dict_match(self, lookup_dict, dict_label, value_label, prop): """ Look up value in dict and add statement on unique match, else report. If the value is empty then no statement is added nor is anything reported. :param lookup_dict: list of dicts to do lookup in :param dict_label: value in dict to do matching on :param value_label: the label of the value we wish to match :prop: the label of the property for which a statement is added """ match_q = None if self.has_non_empty_attribute(value_label): value = getattr(self, value_label) matches = utils.get_item_from_dict_by_key(dict_name=lookup_dict, search_term=value, search_in=dict_label) if len(matches) == 1: match_q = matches[0] if match_q: self.add_statement(prop, match_q) else: self.add_to_report(value_label, value, prop)
def set_adm_location(self): """ Set the administrative location. First try to resolve the municipality, and if that doesn't work use the department which is a higher unit. """ match = None if self.has_non_empty_attribute("municipio"): match = utils.q_from_first_wikilink("es", self.municipio) if not match: self.add_to_report("municipio", self.municipio, "located_adm") if not match: dep_match = utils.get_item_from_dict_by_key( dict_name=self.data_files["departments"], search_term=self.iso, search_in="iso") if len(dep_match) == 1: match = dep_match[0] else: self.add_to_report("iso", self.iso, "located_adm") if match: self.add_statement("located_adm", match)
def set_adm_location(self): """ Set administrative location, or location. The 'municipality' field contains links pointing at both municipalities/districts and settlements. Try to first match actual administrative units, and if that doesn't work, settlements via mapping file. Settlements are added as 'location'. """ adm_q = None settlement_q = None adm_dic = self.data_files["admin"] settlement_dic = self.data_files["settlements"] if self.has_non_empty_attribute("municipality"): if utils.count_wikilinks(self.municipality) == 1: adm_try = utils.q_from_first_wikilink("ka", self.municipality) # ensure this is an administrative unit... if any(x['item'] == adm_try for x in adm_dic): adm_q = adm_try # alternatively a settlement elif any(x['item'] == adm_try for x in settlement_dic): settlement_q = adm_try else: adm_match = utils.get_item_from_dict_by_key( dict_name=adm_dic, search_term=self.municipality, search_in="itemLabel") if len(adm_match) == 1: adm_q = adm_match[0] else: settlement_match = utils.get_item_from_dict_by_key( dict_name=settlement_dic, search_term=self.municipality, search_in="itemLabel") if len(settlement_match) == 1: settlement_q = settlement_match[0] if adm_q: self.add_statement("located_adm", adm_q) if settlement_q: self.add_statement("location", settlement_q) else: self.add_to_report("municipality", self.municipality, "located_adm")
def set_adm_location(self): """Set Adm Location, using the iso of the region.""" reg_dic = self.data_files["regions"] iso = self.region_iso adm_match = utils.get_item_from_dict_by_key(dict_name=reg_dic, search_term=iso, search_in="iso") if len(adm_match) == 1: self.add_statement("located_adm", adm_match[0]) else: self.add_to_report("region_iso", self.region_iso, "located_adm")
def set_location(self): """Set Location if it's matched against valid settlements.""" if self.has_non_empty_attribute("place"): settl_dic = self.data_files["settlements"] s_match = utils.get_item_from_dict_by_key(dict_name=settl_dic, search_term=self.place, search_in="itemLabel") if len(s_match) == 1: self.add_statement("location", s_match[0]) else: self.add_to_report("place", self.place, "location")
def set_adm_location(self): """ Set administrative location. Since the mapping file covers all that's in the source data, there's not trying / reporting to do. """ municip_dict = self.data_files["_static"]["bosnia_adm"] municip_raw = self.municipality.strip() municip_match = utils.get_item_from_dict_by_key( dict_name=municip_dict, search_term=municip_raw, search_in="itemLabel") self.add_statement("located_adm", municip_match[0], refs=self.source)
def set_adm_location(self): """ Set the Admin Location. Try a linked Municipality first, then unlinked Municipality. If failed, use the Department iso code. """ adm_q = None municip_dic = self.data_files["municipalities"] dep_dic = self.data_files["departments"] municip_raw = self.municipio iso = self.departamento_iso if utils.count_wikilinks(municip_raw) == 1: adm_q = utils.q_from_first_wikilink("es", municip_raw) else: municip_match = utils.get_item_from_dict_by_key( dict_name=municip_dic, search_in="itemLabel", search_term=municip_raw) if len(municip_match) == 1: adm_q = municip_match[0] if adm_q is None: self.add_to_report("municipio", municip_raw, "located_adm") dep_match = utils.get_item_from_dict_by_key( dict_name=dep_dic, search_in="iso", search_term=iso) if len(dep_match) == 1: adm_q = dep_match[0] else: self.add_to_report("departamento_iso", iso, "located_adm") if adm_q is not None: self.add_statement("located_adm", adm_q)
def update_descriptions(self): adm_code = self.judetul_iso counties = self.data_files["counties"] county_item = utils.get_item_from_dict_by_key( dict_name=counties, search_term=adm_code, return_content_of="itemLabel", search_in="iso_code") if len(county_item) == 1: place_name = "{}, Romania".format(county_item[0]) else: place_name = "Romania" desc = "heritage site in {}".format(place_name) self.add_description("en", desc) self.add_disambiguator(str(self.cod))
def set_adm_location(self): brussel_region = "Q240" location = self.plaats municip_dict = self.data_files["municipalities"] if location: location_match = utils.get_item_from_dict_by_key( dict_name=municip_dict, search_term=location, search_in="itemLabel") if len(location_match) == 1: self.add_statement("located_adm", location_match[0]) else: self.add_to_report("plaats", self.plaats, "located_adm") else: self.add_statement("located_adm", brussel_region)
def set_admin_location(self): """ Set the admin location. Use the iso code of the gouvernorat for exact matching against list. """ adm_q = None iso = self.gouvernorat_iso admin_dic = self.data_files["admin"] admin_match = utils.get_item_from_dict_by_key(dict_name=admin_dic, search_term=iso, search_in="iso") if len(admin_match) == 1: adm_q = admin_match[0] self.add_statement("located_adm", adm_q) else: self.add_to_report("gouvernorat_iso", self.gouvernorat_iso, "located_adm")
def set_is(self): """ Set P31. Try to get a specific one via mapping file. Otherwise default of cultural property. """ default = self.mapping["default_is"]["item"] type_dict = self.data_files["_static"]["bosnia_types"] type_raw = self.object_type.strip() type_match = utils.get_item_from_dict_by_key(dict_name=type_dict, search_in="itemLabel", search_term=type_raw) if len(type_match) == 1: to_add = type_match[0] else: to_add = default self.add_statement("is", to_add, refs=self.source, if_empty=True)
def set_location(self): loc_q = None loc_dic = self.data_files["settlements"] if self.has_non_empty_attribute("plaats"): if utils.count_wikilinks(self.plaats) == 1: loc_q = utils.q_from_first_wikilink("nl", self.plaats) else: loc_match = utils.get_item_from_dict_by_key( dict_name=loc_dic, search_term=self.plaats, search_in="itemLabel", return_content_of="item") if len(loc_match) == 1: loc_q = loc_match[0] if loc_q: self.add_statement("location", loc_q) else: self.add_to_report("plaats", self.plaats, "location")
def set_location(self): """ Set the location. If present, use the wikilink, otherwise match value against list of settlements. """ loc_q = None loc_raw = self.site if utils.count_wikilinks(loc_raw) == 1: loc_q = utils.q_from_first_wikilink("fr", loc_raw) else: loc_dic = self.data_files["settlements"] loc_match = utils.get_item_from_dict_by_key(dict_name=loc_dic, search_term=loc_raw, search_in="itemLabel") if len(loc_match) == 1: loc_q = loc_match[0] if loc_q: self.add_statement("location", loc_q) else: self.add_to_report("site", self.site, "location")
def set_adm_location(self): """ Set the administrative location. Use the 'gemeinde' field to resolve municipality via wp link first, then if unable, region-iso code via mapping. """ adm_q = None municip_raw = self.gemeinde adm_q = utils.q_from_wikipedia("de", municip_raw) if adm_q is None: adm_dict = self.data_files["councils"] adm_iso_match = utils.get_item_from_dict_by_key(dict_name=adm_dict, search_term=self.region_iso, search_in="iso") if len(adm_iso_match) == 1: adm_q = adm_iso_match[0] if adm_q: self.add_statement("located_adm", adm_q) else: self.add_to_report("gemeinde", self.gemeinde, "located_adm")
def set_adm_location(self): """ Set the Admin Location. Use the linked Municipality first then fall back on state iso code, which is a bigger unit. """ adm_q = utils.q_from_first_wikilink("es", self.municipio) if adm_q is None: self.add_to_report("municipio", self.municipio, "located_adm") iso_match = utils.get_item_from_dict_by_key( dict_name=self.data_files["states"], search_term=self.estado_iso, search_in="iso") if len(iso_match) == 1: adm_q = iso_match[0] else: self.add_to_report("estado_iso", self.estado_iso, "located_adm") if adm_q: self.add_statement("located_adm", adm_q)
def set_location(self): """ Set the location property, P276, based on aadress. Despite its name, aadress does not always contain address-like data. That's why we don't use it for anything if it contains only text. It's only used if it contains 1 unique wikilink; sometimes it contains multiple instances of the same wikilink e.g. [[Võsivere|Võsivere küla]], Janise, [[Võsivere|Võsivere küla]], Mossi, [[Võsivere|Võsivere küla]], Rätsepa, [[Võsivere|Võsivere küla]], Tilmani, [[Võsivere|Võsivere küla]], Viskaja(5) As the content of one field. This will be counted as 1 wikilink. The WD item associated with the wikilink is then matched with a list of Estonian settlements, and if there's a match, it's added as 'location'. """ location_raw = self.aadress # very often not an address.... wikilinks = utils.get_unique_wikilinks(location_raw) if len(wikilinks) == 1: glossary = self.data_files["settlements"] target_name = wikilinks[0].title target_item = utils.get_item_from_dict_by_key( dict_name=glossary, search_term=target_name, search_in="itemLabel", ) if len(target_item) == 1: self.add_statement("location", target_item[0]) else: self.add_to_report("aadress", self.aadress, "location") else: self.add_to_report("aadress", self.aadress, "location")