Skip to content

Commit

Permalink
Added a debug mode which can be accessed by -d or --debug
Browse files Browse the repository at this point in the history
  • Loading branch information
khannatanmai committed Aug 20, 2019
1 parent 0c0674e commit ae3a623
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 18 deletions.
24 changes: 12 additions & 12 deletions src/anaphora.cc
Expand Up @@ -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;
Expand All @@ -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)
Expand All @@ -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;
Expand All @@ -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)
Expand Down Expand Up @@ -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
}
Expand Down
22 changes: 17 additions & 5 deletions src/score.cc
Expand Up @@ -185,23 +185,35 @@ int Scoring::check_agreement(vector<wstring> antecedent_tags, vector<wstring> 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<antecedent>::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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/score.h
Expand Up @@ -41,7 +41,7 @@ class Scoring
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<wstring> antecedent_tags, vector<wstring> anaphor_tags);
wstring get_antecedent();
wstring get_antecedent(int debug_flag);
void clear();
};

Expand Down

0 comments on commit ae3a623

Please sign in to comment.