From c00b7a613cebfb7950166954eed628c4697617bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ricardo=20Monta=C3=B1ana?= Date: Tue, 28 Feb 2023 10:52:26 +0100 Subject: [PATCH] Add path argument to command line --- sample/sample.cpp | 32 ++++++++++++++++++++------------ 1 file changed, 20 insertions(+), 12 deletions(-) diff --git a/sample/sample.cpp b/sample/sample.cpp index 5d1ad71..cb0d8fb 100644 --- a/sample/sample.cpp +++ b/sample/sample.cpp @@ -21,24 +21,27 @@ void usage(const char* path) cout << "usage: " << basename << "[OPTION]" << endl; cout << " -h, --help\t\t Print this help and exit." << endl; cout << " -f, --file[=FILENAME]\t {all, glass, iris, kdd_JapaneseVowels, letter, liver-disorders, mfeat-factors, test}." << endl; + cout << " -p, --path[=FILENAME]\t folder where the arff dataset is located, default " << PATH << endl; cout << " -m, --max_depth=INT\t max_depth pased to discretizer. Default = MAX_INT" << endl; cout << " -n, --min_length=INT\t interval min_length pased to discretizer. Default = 3" << endl; } -tuple parse_arguments(int argc, char** argv) +tuple parse_arguments(int argc, char** argv) { string file_name; + string path = PATH; int max_depth = numeric_limits::max(); int min_length = 3; static struct option long_options[] = { { "help", no_argument, 0, 'h' }, { "file", required_argument, 0, 'f' }, + { "path", required_argument, 0, 'p' }, { "max_depth", required_argument, 0, 'm' }, { "min_length", required_argument, 0, 'n' }, { 0, 0, 0, 0 } }; while (1) { - auto c = getopt_long(argc, argv, "hf:m:n:", long_options, 0); + auto c = getopt_long(argc, argv, "hf:p:m:n:", long_options, 0); if (c == -1) break; switch (c) { @@ -54,6 +57,11 @@ tuple parse_arguments(int argc, char** argv) case 'n': min_length = atoi(optarg); break; + case 'p': + path = optarg; + if (path.back() != '/') + path += '/'; + break; case '?': usage(argv[0]); exit(1); @@ -65,14 +73,14 @@ tuple parse_arguments(int argc, char** argv) usage(argv[0]); exit(1); } - return make_tuple(file_name, max_depth, min_length); + return make_tuple(file_name, path, max_depth, min_length); } -void process_file(string file_name, bool class_last, int max_depth, int min_length) +void process_file(string path, string file_name, bool class_last, int max_depth, int min_length) { ArffFiles file; - file.load(PATH + file_name + ".arff", class_last); + file.load(path + file_name + ".arff", class_last); auto attributes = file.getAttributes(); int items = file.getSize(); cout << "Number of lines: " << items << endl; @@ -108,14 +116,14 @@ void process_file(string file_name, bool class_last, int max_depth, int min_leng cout << "Total feature states: " << total + attributes.size() << endl; } -void process_all_files(map datasets, int max_depth, int min_length) +void process_all_files(map datasets, string path, int max_depth, int min_length) { cout << "Results: " << "Max_depth: " << max_depth << " Min_length: " << min_length << endl << endl; printf("%-20s %4s %4s\n", "Dataset", "Feat", "Cuts Time(s)"); printf("==================== ==== ==== =======\n"); for (auto dataset : datasets) { ArffFiles file; - file.load(PATH + dataset.first + ".arff", dataset.second); + file.load(path + dataset.first + ".arff", dataset.second); auto attributes = file.getAttributes(); vector& X = file.getX(); labels_t& y = file.getY(); @@ -145,21 +153,21 @@ int main(int argc, char** argv) {"mfeat-factors", true}, {"test", true} }; - string file_name; + string file_name, path; int max_depth, min_length; - tie(file_name, max_depth, min_length) = parse_arguments(argc, argv); + tie(file_name, path, max_depth, min_length) = parse_arguments(argc, argv); if (datasets.find(file_name) == datasets.end() && file_name != "all") { cout << "Invalid file name: " << file_name << endl; usage(argv[0]); exit(1); } if (file_name == "all") - process_all_files(datasets, max_depth, min_length); + process_all_files(datasets, path, max_depth, min_length); else { - process_file(file_name, datasets[file_name], max_depth, min_length); + process_file(path, file_name, datasets[file_name], max_depth, min_length); cout << "File name: " << file_name << endl; cout << "Max depth: " << max_depth << endl; cout << "Min length: " << min_length << endl; } return 0; -} +} \ No newline at end of file