From bbe8d057f1d5e67c60c5d5da45098bbfdf30b9a8 Mon Sep 17 00:00:00 2001 From: Ahmad Alobaid Date: Tue, 21 Feb 2023 05:46:23 +0300 Subject: [PATCH] run main in command line --- src/main.cpp | 163 +++++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 133 insertions(+), 30 deletions(-) diff --git a/src/main.cpp b/src/main.cpp index 8d91956..a98f8f8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,49 +1,152 @@ #include +#include #include #include "entity.h" #include +using namespace GetOpt; using namespace hdt; -int main() { + + +void print_options() { + cout << "Options: \n"; + cout << "\t-h --hdt \n"; + cout << "\t-f --file \n"; + cout << "\t-c --subject-col \n"; + cout << "\t-g --lang-tag \n"; + cout << "\t-t --title \n"; + cout << "\t-l --log \n"; + cout << "\t--label-uris \n"; +} + +std::vector *get_list_args_long(GetOpt_pp *ops_ptr, string arg_label) { + std::vector *vec = new std::vector(); + + for (GetOpt_pp::long_iterator it = ops_ptr->begin(); it != ops_ptr->end(); ++it) { + if (*it != arg_label) { + continue; + } + + it >> (*vec); + } + + return vec; +} + +int main(int argc, char **argv) { + GetOpt_pp ops(argc, argv); + + print_options(); + + std::vector *label_uris = nullptr; + string file_dir, hdt_path, lang_tag, col_id_str, title_case, log_path, sample_size_str; + ops >> Option('h', "hdt", hdt_path, ""); + ops >> Option('f', "file", file_dir, ""); + ops >> Option('c', "subject-col", col_id_str, "0"); + ops >> Option('g', "lang-tag", lang_tag, ""); + ops >> Option('t', "title", title_case, "no"); + ops >> Option('s', "sample", sample_size_str, "0"); + ops >> Option('l', "log", log_path, "entity.log"); + label_uris = get_list_args_long(&ops, "label-uris"); + + std::list *candidates; - cout << "Hello!" << endl; -// string file_dir1="/Users/aalobaid/workspaces/Pyworkspace/tada-gam/local_data/t2dv2/5873256_0_7795190905731964989.csv"; -// string file_dir2 = "/Users/aalobaid/workspaces/Pyworkspace/tada-gam/local_data/t2dv2/86747932_0_7532457067740920052.csv"; - int col_idx = 0; - string m_hdt = "/Users/aalobaid/workspaces/Datasets/Bigg/biggv1.hdt"; - string fdir = "/Users/aalobaid/Downloads/a.csv"; - EntityAnn *ea = new EntityAnn(m_hdt, "entity.log"); - ea->set_title_case(true); - Parser p(fdir); - ea->clear_label_uri(); - ea->append_label_uri("http://www.w3.org/2004/02/skos/core#prefLabel"); + int col_idx, sample_size; + + col_idx = stoi(col_id_str); + sample_size = stoi(sample_size_str); + + EntityAnn *ea = new EntityAnn(hdt_path, log_path); + ea->set_title_case(title_case == "yes"); + + if (lang_tag != "") { + ea->set_language_tag("@" + lang_tag); + } + + Parser p(file_dir); + + if (label_uris != nullptr && label_uris->size() > 0) { + ea->clear_label_uri(); + + for (auto it = label_uris->cbegin(); it != label_uris->cend(); it++) { + ea->append_label_uri(*it); + } + } + candidates = ea->annotate_column(p.parse_vertical(), col_idx, true, true); + cout << "Number of candidates: " << candidates->size() << "\n"; + for (auto it = candidates->cbegin(); it != candidates->cend(); it++) { cout << "Candidate: " << *it << endl; } - //ea->set_language_tag("@en"); -// ea->set_title_case(true); -// ea->set_language_tag("@en"); +// ea->set_language_tag("@en"); + // ea->set_title_case(true); + // ea->set_language_tag("@en"); -// Parser p(file_dir1); -// cout << "file_dir: "<annotate_column(p.parse_vertical(), col_idx, true, true); - -// Parser p2(file_dir2); -// cout << "file_dir2: "<annotate_column(p2.parse_vertical(), col_idx, true, true); + // Parser p(file_dir1); + // cout << "file_dir: "<annotate_column(p.parse_vertical(), col_idx, true, true); + // Parser p2(file_dir2); + // cout << "file_dir2: "<annotate_column(p2.parse_vertical(), col_idx, true, true); return 0; } + +//int main() { + +// std::list *candidates; +// cout << "Hello!" << endl; +//// string file_dir1="/Users/aalobaid/workspaces/Pyworkspace/tada-gam/local_data/t2dv2/5873256_0_7795190905731964989.csv"; +//// string file_dir2 = "/Users/aalobaid/workspaces/Pyworkspace/tada-gam/local_data/t2dv2/86747932_0_7532457067740920052.csv"; +// int col_idx = 0; +// string m_hdt = "/Users/aalobaid/workspaces/Datasets/Bigg/biggv1.hdt"; +// string fdir = "/Users/aalobaid/Downloads/a.csv"; +// EntityAnn *ea = new EntityAnn(m_hdt, "entity.log"); +// ea->set_title_case(true); +// Parser p(fdir); +// ea->clear_label_uri(); +// ea->append_label_uri("http://www.w3.org/2004/02/skos/core#prefLabel"); +// candidates = ea->annotate_column(p.parse_vertical(), col_idx, true, true); + +// for (auto it = candidates->cbegin(); it != candidates->cend(); it++) { +// cout << "Candidate: " << *it << endl; +// } + +// //ea->set_language_tag("@en"); +//// ea->set_title_case(true); +//// ea->set_language_tag("@en"); + +//// Parser p(file_dir1); +//// cout << "file_dir: "<annotate_column(p.parse_vertical(), col_idx, true, true); + +//// Parser p2(file_dir2); +//// cout << "file_dir2: "<annotate_column(p2.parse_vertical(), col_idx, true, true); + + +// return 0; +//} +