From 954b6548bf0c494ae0102d919e1069a6195e340f Mon Sep 17 00:00:00 2001 From: Al Date: Sun, 18 Dec 2016 17:20:03 -0500 Subject: [PATCH] [names] adding name_key_dist method to boundary names to account for certain boundaries like e.g. Kings County that have name exceptions --- scripts/geodata/boundaries/names.py | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/scripts/geodata/boundaries/names.py b/scripts/geodata/boundaries/names.py index e7401594..67db8cd9 100644 --- a/scripts/geodata/boundaries/names.py +++ b/scripts/geodata/boundaries/names.py @@ -66,15 +66,19 @@ class BoundaryNames(object): probs = cdf(probs) self.exceptions[(object_type, object_id)] = (keys, probs) - def name_key(self, props, component): + def name_key_dist(self, props, component): object_type = props.get('type') object_id = safe_encode(props.get('id', '')) if (object_type, object_id) in self.exceptions: values, probs = self.exceptions[(object_type, object_id)] - return weighted_choice(values, probs) + return values, probs name_keys, probs = self.component_name_keys.get(component, (self.name_keys, self.name_key_probs)) + return name_keys, probs + + def name_key(self, props, component): + name_keys, probs = self.name_key_dist(props, component) return weighted_choice(name_keys, probs) def name(self, country, name): @@ -89,5 +93,4 @@ class BoundaryNames(object): return name - boundary_names = BoundaryNames()