diff --git a/app/src/kor/cmdline_cor.ggo b/app/src/kor/cmdline_cor.ggo index 8b1c93a..3738d59 100755 --- a/app/src/kor/cmdline_cor.ggo +++ b/app/src/kor/cmdline_cor.ggo @@ -3,8 +3,11 @@ version "0.1" option "dictionary-home" - "Dictionary home dir." string typestr="FILENAME" no hidden option "dictionary" d "Dictionary" string typestr="FILENAME" default="cor.bin" no -option "distance" n "Maximal edit distance." int default="1" no +option "distance" D "Maximal edit distance." int default="1" no option "replace" r "Replace original form with corrected form, place original form in the cor field. This option has no effect in single mode" flag off #option "single" - "Place all alternatives in the same line" flag off option "weights" w "File with translation rules." string typestr="FILENAME" default="weight.cor" no -option "threshold" t "Edit distance threshold" float default="1" no \ No newline at end of file +option "threshold" t "Edit distance threshold" float default="1" no +option "show-scores" - "Show scores" flag off +option "count" n "Print only count best results" int no + diff --git a/app/src/kor/common_cor.cc b/app/src/kor/common_cor.cc index 98a586a..a302135 100755 --- a/app/src/kor/common_cor.cc +++ b/app/src/kor/common_cor.cc @@ -7,6 +7,8 @@ char dictionary[MAX_PATH_LENGTH]; char file_weights[MAX_PATH_LENGTH]; float threshold; +bool show_scores = false; +int result_count; void process_cor_options(gengetopt_args_info* args) { @@ -24,4 +26,13 @@ void process_cor_options(gengetopt_args_info* args) expand_path(args->weights_arg, file_weights); threshold = args->threshold_arg; + + show_scores = args->show_scores_flag; + + if(args->count_given) { + result_count = args->count_arg; + } + else { + result_count = 0; + } } diff --git a/app/src/kor/common_cor.h b/app/src/kor/common_cor.h index 3ff675e..f6f0dff 100755 --- a/app/src/kor/common_cor.h +++ b/app/src/kor/common_cor.h @@ -21,6 +21,8 @@ extern void process_cor_options(gengetopt_args_info* args); extern char dictionary[]; extern char file_weights[]; extern float threshold; +extern bool show_scores; +extern int result_count; #endif diff --git a/app/src/kor/main.cc b/app/src/kor/main.cc index 4ff051f..8095c7b 100755 --- a/app/src/kor/main.cc +++ b/app/src/kor/main.cc @@ -76,6 +76,14 @@ int main(int argc, char** argv) { { tab.sort(); + int max_cnt = 0; + if(result_count < 1) { + max_cnt = tab.count(); + } + else { + max_cnt = (tab.count() < result_count) ? tab.count() : result_count; + } + if(args.replace_flag) { char corfield[128]; @@ -97,11 +105,14 @@ int main(int argc, char** argv) { if(one_line) { char* p=corfield; - for(int i=tab.count()-1; i >= 0; --i) + for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i) { if(tab[i].w_suf() > threshold) continue; restorecasing(tab[i].form(),tab[i].form(),formcasing); - p += sprintf(p," %s%s,%1.2f",output_field_prefix,tab[i].form(),tab[i].w_suf()); + p += sprintf(p," %s%s",output_field_prefix,tab[i].form()); + if(show_scores) { + p += sprintf(p,",%1.2f",tab[i].w_suf()); + } } sprintf(p,"\n"); @@ -114,11 +125,14 @@ int main(int argc, char** argv) { { char* p=corfield; p += sprintf(p," %s",output_field_prefix); - for(int i=tab.count()-1; i >= 0; --i) + for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i) { if(tab[i].w_suf() > threshold) continue; restorecasing(tab[i].form(),tab[i].form(),formcasing); - p += sprintf(p,(i==0)?"%s,%1.2f":";%s,%1.2f",tab[i].form(),tab[i].w_suf()); + p += sprintf(p,(i==0)?"%s":";%s",tab[i].form()); + if(show_scores) { + p += sprintf(p,",%1.2f",tab[i].w_suf()); + } } sprintf(p,"\n"); @@ -130,11 +144,16 @@ int main(int argc, char** argv) { } else { - for(int i=tab.count()-1; i >= 0; --i) + for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i) { if(tab[i].w_suf() > threshold) continue; restorecasing(tab[i].form(),tab[i].form(),formcasing); - sprintf(corfield," %s%s,%1.2f\n",output_field_prefix,tab[i].form(),tab[i].w_suf()); + char* p = corfield; + p += sprintf(p," %s%s",output_field_prefix,tab[i].form()); + if(show_scores) { + p += sprintf(p,",%1.2f",tab[i].w_suf()); + } + p += sprintf(p, "\n"); strcpy(outline,line); outline[strlen(outline)-1]='\0'; strcat(outline,corfield);