X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/8c14df55a61d71f2476c8a17287e1bd162a5c6a6..1f0796778754d8df0dfab9dd01302e26a397f064:/src/nominatim_api/v1/helpers.py diff --git a/src/nominatim_api/v1/helpers.py b/src/nominatim_api/v1/helpers.py index 4e1e4e55..2c6ddc99 100644 --- a/src/nominatim_api/v1/helpers.py +++ b/src/nominatim_api/v1/helpers.py @@ -15,6 +15,7 @@ import re from ..results import SearchResult, SearchResults, SourceTable from ..types import SearchDetails, GeometryFormat + REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea 4, 4, # 3-4 Country 8, # 5 State @@ -28,7 +29,7 @@ REVERSE_MAX_RANKS = [2, 2, 2, # 0-2 Continent/Sea 26, # 16 Major Streets 27, # 17 Minor Streets 30 # 18 Building - ] + ] def zoom_to_rank(zoom: int) -> int: @@ -52,7 +53,6 @@ def feature_type_to_rank(feature_type: Optional[str]) -> Tuple[int, int]: return FEATURE_TYPE_TO_RANK.get(feature_type, (0, 30)) -#pylint: disable=too-many-arguments,too-many-branches def extend_query_parts(queryparts: Dict[str, Any], details: Dict[str, Any], feature_type: Optional[str], namedetails: bool, extratags: bool, @@ -135,15 +135,18 @@ def _is_postcode_relation_for(result: SearchResult, postcode: str) -> bool: and result.names.get('ref') == postcode -def _deg(axis:str) -> str: +def _deg(axis: str) -> str: return f"(?P<{axis}_deg>\\d+\\.\\d+)°?" + def _deg_min(axis: str) -> str: return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>[\\d.]+)[′']*" + def _deg_min_sec(axis: str) -> str: return f"(?P<{axis}_deg>\\d+)[°\\s]+(?P<{axis}_min>\\d+)[′'\\s]+(?P<{axis}_sec>[\\d.]+)[\"″]*" + COORD_REGEX = [re.compile(r'(?:(?P
.*?)\s+)??' + r + r'(?:\s+(?P.*))?') for r in (
     r"(?P[NS])\s*" + _deg('lat') + r"[\s,]+" + r"(?P[EW])\s*" + _deg('lon'),
     _deg('lat') + r"\s*(?P[NS])[\s,]+" + _deg('lon') + r"\s*(?P[EW])",
@@ -154,6 +157,7 @@ COORD_REGEX = [re.compile(r'(?:(?P
.*?)\s+)??' + r + r'(?:\s+(?P.*))?'
     r"\[?(?P[+-]?\d+\.\d+)[\s,]+(?P[+-]?\d+\.\d+)\]?"
 )]
 
+
 def extract_coords_from_query(query: str) -> Tuple[str, Optional[float], Optional[float]]:
     """ Look for something that is formatted like a coordinate at the
         beginning or end of the query. If found, extract the coordinate and
@@ -185,6 +189,7 @@ def extract_coords_from_query(query: str) -> Tuple[str, Optional[float], Optiona
 
 CATEGORY_REGEX = re.compile(r'(?P
.*?)\[(?P[a-zA-Z_]+)=(?P[a-zA-Z_]+)\](?P.*)')
 
+
 def extract_category_from_query(query: str) -> Tuple[str, Optional[str], Optional[str]]:
     """ Extract a hidden category specification of the form '[key=value]' from
         the query. If found, extract key and value  and