Пример #1
0
    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
Пример #2
0
    def set_location(self):
        """
        Set location (P276) of object.

        If there's a 'plats' and it's wikilinked use it as location:
            [[Tyresta]]
        It's just a handful of items that have it, though.
        But all should have socken/landskap,
        so use that as location as well.
        """
        if self.has_non_empty_attribute("plats"):
            wikilinks = utils.get_wikilinks(self.plats)
            if len(wikilinks) == 1:
                target_page = wikilinks[0].title
                wd_item = utils.q_from_wikipedia("sv", target_page)
                self.add_statement("location", wd_item)
            else:
                self.add_to_report("plats", self.plats)
        if self.has_non_empty_attribute("socken"):
            socken_dict = self.data_files["socken"]
            socken = self.get_socken(self.socken, self.landskap)
            if socken:
                self.add_statement("location", socken)
            else:
                try:
                    possible_socken = [
                        x["item"] for x in socken_dict
                        if x["itemLabel"].startswith(self.socken)
                    ]
                    if len(possible_socken) != 1:
                        raise ValueError
                    self.add_statement("location", possible_socken[0])
                except (IndexError, ValueError):
                    raw_socken = "{} ({})".format(self.socken, self.landskap)
                    self.add_to_report("socken", raw_socken)
Пример #3
0
 def set_parts(self):
     if self.has_non_empty_attribute("enlace"):
         parts_raw = self.enlace
         parts_links = utils.get_wikilinks(parts_raw)
         for link in parts_links:
             part_q = utils.q_from_wikipedia("es", link.title)
             if part_q:
                 self.add_statement("has_part", part_q)
             else:
                 self.add_to_report("enlace", self.enlace, "has_part")
Пример #4
0
    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
Пример #5
0
    def set_architect(self):
        """
        Set the architect.

        Only if wikilinked.
        Can be more than one.
        Check if it's a human.
        """
        if self.has_non_empty_attribute("arkitekt"):
            architects = utils.get_wikilinks(self.arkitekt)
            for name in architects:
                wp_page = name.title
                q_item = utils.q_from_wikipedia("sv", wp_page)
                if q_item:
                    if utils.is_whitelisted_P31(q_item, self.repo, ["Q5"]):
                        self.add_statement("architect", q_item)
                    else:
                        self.add_to_report("arkitekt", self.arkitekt)
Пример #6
0
    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")