use program_options to parse command line args

This commit is contained in:
Hieu Hoang 2016-01-07 11:11:31 +00:00
parent bef1910c5e
commit 859705431a
3 changed files with 44 additions and 14 deletions

View File

@ -1,24 +1,54 @@
#include <string>
#include <boost/program_options.hpp>
#include "util/usage.hh"
#include "moses/TranslationModel/ProbingPT/storing.hh"
using namespace std;
int main(int argc, char* argv[])
{
if (!(argc == 5 || argc == 4)) {
// Tell the user how to run the program
std::cerr << "Provided " << argc << " arguments, needed 4 or 5." << std::endl;
std::cerr << "Usage: " << argv[0] << " path_to_phrasetable output_dir num_scores num_reordering_scores" << std::endl;
//std::cerr << "Usage: " << argv[0] << " path_to_phrasetable number_of_uniq_lines output_bin_file output_hash_table output_vocab_id" << std::endl;
return 1;
string inPath, outPath;
int num_scores = 4;
int num_lex_scores = 0;
namespace po = boost::program_options;
po::options_description desc("Options");
desc.add_options()
("help", "Print help messages")
("input-pt", po::value<string>()->required(), "Text pt")
("output-dir", po::value<string>()->required(), "Directory when binary files will be written")
("num-scores", po::value<int>()->default_value(num_scores), "Number of pt scores")
("num-lex-scores", po::value<int>()->default_value(num_lex_scores), "Number of lexicalized reordering scores")
;
po::variables_map vm;
try {
po::store(po::parse_command_line(argc, argv, desc),
vm); // can throw
/** --help option
*/
if ( vm.count("help")) {
std::cout << desc << std::endl;
return EXIT_SUCCESS;
}
po::notify(vm); // throws on error, so do after help in case
// there are any problems
} catch(po::error& e) {
std::cerr << "ERROR: " << e.what() << std::endl << std::endl;
std::cerr << desc << std::endl;
return EXIT_FAILURE;
}
int num_lex_scores = 0;
if (argc > 4) {
num_lex_scores = atoi(argv[4]);
}
if (vm.count("input-pt")) inPath = vm["input-pt"].as<string>();
if (vm.count("output-dir")) outPath = vm["output-dir"].as<string>();
if (vm.count("num-scores")) num_scores = vm["num-scores"].as<int>();
if (vm.count("num-lex-scores")) num_lex_scores = vm["num-lex-scores"].as<int>();
createProbingPT(argv[1], argv[2], argv[3], num_lex_scores);
createProbingPT(inPath.c_str(), outPath.c_str(), num_scores, num_lex_scores);
util::PrintUsage(std::cout);
return 0;

View File

@ -39,7 +39,7 @@ BinaryFileWriter::~BinaryFileWriter ()
}
void createProbingPT(const char * phrasetable_path, const char * target_path,
const char * num_scores, int num_lex_scores)
int num_scores, int num_lex_scores)
{
//Get basepath and create directory if missing
std::string basepath(target_path);

View File

@ -15,7 +15,7 @@
#define API_VERSION 5
void createProbingPT(const char * phrasetable_path, const char * target_path,
const char * num_scores, int num_lex_scores);
int num_scores, int num_lex_scores);
class BinaryFileWriter
{