readme.md

ParamsMap

This class implements a simple command line parser which also stores command line parameters in a simple data structure accessible through a get method.

Example of usage

ParamsMap pmap;    // Instantiate the class

pmap.addMessage("\nHelp options:");    // This is not an actual option, it's used for the help message only
pmap.addOption("help", "h", "print help message");    // This is a flag, i.e., an option without arguments

pmap.addMessage("\nTraining Options:");
// below an option with a string argument and a default value. Note: only the long name is mandatory
pmap.addOptionWithArg("algo", "LtR algorithm [MART|LAMBDAMART]",std::string("LAMBDAMART"));
pmap.addOptionWithArg<std::string>("train", "Training dataset");    // This is an option of type string without default value

pmap.addMessage("\nTraining options for tree-based models:");
pmap.addOptionWithArg("num-trees", "Number of trees in the ensemble", 100);    // The argument is of type int

bool parse_status = pmap.parse(argc, argv);    // parse the command line and immediately check that everything is fine
if (!parse_status || pmap.isSet("help")) 
    std::cout << pmap.help();                  // print help message

std::cout << "count of train " << pmap.count("train") << std::endl;              // get options' arguments
std::cout << "param of train " << pmap.get<std::string>("train") << std::endl;
std::cout << "param of algo " << pmap.get<std::string>("algo") << std::endl;
std::cout << "param of num trees " << pmap.get<int>("num-trees") << std::endl;

References

ParamsMap is used in:

  • QuickRank: A C++ suite of Learning to Rank algorithms

Licence

© Contributors, 2016. Licensed under MIT LIcense.