1 # SPDX-License-Identifier: GPL-2.0-only
3 # This file is part of Nominatim. (https://nominatim.org)
5 # Copyright (C) 2022 by the Nominatim developer community.
6 # For a full list of authors see the git log.
8 Wrapper around place information the indexer gets from the database and hands to
11 from typing import Optional, Mapping, Any
14 """ This data class contains all information the tokenizer can access
18 def __init__(self, info: Mapping[str, Any]) -> None:
23 def name(self) -> Optional[Mapping[str, str]]:
24 """ A dictionary with the names of the place. Keys and values represent
25 the full key and value of the corresponding OSM tag. Which tags
26 are saved as names is determined by the import style.
27 The property may be None if the place has no names.
29 return self._info.get('name')
33 def address(self) -> Optional[Mapping[str, str]]:
34 """ A dictionary with the address elements of the place. They key
35 usually corresponds to the suffix part of the key of an OSM
36 'addr:*' or 'isin:*' tag. There are also some special keys like
37 `country` or `country_code` which merge OSM keys that contain
38 the same information. See [Import Styles][1] for details.
40 The property may be None if the place has no address information.
42 [1]: ../customize/Import-Styles.md
44 return self._info.get('address')
48 def country_code(self) -> Optional[str]:
49 """ The country code of the country the place is in. Guaranteed
50 to be a two-letter lower-case string. If the place is not inside
51 any country, the property is set to None.
53 return self._info.get('country_code')
57 def rank_address(self) -> int:
58 """ The [rank address][1] before ant rank correction is applied.
60 [1]: ../customize/Ranking.md#address-rank
62 return self._info.get('rank_address', 0)
65 def is_a(self, key: str, value: str) -> bool:
66 """ Set to True when the place's primary tag corresponds to the given
69 return self._info.get('class') == key and self._info.get('type') == value
72 def is_country(self) -> bool:
73 """ Set to True when the place is a valid country boundary.
75 return self.rank_address == 4 \
76 and self.is_a('boundary', 'administrative') \
77 and self.country_code is not None