| 1 | #include <stdlib.h> | 
|---|
| 2 | #include <ctype.h> | 
|---|
| 3 | #include "../lib/iotools.h" | 
|---|
| 4 | #include "common_cor.h" | 
|---|
| 5 | #include "corr.hh" | 
|---|
| 6 | #include <locale.h> | 
|---|
| 7 |  | 
|---|
| 8 |  | 
|---|
| 9 | int main(int argc, char** argv) { | 
|---|
| 10 |  | 
|---|
| 11 | //   setlocale(LC_CTYPE,""); | 
|---|
| 12 | //   setlocale(LC_COLLATE,""); | 
|---|
| 13 |  | 
|---|
| 14 | gengetopt_args_info args; | 
|---|
| 15 |  | 
|---|
| 16 | if(cmdline_parser(argc, argv, &args) != 0) | 
|---|
| 17 | exit(1); | 
|---|
| 18 |  | 
|---|
| 19 | process_config_files(&args,argv[0]); | 
|---|
| 20 | process_common_options(&args,argv[0]); | 
|---|
| 21 | process_cor_options(&args); | 
|---|
| 22 |  | 
|---|
| 23 | Corr cor; | 
|---|
| 24 |  | 
|---|
| 25 | //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! | 
|---|
| 26 | //  strcpy(dictionary,"cor.bin"); | 
|---|
| 27 |  | 
|---|
| 28 | cor.load(dictionary); | 
|---|
| 29 | cor.t=args.distance_arg; | 
|---|
| 30 |  | 
|---|
| 31 | //>>>>>>>>>>>>>>> | 
|---|
| 32 | cor.CL.cor_stdcor=1*PREC; | 
|---|
| 33 | cor.CL.cor_xchg=1*PREC; | 
|---|
| 34 | if (cor.load2(file_weights)==-1) return -1;  // moje | 
|---|
| 35 | cor.t=1*PREC; // ODLEGLOSC EDYCYJNA | 
|---|
| 36 | //<<<<<<<<<<<<<< | 
|---|
| 37 |  | 
|---|
| 38 | char line[MAX_LINE+1]; | 
|---|
| 39 | long line_count = 0; | 
|---|
| 40 |  | 
|---|
| 41 | Segment seg; | 
|---|
| 42 | Words tab; | 
|---|
| 43 | char form1[MAX_LINE]; | 
|---|
| 44 | char* form; | 
|---|
| 45 | int formcasing; | 
|---|
| 46 | char corfield[MAX_LINE]=""; | 
|---|
| 47 |  | 
|---|
| 48 | while (fgets(line, MAX_LINE, inputf)) | 
|---|
| 49 | { | 
|---|
| 50 | ++line_count; | 
|---|
| 51 | char outline[128]; | 
|---|
| 52 |  | 
|---|
| 53 | if (!process_seg(line, args)) | 
|---|
| 54 | fputs(line, outputf); | 
|---|
| 55 | else | 
|---|
| 56 | { | 
|---|
| 57 | char form[MAX_FORM]; | 
|---|
| 58 |  | 
|---|
| 59 | tab.clear(); | 
|---|
| 60 | getfield(line,input_field_prefix,form); | 
|---|
| 61 | if (form==NULL) continue; | 
|---|
| 62 |  | 
|---|
| 63 | formcasing=3; | 
|---|
| 64 | cor.correct(form, tab); | 
|---|
| 65 |  | 
|---|
| 66 | if( tab.count() == 0 ) | 
|---|
| 67 | { | 
|---|
| 68 | formcasing=casing(form); | 
|---|
| 69 | if( formcasing == 1 || formcasing == 2) | 
|---|
| 70 | tolowers(form, form1), cor.correct(form1, tab); | 
|---|
| 71 | } | 
|---|
| 72 |  | 
|---|
| 73 | if ( tab.count() == 0) | 
|---|
| 74 | fputs(line, failedf); | 
|---|
| 75 | else | 
|---|
| 76 | { | 
|---|
| 77 | tab.sort(); | 
|---|
| 78 |  | 
|---|
| 79 | if(args.replace_flag) | 
|---|
| 80 | { | 
|---|
| 81 | char corfield[128]; | 
|---|
| 82 | strcpy(corfield, input_field_prefix); | 
|---|
| 83 | strcat(corfield, form); | 
|---|
| 84 | seg.aux[seg.auxn]=corfield; | 
|---|
| 85 | ++seg.auxn; | 
|---|
| 86 | for(int i=0; i<tab.count(); ++i) | 
|---|
| 87 | { | 
|---|
| 88 | seg.form=tab[i].form(); | 
|---|
| 89 | restorecasing(seg.form,seg.form,formcasing); | 
|---|
| 90 | seg.print(outline); | 
|---|
| 91 | fputs(outline, outputf); | 
|---|
| 92 | } | 
|---|
| 93 | --seg.auxn; | 
|---|
| 94 | } | 
|---|
| 95 | else | 
|---|
| 96 | { | 
|---|
| 97 | if(one_line) | 
|---|
| 98 | { | 
|---|
| 99 | char* p=corfield; | 
|---|
| 100 | for(int i=tab.count()-1; i >= 0; --i) | 
|---|
| 101 | { | 
|---|
| 102 | if(tab[i].w_suf() > threshold) continue; | 
|---|
| 103 | restorecasing(tab[i].form(),tab[i].form(),formcasing); | 
|---|
| 104 | p += sprintf(p," %s%s,%1.2f",output_field_prefix,tab[i].form(),tab[i].w_suf()); | 
|---|
| 105 | } | 
|---|
| 106 | sprintf(p,"\n"); | 
|---|
| 107 |  | 
|---|
| 108 | strcpy(outline,line); | 
|---|
| 109 | outline[strlen(outline)-1]='\0'; | 
|---|
| 110 | strcat(outline,corfield); | 
|---|
| 111 | fputs(outline, outputf); | 
|---|
| 112 | } | 
|---|
| 113 | else if(one_field) | 
|---|
| 114 | { | 
|---|
| 115 | char* p=corfield; | 
|---|
| 116 | p += sprintf(p," %s",output_field_prefix); | 
|---|
| 117 | for(int i=tab.count()-1; i >= 0; --i) | 
|---|
| 118 | { | 
|---|
| 119 | if(tab[i].w_suf() > threshold) continue; | 
|---|
| 120 | restorecasing(tab[i].form(),tab[i].form(),formcasing); | 
|---|
| 121 | p += sprintf(p,(i==0)?"%s,%1.2f":";%s,%1.2f",tab[i].form(),tab[i].w_suf()); | 
|---|
| 122 | } | 
|---|
| 123 |  | 
|---|
| 124 | sprintf(p,"\n"); | 
|---|
| 125 |  | 
|---|
| 126 | strcpy(outline,line); | 
|---|
| 127 | outline[strlen(outline)-1]='\0'; | 
|---|
| 128 | strcat(outline,corfield); | 
|---|
| 129 | fputs(outline, outputf); | 
|---|
| 130 | } | 
|---|
| 131 | else | 
|---|
| 132 | { | 
|---|
| 133 | for(int i=tab.count()-1; i >= 0; --i) | 
|---|
| 134 | { | 
|---|
| 135 | if(tab[i].w_suf() > threshold) continue; | 
|---|
| 136 | restorecasing(tab[i].form(),tab[i].form(),formcasing); | 
|---|
| 137 | sprintf(corfield," %s%s,%1.2f\n",output_field_prefix,tab[i].form(),tab[i].w_suf()); | 
|---|
| 138 | strcpy(outline,line); | 
|---|
| 139 | outline[strlen(outline)-1]='\0'; | 
|---|
| 140 | strcat(outline,corfield); | 
|---|
| 141 | fputs(outline, outputf); | 
|---|
| 142 | } | 
|---|
| 143 | } | 
|---|
| 144 | } | 
|---|
| 145 | } | 
|---|
| 146 | } | 
|---|
| 147 |  | 
|---|
| 148 | if(args.interactive_flag) | 
|---|
| 149 | { | 
|---|
| 150 | fflush(outputf); | 
|---|
| 151 | fflush(failedf); | 
|---|
| 152 | } | 
|---|
| 153 | } | 
|---|
| 154 | cmdline_parser_free(&args); | 
|---|
| 155 | } | 
|---|