commit ae3a62382b9ad56feee62e56c45ea687ed3ba360 Author: Tanmai Khanna Date: Wed Aug 21 03:23:13 2019 +0530 Added a debug mode which can be accessed by -d or --debug diff --git a/src/anaphora.cc b/src/anaphora.cc index a11ae4f..3a75dc6 100644 --- a/src/anaphora.cc +++ b/src/anaphora.cc @@ -76,10 +76,12 @@ void help_message(char *progname) exit(EXIT_FAILURE); } -static int debug_flag; //flag set by --debug + int main(int argc, char **argv) { + int debug_flag = 0; //flag set by --debug + char *arxFileName = nullptr; int nullFlush = 0; @@ -92,16 +94,16 @@ int main(int argc, char **argv) { static struct option long_options[] = { - {"debug", no_argument, &debug_flag, 1}, - {"null-flush", no_argument, 0, 'z'}, - {"help", no_argument, 0, 'h'}, + {"debug", no_argument, 0, 'd'}, + {"null-flush", no_argument, 0, 'z'}, + {"help", no_argument, 0, 'h'}, {0, 0, 0, 0} }; /* getopt_long stores the option index here. */ int option_index = 0; - c = getopt_long (argc, argv, "zh", long_options, &option_index); + c = getopt_long (argc, argv, "dzh", long_options, &option_index); /* Detect the end of the options. */ if (c == -1) @@ -110,15 +112,16 @@ int main(int argc, char **argv) switch (c) { case 0: - /* If this option set a flag, do nothing else now. */ - if (long_options[option_index].flag != 0) - break; fprintf (stderr, "option %s", long_options[option_index].name); if (optarg) fprintf (stderr, " with arg %s", optarg); fprintf (stderr, "\n"); break; + case 'd': + debug_flag = 1; + break; + case 'z': nullFlush = 1; break; @@ -134,9 +137,6 @@ int main(int argc, char **argv) } } - if(debug_flag) - fprintf(stderr, "Debug Flag is set.\n"); - FILE *input = stdin, *output = stdout; switch(argc - optind) @@ -256,7 +256,7 @@ int main(int argc, char **argv) //If retval is 1, we call get_antecedent() and add it to ref if(retval == 1) { - final_ref = score_module.get_antecedent(); + final_ref = score_module.get_antecedent(debug_flag); fputws(final_ref.c_str(), output); //add antecedent to side ref of LU } diff --git a/src/score.cc b/src/score.cc index c3da674..ff0f101 100644 --- a/src/score.cc +++ b/src/score.cc @@ -185,23 +185,35 @@ int Scoring::check_agreement(vector antecedent_tags, vector an } -wstring Scoring::get_antecedent() +wstring Scoring::get_antecedent(int debug_flag) { unique_LU final_antecedent_LU; antecedent final_antecedent = {final_antecedent_LU, -5}; for(vector::iterator it=antecedent_list.begin();it!=antecedent_list.end();++it) //read from furthest to nearest { - //cerr << "\n" << (*it).LU.id << ": "; //for debugging - //fputws((*it).LU.wordform.c_str(), stderr); - //cerr << " : " << (*it).score << "\n"; - + if(debug_flag) + { + cerr << "\n" << (*it).LU.id << ": "; + fputws((*it).LU.wordform.c_str(), stderr); + cerr << " : " << (*it).score << "\n"; + } + if((*it).score >= final_antecedent.score) //picking the highest scored and latest added (most recent) antecedent final_antecedent = (*it); } antecedent_list.clear(); + if(debug_flag) + { + cerr << "\n" << "Final Antecedent: "; + fputws(final_antecedent.LU.wordform.c_str(), stderr); + cerr << "/"; + fputws(final_antecedent.LU.tl_wordform.c_str(), stderr); + cerr << "\n"; + } + return final_antecedent.LU.tl_wordform; } diff --git a/src/score.h b/src/score.h index ddba92a..8e54deb 100644 --- a/src/score.h +++ b/src/score.h @@ -41,7 +41,7 @@ public: int add_word(unsigned int input_id, wstring input_wordform, vector< wstring > pos_tags, wstring input_tl_wordform, ParseArx arx_file); void apply_indicators(unique_LU anaphor, ParseArx arx_file); int check_agreement(vector antecedent_tags, vector anaphor_tags); - wstring get_antecedent(); + wstring get_antecedent(int debug_flag); void clear(); };