Ejemplo n.º 1
0
    def is_matched(q: WikidataItem) -> bool:
        # 確認是否有中文名
        if q.get_label("zh") == "":
            print(f'Skip, no zh label: {q.get_enwiki_title()}')
            return False

        # entity不能是人
        cg = q.get_claim_group("P31")  # P31:instance_of
        instanceof = [c.mainsnak.datavalue.value['id'] for c in cg]
        if "Q5" in instanceof:  # Q5:human
            print(f'Skip, is a person: {q.get_enwiki_title()}')
            return False

        # entity不能有位置claim
        cg = q.get_claim_group("P625")  # P625:coordinate_location
        if cg.property_id is not None:
            print(f'Skip, has coordinate location: {q.get_enwiki_title()}')
            return False
        return True
Ejemplo n.º 2
0
 def test_get_claim_1(self) -> None:
     """Assert correct behavior."""
     q42_dict = _load_item_dict(typedefs.ItemId("Q42"))
     given_name_douglas = "Q463035"
     given_name_noel = "Q19688263"
     item = WikidataItem(q42_dict)
     claim_group = item.get_claim_group(typedefs.PropertyId("P735"))
     assert len(claim_group) == 2
     given_names = set(
         [cl.mainsnak.datavalue.value["id"] for cl in claim_group])
     assert given_names == set([given_name_douglas, given_name_noel])
Ejemplo n.º 3
0
def has_occupation_politician(item: WikidataItem, truthy: bool = True) -> bool:
    """Return True if the Wikidata Item has occupation politician."""
    if truthy:
        claim_group = item.get_truthy_claim_group(P_OCCUPATION)
    else:
        claim_group = item.get_claim_group(P_OCCUPATION)

    occupation_qids = [
        claim.mainsnak.datavalue.value["id"]
        for claim in claim_group
        if claim.mainsnak.snaktype == "value"
    ]
    return Q_POLITICIAN in occupation_qids