def sanitize_with_delimiter(delimiter, name): place = PlaceInfo({'name': {'name': name}}) san = PlaceSanitizer([{ 'step': 'split-name-list', 'delimiters': delimiter }]) name, _ = san.process_names(place) return sorted([p.name for p in name])
def run_sanitizer_on(**kwargs): place = PlaceInfo({'name': kwargs}) name, _ = PlaceSanitizer([{ 'step': 'strip-brace-terms' }]).process_names(place) return sorted([(p.name, p.kind, p.suffix) for p in name])
def test_no_names(): place = PlaceInfo({'address': {'housenumber': '3'}}) name, address = PlaceSanitizer([{ 'step': 'strip-brace-terms' }]).process_names(place) assert not name assert len(address) == 1
def test_no_name_list(): place = PlaceInfo({'address': {'housenumber': '3'}}) name, address = PlaceSanitizer([{ 'step': 'split-name-list' }]).process_names(place) assert not name assert len(address) == 1
def run_sanitizer_on(country, **kwargs): place = PlaceInfo({ 'name': {k.replace('_', ':'): v for k, v in kwargs.items()}, 'country_code': country }) name, _ = PlaceSanitizer([{ 'step': 'tag-analyzer-by-language' }]).process_names(place) return sorted([(p.name, p.kind, p.suffix, p.attr) for p in name])
def test_missing_country(self): place = PlaceInfo({'name': {'name': 'something'}}) name, _ = PlaceSanitizer([{ 'step': 'tag-analyzer-by-language', 'use-defaults': 'all', 'mode': 'replace' }]).process_names(place) assert len(name) == 1 assert name[0].name == 'something' assert name[0].suffix is None assert 'analyzer' not in name[0].attr
def run_sanitizer_on(whitelist, **kwargs): place = PlaceInfo( {'name': {k.replace('_', ':'): v for k, v in kwargs.items()}}) name, _ = PlaceSanitizer([{ 'step': 'tag-analyzer-by-language', 'mode': 'replace', 'whitelist': whitelist }]).process_names(place) assert all(isinstance(p.attr, dict) for p in name) assert all(len(p.attr) <= 1 for p in name) assert all(not p.attr or ('analyzer' in p.attr and p.attr['analyzer']) for p in name) return sorted([(p.name, p.attr.get('analyzer', '')) for p in name])
def run_sanitizer_replace(mode, country, **kwargs): place = PlaceInfo({ 'name': {k.replace('_', ':'): v for k, v in kwargs.items()}, 'country_code': country }) name, _ = PlaceSanitizer([{ 'step': 'tag-analyzer-by-language', 'use-defaults': mode, 'mode': 'replace' }]).process_names(place) assert all(isinstance(p.attr, dict) for p in name) assert all(len(p.attr) <= 1 for p in name) assert all(not p.attr or ('analyzer' in p.attr and p.attr['analyzer']) for p in name) return sorted([(p.name, p.attr.get('analyzer', '')) for p in name])
def make_sanitizer(self): """ Create a place sanitizer from the configured rules. """ return PlaceSanitizer(self.sanitizer_rules)