X-Git-Url: https://git.openstreetmap.org./nominatim.git/blobdiff_plain/231250f2eb272b77d54e4b4b18bd85a80413ac34..98432395c31f0ae46962907e2c19c4eebc12c8bb:/nominatim/indexer/place_info.py diff --git a/nominatim/indexer/place_info.py b/nominatim/indexer/place_info.py index fd179fef..87ecb731 100644 --- a/nominatim/indexer/place_info.py +++ b/nominatim/indexer/place_info.py @@ -1,3 +1,9 @@ +# 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. """ Wrapper around place information the indexer gets from the database and hands to the tokenizer. @@ -38,7 +44,31 @@ class PlaceInfo: @property - def country_feature(self): - """ Return the country code if the place is a valid country boundary. + def country_code(self): + """ 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. """ - return self._info.get('country_feature') + return self._info.get('country_code') + + + @property + def rank_address(self): + """ The computed rank address before rank correction. + """ + return self._info.get('rank_address') + + + def is_a(self, key, value): + """ 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): + """ Check if the place is a valid country boundary. + """ + return self.rank_address == 4 \ + and self.is_a('boundary', 'administrative') \ + and self.country_code is not None