def set_location(self): """ Set location based on 'by' column. If there's one wikilinked item, confirm that the corresponding WD item is of a type that's a subclass of 'human settlement', using query results downloaded by importer. If not wikilinked, check if there's a dawp article with the same name and do the same check. """ place_item = None if self.has_non_empty_attribute("by"): place = self.by if utils.count_wikilinks(place) == 1: place = utils.get_wikilinks(place)[0].title if utils.wp_page_exists("da", place): place_item = utils.q_from_wikipedia("da", place) if place_item: place_item_ids = utils.get_P31(place_item, self.repo) for p31_value in place_item_ids: if p31_value in self.data_files["settlement"]: self.add_statement("location", place_item) # there can be more than one P31, but after first positive # we can leave return
def set_architect(self): if self.has_non_empty_attribute("bouwdoor"): if utils.count_wikilinks(self.bouwdoor) == 1: arch_q = utils.q_from_first_wikilink("nl", self.bouwdoor) self.add_statement("architect", arch_q) else: self.add_to_report("bouwdoor", self.bouwdoor, "architect")
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_location(self): """Set location, using wikilinked value.""" if self.has_non_empty_attribute("ville"): if utils.count_wikilinks(self.ville) == 1: loc_q = utils.q_from_first_wikilink("fr", self.ville) self.add_statement("location", loc_q) else: self.add_to_report("ville", self.ville, "location")
def set_wd_item_via_name(self): """ Attempt to set wd item via name. Populates self.monument_article, the value then gets used in find_matching_wikidata() with extra precautionary logic. """ if utils.count_wikilinks(self.monumento) == 1: self.monument_article = utils.get_wikilinks( self.monumento)[0].title
def set_location(self): """Set the Location, using linked article.""" loc_q = None if self.has_non_empty_attribute("localidad"): if utils.count_wikilinks(self.localidad) == 1: loc_q = utils.q_from_first_wikilink("es", self.localidad) if loc_q: self.add_statement("location", loc_q) else: self.add_to_report("localidad", self.localidad, "location")
def set_location(self): settlements_dict = self.data_files["settlements"] if utils.count_wikilinks(self.miejscowosc) == 1: location = utils.q_from_first_wikilink("pl", self.miejscowosc) self.add_statement("location", location) else: placename = utils.remove_markup(self.miejscowosc) try: location = [x["item"] for x in settlements_dict if x[ "pl"].strip() == placename][0] self.add_statement("location", location) except IndexError: return
def set_homeport(self): """ Add homeport to data object. Only works if column 'hemmahamn' contains exactly one wikilink. Use WLM database as source. """ if self.has_non_empty_attribute("hemmahamn"): if utils.count_wikilinks(self.hemmahamn) == 1: home_port = utils.q_from_first_wikilink("sv", self.hemmahamn) ref = self.wlm_source self.add_statement("home_port", home_port, refs=[ref])
def set_location(self): """ Set location or street address. There are some street addresses. Some are simple: Norra Murgatan 3 Some are complex: Skolgatan 5, Västra Kyrkogatan 3 Norra Murgatan 27, Uddens gränd 14-16 If self.plats consists of 1 wikilinked item, get the WD item and cross check with the list of known human settlements. If it's not wikilinked text, try to extract an address. """ settlements_dict = self.data_files["settlements"] if self.has_non_empty_attribute("plats"): if utils.count_wikilinks(self.plats) == 1: location_q = utils.q_from_first_wikilink("sv", self.plats) try: legit_location = [ x["item"] for x in settlements_dict if x["item"] == location_q ] legit_location_clean = legit_location[0] self.add_statement("location", legit_location_clean) except IndexError: self.add_to_report("plats", self.plats) elif utils.count_wikilinks(self.plats) == 0: processed_address = utils.get_street_address(self.plats, "sv") if processed_address: self.add_statement("located_street", processed_address) else: self.add_to_report("plats", self.plats) else: self.add_to_report("plats", self.plats)
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_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_adm_location(self): """ Set municipality of the object. Note: All distinct values in this column are wikilinked and in the form "[[Allerød Kommune]]". For safety, compare with offline list of Danish municipalities. """ mun_dict = self.data_files["municipalities"] if self.has_non_empty_attribute("kommune"): if utils.count_wikilinks(self.kommune) == 1: try: adm_q = utils.q_from_first_wikilink("da", self.kommune) municipality = [ x["item"] for x in mun_dict if x["item"] == adm_q ] municipality = municipality[0] self.add_statement("located_adm", municipality) except IndexError: self.add_to_report("kommune", self.kommune)
def set_location(self): """ Set Location property from article linked in localitate. Run this after set_adm_location. localitate can contain several links (we take the 1st which seems to be the most granular one) and a mix of administrative types. Compare with admin location so that they're not the same. """ if self.has_non_empty_attribute("localitate"): loc_item = None if utils.count_wikilinks(self.localitate) > 0: loc_link = utils.get_wikilinks(self.localitate)[0] loc_item = utils.q_from_wikipedia("ro", loc_link.title) adm_item = self.get_statement_values("located_adm") if loc_item and loc_item != adm_item[0]: self.add_statement("location", loc_item) if not loc_item: self.add_to_report("localitate", self.localitate, "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 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 set_adm_location(self): if self.has_non_empty_attribute("kommune"): if utils.count_wikilinks(self.kommune) == 1: adm_location = utils.q_from_first_wikilink("da", self.kommune) self.add_statement("located_adm", adm_location)