[fix] component bitsets

This commit is contained in:
Al
2016-05-24 13:07:32 -04:00
parent 0dbfd79b72
commit 046f445a56

View File

@@ -187,6 +187,9 @@ class AddressComponents(object):
Some components are also more likely to be dropped than others, so in the same config there are Some components are also more likely to be dropped than others, so in the same config there are
dropout probabilities for each. dropout probabilities for each.
''' '''
if not components:
return []
component_bitset = self.component_bitset(components) component_bitset = self.component_bitset(components)
candidates = [c for c in components if c in self.address_level_dropout_probabilities] candidates = [c for c in components if c in self.address_level_dropout_probabilities]
@@ -985,6 +988,8 @@ class AddressComponents(object):
return {c: v for c, v in six.iteritems(address_components) if c != AddressFormatter.POSTCODE} return {c: v for c, v in six.iteritems(address_components) if c != AddressFormatter.POSTCODE}
def drop_invalid_components(self, address_components): def drop_invalid_components(self, address_components):
if not address_components:
return
component_bitset = self.component_bitset(address_components) component_bitset = self.component_bitset(address_components)
for c in list(address_components): for c in list(address_components):
if c in self.component_dependencies and not component_bitset & self.component_dependencies[c]: if c in self.component_dependencies and not component_bitset & self.component_dependencies[c]: