New method to get IsA details for item

This commit is contained in:
Edward Betts 2021-10-22 09:53:40 +01:00
parent f291ce993e
commit 38e23ec8cc

View file

@ -146,6 +146,18 @@ class Item(Base):
return dict(d) or None return dict(d) or None
def get_isa(self):
isa_list = []
of_property = "P642"
for claim in self.claims.get("P31", []):
qualifiers = claim.get("qualifiers", {})
if "datavalue" in claim["mainsnak"]:
isa_list.append(claim["mainsnak"]["datavalue"]["value"])
for of_qualifier in qualifiers.get(of_property, []):
if "datavalue" in of_qualifier:
isa_list.append(of_qualifier["datavalue"]["value"])
return isa_list
def get_isa_qids(self): def get_isa_qids(self):
return [v["id"] for v in self.get_claim("P31") if v] return [v["id"] for v in self.get_claim("P31") if v]