From 38e23ec8cce7a34b1f33cc9856a14ea19c0d5948 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 22 Oct 2021 09:53:40 +0100 Subject: [PATCH] New method to get IsA details for item --- matcher/model.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/matcher/model.py b/matcher/model.py index f4c83b7..f4a6f0a 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -146,6 +146,18 @@ class Item(Base): 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): return [v["id"] for v in self.get_claim("P31") if v]