From 9c426b2918f29d6ea28cff49c8a197c6cc5f9e8c Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Fri, 22 Oct 2021 09:54:04 +0100 Subject: [PATCH] Item methods to work out if it is a linear feature --- matcher/model.py | 40 ++++++++++++++++++++++++++++++++-------- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/matcher/model.py b/matcher/model.py index f4a6f0a..ac38705 100644 --- a/matcher/model.py +++ b/matcher/model.py @@ -159,16 +159,40 @@ class Item(Base): return isa_list def get_isa_qids(self): - return [v["id"] for v in self.get_claim("P31") if v] + return [isa["id"] for isa in self.get_isa()] - def is_street(self): - street_items = { - 'Q34442', # road - 'Q79007', # street - 'Q83620', # thoroughfare - 'Q21000333', # shopping street + def is_street(self, isa_qids=None): + if isa_qids is None: + isa_qids = self.get_isa_qids() + + matching_types = { + "Q12731", # dead end street + "Q34442", # road + "Q79007", # street + "Q83620", # thoroughfare + "Q21000333", # shopping street + "Q62685721", # pedestrian street } - return bool(street_items & set(self.get_isa_qids())) + return bool(matching_types & set(isa_qids)) + + def is_watercourse(self, isa_qids=None): + if isa_qids is None: + isa_qids = self.get_isa_qids() + matching_types = { + "Q355304", # watercourse + "Q4022", # river + "Q47521", # stream + "Q1437299", # creek + "Q63565252", # brook + "Q12284", # canal + "Q55659167", # natural watercourse + + } + return bool(matching_types & set(isa_qids)) + + def is_linear_feature(self): + isa_qids = set(self.get_isa_qids()) + return self.is_street(isa_qids) or self.is_watercourse(isa_qids) def is_tram_stop(self): return 'Q2175765' in self.get_isa_qids()