2 Implementation of the 'special-phrases' command.
5 from nominatim.errors import UsageError
6 from pathlib import Path
7 from nominatim.tools import SPWikiLoader
8 from nominatim.tools import SPImporter
9 from nominatim.db.connection import connect
11 LOG = logging.getLogger()
13 # Do not repeat documentation of subcommand classes.
14 # pylint: disable=C0111
15 # Using non-top-level imports to avoid eventually unused imports.
16 # pylint: disable=E0012,C0415
18 class ImportSpecialPhrases:
20 Import special phrases.
24 group = parser.add_argument_group('Input arguments')
25 group.add_argument('--import-from-wiki', action='store_true',
26 help='Import special phrases from the OSM wiki to the database.')
27 group.add_argument('--csv-file', metavar='FILE',
28 help='CSV file containing phrases to import.')
32 from ..tokenizer import factory as tokenizer_factory
34 if args.import_from_wiki:
35 tokenizer = tokenizer_factory.get_tokenizer_for_db(args.config)
36 with connect(args.config.get_libpq_dsn()) as db_connection:
38 args.config, args.phplib_dir, db_connection, SPWikiLoader(args.config)
39 ).import_phrases(tokenizer)
42 if not Path(args.csv_file).is_file():
43 LOG.fatal("CSV file '%s' does not exist.", args.csv_file)
44 raise UsageError('Cannot access file.')