1 # SPDX-License-Identifier: GPL-2.0-only
 
   3 # This file is part of Nominatim. (https://nominatim.org)
 
   5 # Copyright (C) 2022 by the Nominatim developer community.
 
   6 # For a full list of authors see the git log.
 
   8 Wrapper around place information the indexer gets from the database and hands to
 
  12 import psycopg2.extras
 
  15     """ Data class containing all information the tokenizer gets about a
 
  16         place it should process the names for.
 
  19     def __init__(self, info):
 
  23     def analyze(self, analyzer):
 
  24         """ Process this place with the given tokenizer and return the
 
  25             result in psycopg2-compatible Json.
 
  27         return psycopg2.extras.Json(analyzer.process_place(self))
 
  32         """ A dictionary with the names of the place or None if the place
 
  35         return self._info.get('name')
 
  40         """ A dictionary with the address elements of the place
 
  41             or None if no address information is available.
 
  43         return self._info.get('address')
 
  47     def country_code(self):
 
  48         """ The country code of the country the place is in. Guaranteed
 
  49             to be a two-letter lower-case string or None, if no country
 
  52         return self._info.get('country_code')
 
  56     def rank_address(self):
 
  57         """ The computed rank address before rank correction.
 
  59         return self._info.get('rank_address')
 
  62     def is_a(self, key, value):
 
  63         """ Check if the place's primary tag corresponds to the given
 
  66         return self._info.get('class') == key and self._info.get('type') == value
 
  70         """ Check if the place is a valid country boundary.
 
  72         return self.rank_address == 4 \
 
  73                and self.is_a('boundary', 'administrative') \
 
  74                and self.country_code is not None