X-Git-Url: https://git.openstreetmap.org/nominatim.git/blobdiff_plain/d44a428b744916a21c2d82d654f1358efe027d21..231250f2eb272b77d54e4b4b18bd85a80413ac34:/nominatim/indexer/place_info.py diff --git a/nominatim/indexer/place_info.py b/nominatim/indexer/place_info.py new file mode 100644 index 00000000..fd179fef --- /dev/null +++ b/nominatim/indexer/place_info.py @@ -0,0 +1,44 @@ +""" +Wrapper around place information the indexer gets from the database and hands to +the tokenizer. +""" + +import psycopg2.extras + +class PlaceInfo: + """ Data class containing all information the tokenizer gets about a + place it should process the names for. + """ + + def __init__(self, info): + self._info = info + + + def analyze(self, analyzer): + """ Process this place with the given tokenizer and return the + result in psycopg2-compatible Json. + """ + return psycopg2.extras.Json(analyzer.process_place(self)) + + + @property + def name(self): + """ A dictionary with the names of the place or None if the place + has no names. + """ + return self._info.get('name') + + + @property + def address(self): + """ A dictionary with the address elements of the place + or None if no address information is available. + """ + return self._info.get('address') + + + @property + def country_feature(self): + """ Return the country code if the place is a valid country boundary. + """ + return self._info.get('country_feature')