[boundaries] removing omissions from boundary names config

This commit is contained in:
Al
2016-05-10 00:52:00 -04:00
parent 44f0054170
commit 7ef207f54d

View File

@@ -50,22 +50,6 @@ class BoundaryNames(object):
probs = cdf(probs)
self.exceptions[(object_type, object_id)] = (keys, probs)
self.include_probabilities = {}
self.omit_conditions = defaultdict(set)
for props in nested_get(config, ('names', 'omissions'), default=[]):
object_type = props['type']
object_id = safe_encode(props['id'])
include_probability = props.get('include_probability')
if include_probability is not None:
self.include_probabilities[(object_type, object_id)] = float(include_probability)
for condition in nested_get(props, ('omit', 'conditions'), default=[]):
condition_object_id = safe_encode(condition['id'])
condition_object_type = condition['type']
self.omit_conditions[(object_type, object_id)].add((condition_object_type, condition_object_id))
def name_key(self, props, component):
object_type = props.get('type')
object_id = safe_encode(props.get('id', ''))
@@ -77,25 +61,4 @@ class BoundaryNames(object):
name_keys, probs = self.component_name_keys.get(component, (self.name_keys, self.name_key_probs))
return weighted_choice(name_keys, probs)
def remove_excluded_components(self, components):
all_ids = set()
for component in components:
object_type = component.get('type')
object_id = safe_encode(component.get('id', ''))
all_ids.add((object_type, object_id))
for object_type, object_id in list(all_ids):
if (object_type, object_id) in self.omit_conditions:
conditions = self.omit_conditions[(object_type, object_id)]
if all_ids & conditions:
all_ids.remove((object_type, object_id))
if (object_type, object_id) in self.include_probabilities and random.random() > self.include_probabilities[(object_type, object_id)]:
all_ids.remove((object_type, object_id))
if len(all_ids) == len(components):
return components
return [c for c in components if (c.get('type'), safe_encode(c.get('id', ''))) in all_ids]
boundary_names = BoundaryNames()