From 238fbeef0599d7db24a82cc959d4831278a32132 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 28 Jun 2021 11:50:37 +0200 Subject: [PATCH] Avoid matching tram stops with buildings --- matcher/api.py | 2 ++ matcher/model.py | 8 ++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/matcher/api.py b/matcher/api.py index b505ad3..20f7018 100644 --- a/matcher/api.py +++ b/matcher/api.py @@ -174,6 +174,8 @@ def get_item_tags(item): osm_list = set() skip_isa = {row[0] for row in database.session.query(model.SkipIsA.item_id)} + if item.is_tram_stop(): + skip_isa.add(41176) # building (Q41176) seen = set(isa_list) | skip_isa while isa_items: diff --git a/matcher/model.py b/matcher/model.py index 796d28c..546abc2 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -45,7 +45,6 @@ class Item(Base): def wd_url(self): return f"https://www.wikidata.org/wiki/{self.qid}" - def get_claim(self, pid): return [i["mainsnak"]["datavalue"]["value"] if "datavalue" in i["mainsnak"] else None for i in self.claims.get(pid, [])] @@ -145,13 +144,18 @@ class Item(Base): return dict(d) or None + def get_isa_qids(self): + return {v["id"] for v in self.get_claim("P31") if v} + def is_street(self): street_items = { 'Q79007', # street 'Q21000333', # shopping street } - return any(v and v["id"] in street_items for v in self.get_claim("P31")) + return bool(street_items & self.get_isa_qids()) + def is_tram_stop(self): + return 'Q2175765' in self.get_isa_qids() # class Claim(Base): # __tablename__ = "claim"