[names] adding name_key_dist method to boundary names to account for certain boundaries like e.g. Kings County that have name exceptions

This commit is contained in:
Al
2016-12-18 17:20:03 -05:00
parent d308473686
commit 954b6548bf

View File

@@ -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()