X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/3742fa2929619a4c54a50d3e79e0eeadb4d6ca6f..1f0796778754d8df0dfab9dd01302e26a397f064:/src/nominatim_db/data/country_info.py?ds=sidebyside diff --git a/src/nominatim_db/data/country_info.py b/src/nominatim_db/data/country_info.py index e2bf5133..bc3f20f5 100644 --- a/src/nominatim_db/data/country_info.py +++ b/src/nominatim_db/data/country_info.py @@ -16,6 +16,7 @@ from ..errors import UsageError from ..config import Configuration from ..tokenizer.base import AbstractTokenizer + def _flatten_name_list(names: Any) -> Dict[str, str]: if names is None: return {} @@ -39,7 +40,6 @@ def _flatten_name_list(names: Any) -> Dict[str, str]: return flat - class _CountryInfo: """ Caches country-specific properties from the configuration file. """ @@ -47,7 +47,6 @@ class _CountryInfo: def __init__(self) -> None: self._info: Dict[str, Dict[str, Any]] = {} - def load(self, config: Configuration) -> None: """ Load the country properties from the configuration files, if they are not loaded yet. @@ -63,7 +62,6 @@ class _CountryInfo: for x in prop['languages'].split(',')] prop['names'] = _flatten_name_list(prop.get('names')) - def items(self) -> Iterable[Tuple[str, Dict[str, Any]]]: """ Return tuples of (country_code, property dict) as iterable. """ @@ -75,7 +73,6 @@ class _CountryInfo: return self._info.get(country_code, {}) - _COUNTRY_INFO = _CountryInfo() @@ -86,14 +83,17 @@ def setup_country_config(config: Configuration) -> None: """ _COUNTRY_INFO.load(config) + @overload def iterate() -> Iterable[Tuple[str, Dict[str, Any]]]: ... + @overload def iterate(prop: str) -> Iterable[Tuple[str, Any]]: ... + def iterate(prop: Optional[str] = None) -> Iterable[Tuple[str, Dict[str, Any]]]: """ Iterate over country code and properties. @@ -138,9 +138,10 @@ def setup_country_tables(dsn: str, sql_dir: Path, ignore_partitions: bool = Fals country_default_language_code text, partition integer ); """) - cur.execute_values( + cur.executemany( """ INSERT INTO public.country_name - (country_code, name, country_default_language_code, partition) VALUES %s + (country_code, name, country_default_language_code, partition) + VALUES (%s, %s, %s, %s) """, params) conn.commit() @@ -167,7 +168,7 @@ def create_country_names(conn: Connection, tokenizer: AbstractTokenizer, # country names (only in languages as provided) if name: - names.update({k : v for k, v in name.items() if _include_key(k)}) + names.update({k: v for k, v in name.items() if _include_key(k)}) analyzer.add_country_names(code, names)