From 2760cdb9400347804f1a3ee1b122fa6e32061339 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Thu, 22 Jul 2021 17:07:26 +0200 Subject: [PATCH] Use sets in get_item_tags --- matcher/api.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/matcher/api.py b/matcher/api.py index d250e52..e16a089 100644 --- a/matcher/api.py +++ b/matcher/api.py @@ -244,13 +244,13 @@ def get_item_tags(item): for i in osm: osm_list[i].append(isa_path[:]) - subclass_of = [v["numeric-id"] for v in (isa.get_claim("P279") or []) if v] - religion = [v["numeric-id"] for v in (isa.get_claim("P140") or []) if v] - sport = [v["numeric-id"] for v in (isa.get_claim("P641") or []) if v] - use = [v["numeric-id"] for v in (isa.get_claim("P366") or []) if v] - check = subclass_of + religion + sport + use + subclass_of = {v["numeric-id"] for v in (isa.get_claim("P279") or []) if v} + religion = {v["numeric-id"] for v in (isa.get_claim("P140") or []) if v} + sport = {v["numeric-id"] for v in (isa.get_claim("P641") or []) if v} + use = {v["numeric-id"] for v in (isa.get_claim("P366") or []) if v} + check = subclass_of | religion | sport | use print(isa.qid, isa.label(), check) - isa_list = [isa_id for isa_id in check if isa_id not in seen] + isa_list = check - seen seen.update(isa_list) isa_items += [(isa, isa_path) for isa in get_items(isa_list)] return {key: list(values) for key, values in osm_list.items()}