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 """ Data class containing all information the tokenizer gets about a
15 place it should process the names for.
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 or None if the place
27 return self._info.get('name')
31 def address(self) -> Optional[Mapping[str, str]]:
32 """ A dictionary with the address elements of the place
33 or None if no address information is available.
35 return self._info.get('address')
39 def country_code(self) -> Optional[str]:
40 """ The country code of the country the place is in. Guaranteed
41 to be a two-letter lower-case string or None, if no country
44 return self._info.get('country_code')
48 def rank_address(self) -> int:
49 """ The computed rank address before rank correction.
51 return self._info.get('rank_address', 0)
54 def is_a(self, key: str, value: str) -> bool:
55 """ Check if the place's primary tag corresponds to the given
58 return self._info.get('class') == key and self._info.get('type') == value
61 def is_country(self) -> bool:
62 """ Check if the place is a valid country boundary.
64 return self.rank_address == 4 \
65 and self.is_a('boundary', 'administrative') \
66 and self.country_code is not None