Example #1
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
Example #2
0
 def test_get_truthy_claim_1(self) -> None:
     """Assert correct behavior with one preferred and one normal."""
     q42_dict = _load_item_dict(typedefs.ItemId("Q42"))
     given_name_douglas = "Q463035"
     item = WikidataItem(q42_dict)
     truthy_claim_group = item.get_truthy_claim_group(
         typedefs.PropertyId("P735"))
     assert len(truthy_claim_group) == 1
     claim = truthy_claim_group[0]
     mainsnak = claim.mainsnak
     datavalue = mainsnak.datavalue
     assert isinstance(datavalue, WikibaseEntityId)
     qid = datavalue.value["id"]
     assert qid == given_name_douglas