]> git.openstreetmap.org Git - nominatim.git/blob - nominatim/clicmd/special_phrases.py
Merge remote-tracking branch 'upstream/master'
[nominatim.git] / nominatim / clicmd / special_phrases.py
1 """
2     Implementation of the 'special-phrases' command.
3 """
4 import logging
5 from nominatim.tools import SpecialPhrasesImporter
6 from nominatim.db.connection import connect
7
8 LOG = logging.getLogger()
9
10 # Do not repeat documentation of subcommand classes.
11 # pylint: disable=C0111
12 # Using non-top-level imports to avoid eventually unused imports.
13 # pylint: disable=E0012,C0415
14
15 class ImportSpecialPhrases:
16     """\
17     Import special phrases.
18     """
19     @staticmethod
20     def add_args(parser):
21         group = parser.add_argument_group('Input arguments')
22         group.add_argument('--import-from-wiki', action='store_true',
23                            help='Import special phrases from the OSM wiki to the database.')
24
25     @staticmethod
26     def run(args):
27         from ..tokenizer import factory as tokenizer_factory
28
29         if args.import_from_wiki:
30             LOG.warning('Special phrases importation starting')
31             tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
32             with connect(args.config.get_libpq_dsn()) as db_connection:
33                 SpecialPhrasesImporter(
34                     args.config, args.phplib_dir, db_connection
35                 ).import_from_wiki(tokenizer)
36         return 0