Exemplo n.º 1
0
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])
Exemplo n.º 2
0
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])
Exemplo n.º 3
0
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
Exemplo n.º 4
0
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
Exemplo n.º 5
0
    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])
Exemplo n.º 6
0
    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
Exemplo n.º 7
0
    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])
Exemplo n.º 8
0
    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])
Exemplo n.º 9
0
 def make_sanitizer(self):
     """ Create a place sanitizer from the configured rules.
     """
     return PlaceSanitizer(self.sanitizer_rules)