X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/c4f5c11a4e8e633bb8e023fc9c2a97232e7463bb..8c7140d92b7a679ae5ef5bb3655c69bd39b7dfeb:/nominatim/tools/special_phrases/special_phrase.py?ds=sidebyside diff --git a/nominatim/tools/special_phrases/special_phrase.py b/nominatim/tools/special_phrases/special_phrase.py index 3b6aef85..40f6a9e4 100644 --- a/nominatim/tools/special_phrases/special_phrase.py +++ b/nominatim/tools/special_phrases/special_phrase.py @@ -1,20 +1,37 @@ +# SPDX-License-Identifier: GPL-2.0-only +# +# This file is part of Nominatim. (https://nominatim.org) +# +# Copyright (C) 2022 by the Nominatim developer community. +# For a full list of authors see the git log. """ Module containing the class SpecialPhrase. This class is a model used to transfer a special phrase through the process of load and importation. """ -import re +from typing import Any -class SpecialPhrase(): +class SpecialPhrase: """ Model representing a special phrase. """ - def __init__(self, p_label, p_class, p_type, p_operator): + def __init__(self, p_label: str, p_class: str, p_type: str, p_operator: str) -> None: self.p_label = p_label.strip() self.p_class = p_class.strip() - # Hack around a bug where building=yes was imported with quotes into the wiki - self.p_type = re.sub(r'\"|"', '', p_type.strip()) + self.p_type = p_type.strip() # Needed if some operator in the wiki are not written in english p_operator = p_operator.strip().lower() self.p_operator = '-' if p_operator not in ('near', 'in') else p_operator + + def __eq__(self, other: Any) -> bool: + if not isinstance(other, SpecialPhrase): + return False + + return self.p_label == other.p_label \ + and self.p_class == other.p_class \ + and self.p_type == other.p_type \ + and self.p_operator == other.p_operator + + def __hash__(self) -> int: + return hash((self.p_label, self.p_class, self.p_type, self.p_operator))