|
9 | 9 | #include "normalization.h" |
10 | 10 |
|
11 | 11 | #include <algorithm> |
12 | | -#include <boost/tokenizer.hpp> |
| 12 | +#include <boost/program_options.hpp> |
13 | 13 | #include <cctype> |
14 | 14 | #include <cstdlib> |
15 | 15 | #include <deque> |
|
23 | 23 | #include <set> |
24 | 24 | #include <sqlite3pp.h> |
25 | 25 |
|
26 | | -using json = nlohmann::json; |
| 26 | +using json = nlohmann::json; |
| 27 | +namespace po = boost::program_options; |
27 | 28 |
|
28 | 29 | //////////////////////////////////////////////////////////////////////////// |
29 | 30 | // MAIN |
30 | 31 |
|
31 | 32 | int main(int argc, char *argv[]) |
32 | 33 | { |
33 | | - if (argc == 2) |
34 | | - { |
35 | | - std::string option = argv[1]; |
36 | | - if (option == "--version") |
37 | | - { |
38 | | - std::cout << GeoNLP::Geocoder::version << "\n"; |
39 | | - return 0; |
40 | | - } |
41 | | - } |
42 | | - |
43 | | - if (argc < 3) |
44 | | - { |
45 | | - std::cerr << "importer <poly.json> <geocoder-nlp database directory> " |
46 | | - "[postal_country_parser_code] [address_parser_directory] [verbose]\n"; |
47 | | - std::cerr |
48 | | - << "When using optional parameters, you have to specify all of the perceiving ones\n"; |
49 | | - return 1; |
50 | | - } |
51 | | - |
52 | | - std::string polyjson = argv[1]; |
53 | | - std::string database_path = argv[2]; |
| 34 | + std::string polyjson; |
| 35 | + std::string database_path; |
54 | 36 | std::string postal_country_parser; |
55 | 37 | std::string postal_address_parser_dir; |
56 | 38 | bool verbose_address_expansion = false; |
57 | 39 |
|
58 | | - if (argc > 3) |
59 | | - postal_country_parser = argv[3]; |
60 | | - if (argc > 4) |
61 | | - postal_address_parser_dir = argv[4]; |
62 | | - if (argc > 5 && strcmp("verbose", argv[5]) == 0) |
63 | | - verbose_address_expansion = true; |
| 40 | + { |
| 41 | + po::options_description generic("Geocoder NLP importer options"); |
| 42 | + generic.add_options()("help", "Help message")("version,v", "Data format version")( |
| 43 | + "poly,p", po::value<std::string>(&polyjson), |
| 44 | + "Boundary of the imported region in GeoJSON format")( |
| 45 | + "postal-country", po::value<std::string>(&postal_country_parser), |
| 46 | + "libpostal country preference for this database")( |
| 47 | + "postal-address", po::value<std::string>(&postal_address_parser_dir), |
| 48 | + "libpostal address parser directory. If not specified, global libpostal parser directory " |
| 49 | + "preference is used.")("verbose", "Verbose address expansion"); |
| 50 | + |
| 51 | + po::options_description hidden("Hidden options"); |
| 52 | + hidden.add_options()("output-directory", po::value<std::string>(&database_path), |
| 53 | + "Output directory for imported database"); |
| 54 | + |
| 55 | + po::positional_options_description p; |
| 56 | + p.add("output-directory", 1); |
| 57 | + |
| 58 | + po::options_description cmdline_options; |
| 59 | + cmdline_options.add(generic).add(hidden); |
| 60 | + |
| 61 | + po::variables_map vm; |
| 62 | + po::store(po::command_line_parser(argc, argv).options(cmdline_options).positional(p).run(), vm); |
| 63 | + po::notify(vm); |
| 64 | + |
| 65 | + if (vm.count("help")) |
| 66 | + { |
| 67 | + std::cout << "Geocoder NLP importer:\n\n" |
| 68 | + << "Call as\n\n " << argv[0] << " <options> output-directory\n" |
| 69 | + << "\nwhere output-directory is a directory for imported database.\n\n" |
| 70 | + << generic << "\n"; |
| 71 | + return 0; |
| 72 | + } |
| 73 | + |
| 74 | + if (vm.count(("version"))) |
| 75 | + { |
| 76 | + std::cout << GeoNLP::Geocoder::version << "\n"; |
| 77 | + return 0; |
| 78 | + } |
| 79 | + |
| 80 | + if (vm.count("verbose")) |
| 81 | + verbose_address_expansion = true; |
| 82 | + |
| 83 | + if (!vm.count("poly")) |
| 84 | + { |
| 85 | + std::cerr << "Boundary of the imported region in GeoJSON format is missing\n"; |
| 86 | + return -1; |
| 87 | + } |
| 88 | + } |
64 | 89 |
|
65 | 90 | // load GeoJSON for surrounding (multi)polygon from poly.json |
66 | 91 | std::string border; |
|
0 commit comments