forked from hans/Nominatim
add typing information for place_info and country_info
This commit is contained in:
@@ -8,18 +8,19 @@
|
||||
Wrapper around place information the indexer gets from the database and hands to
|
||||
the tokenizer.
|
||||
"""
|
||||
from typing import Optional, Mapping, Any
|
||||
|
||||
class PlaceInfo:
|
||||
""" Data class containing all information the tokenizer gets about a
|
||||
place it should process the names for.
|
||||
"""
|
||||
|
||||
def __init__(self, info):
|
||||
def __init__(self, info: Mapping[str, Any]) -> None:
|
||||
self._info = info
|
||||
|
||||
|
||||
@property
|
||||
def name(self):
|
||||
def name(self) -> Optional[Mapping[str, str]]:
|
||||
""" A dictionary with the names of the place or None if the place
|
||||
has no names.
|
||||
"""
|
||||
@@ -27,7 +28,7 @@ class PlaceInfo:
|
||||
|
||||
|
||||
@property
|
||||
def address(self):
|
||||
def address(self) -> Optional[Mapping[str, str]]:
|
||||
""" A dictionary with the address elements of the place
|
||||
or None if no address information is available.
|
||||
"""
|
||||
@@ -35,7 +36,7 @@ class PlaceInfo:
|
||||
|
||||
|
||||
@property
|
||||
def country_code(self):
|
||||
def country_code(self) -> Optional[str]:
|
||||
""" The country code of the country the place is in. Guaranteed
|
||||
to be a two-letter lower-case string or None, if no country
|
||||
could be found.
|
||||
@@ -44,20 +45,20 @@ class PlaceInfo:
|
||||
|
||||
|
||||
@property
|
||||
def rank_address(self):
|
||||
def rank_address(self) -> int:
|
||||
""" The computed rank address before rank correction.
|
||||
"""
|
||||
return self._info.get('rank_address')
|
||||
return self._info.get('rank_address', 0)
|
||||
|
||||
|
||||
def is_a(self, key, value):
|
||||
def is_a(self, key: str, value: str) -> bool:
|
||||
""" Check if the place's primary tag corresponds to the given
|
||||
key and value.
|
||||
"""
|
||||
return self._info.get('class') == key and self._info.get('type') == value
|
||||
|
||||
|
||||
def is_country(self):
|
||||
def is_country(self) -> bool:
|
||||
""" Check if the place is a valid country boundary.
|
||||
"""
|
||||
return self.rank_address == 4 \
|
||||
|
||||
Reference in New Issue
Block a user