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 | cor.load(dictionary); |
---|
26 | cor.t=args.distance_arg; |
---|
27 | |
---|
28 | //>>>>>>>>>>>>>>> |
---|
29 | cor.CL.cor_stdcor=1*PREC; |
---|
30 | cor.CL.cor_xchg=1*PREC; |
---|
31 | if (cor.load2(file_weights)==-1) return -1; // moje |
---|
32 | cor.t=1*PREC; // ODLEGLOSC EDYCYJNA |
---|
33 | //<<<<<<<<<<<<<< |
---|
34 | |
---|
35 | char line[MAX_LINE+1]; |
---|
36 | long line_count = 0; |
---|
37 | |
---|
38 | Segment seg; |
---|
39 | Words tab; |
---|
40 | char form1[MAX_LINE]; |
---|
41 | char* form; |
---|
42 | int formcasing; |
---|
43 | char corfield[MAX_LINE]=""; |
---|
44 | |
---|
45 | while (fgets(line, MAX_LINE, inputf)) |
---|
46 | { |
---|
47 | ++line_count; |
---|
48 | char outline[128]; |
---|
49 | |
---|
50 | if (!process_seg(line, args)) |
---|
51 | fputs(line, outputf); |
---|
52 | else |
---|
53 | { |
---|
54 | char form[MAX_FORM]; |
---|
55 | |
---|
56 | tab.clear(); |
---|
57 | getfield(line,input_field_prefix,form); |
---|
58 | if (form==NULL) continue; |
---|
59 | |
---|
60 | formcasing=3; |
---|
61 | cor.correct(form, tab); |
---|
62 | |
---|
63 | if( tab.count() == 0 ) |
---|
64 | { |
---|
65 | formcasing=casing(form); |
---|
66 | if( formcasing == 1 || formcasing == 2) |
---|
67 | tolowers(form, form1), cor.correct(form1, tab); |
---|
68 | } |
---|
69 | |
---|
70 | if ( tab.count() == 0) |
---|
71 | fputs(line, inputf); |
---|
72 | else |
---|
73 | { |
---|
74 | tab.sort(); |
---|
75 | |
---|
76 | int max_cnt = 0; |
---|
77 | if(result_count < 1) { |
---|
78 | max_cnt = tab.count(); |
---|
79 | } |
---|
80 | else { |
---|
81 | max_cnt = (tab.count() < result_count) ? tab.count() : result_count; |
---|
82 | } |
---|
83 | |
---|
84 | if(args.replace_flag) |
---|
85 | { |
---|
86 | char corfield[128]; |
---|
87 | strcpy(corfield, input_field_prefix); |
---|
88 | strcat(corfield, form); |
---|
89 | seg.aux[seg.auxn]=corfield; |
---|
90 | ++seg.auxn; |
---|
91 | for(int i=0; i<tab.count(); ++i) |
---|
92 | { |
---|
93 | seg.form=tab[i].form(); |
---|
94 | restorecasing(seg.form,seg.form,formcasing); |
---|
95 | seg.print(outline); |
---|
96 | fputs(outline, outputf); |
---|
97 | } |
---|
98 | --seg.auxn; |
---|
99 | } |
---|
100 | else |
---|
101 | { |
---|
102 | if(one_line) |
---|
103 | { |
---|
104 | char* p=corfield; |
---|
105 | for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i) |
---|
106 | { |
---|
107 | if(tab[i].w_suf() > threshold) continue; |
---|
108 | restorecasing(tab[i].form(),tab[i].form(),formcasing); |
---|
109 | p += sprintf(p," %s%s",output_field_prefix,tab[i].form()); |
---|
110 | if(show_scores) { |
---|
111 | p += sprintf(p,",%1.2f",tab[i].w_suf()); |
---|
112 | } |
---|
113 | } |
---|
114 | sprintf(p,"\n"); |
---|
115 | |
---|
116 | strcpy(outline,line); |
---|
117 | outline[strlen(outline)-1]='\0'; |
---|
118 | strcat(outline,corfield); |
---|
119 | fputs(outline, outputf); |
---|
120 | } |
---|
121 | else if(one_field) |
---|
122 | { |
---|
123 | char* p=corfield; |
---|
124 | p += sprintf(p," %s",output_field_prefix); |
---|
125 | for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i) |
---|
126 | { |
---|
127 | if(tab[i].w_suf() > threshold) continue; |
---|
128 | restorecasing(tab[i].form(),tab[i].form(),formcasing); |
---|
129 | p += sprintf(p,(i==0)?"%s":";%s",tab[i].form()); |
---|
130 | if(show_scores) { |
---|
131 | p += sprintf(p,",%1.2f",tab[i].w_suf()); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | sprintf(p,"\n"); |
---|
136 | |
---|
137 | strcpy(outline,line); |
---|
138 | outline[strlen(outline)-1]='\0'; |
---|
139 | strcat(outline,corfield); |
---|
140 | fputs(outline, outputf); |
---|
141 | } |
---|
142 | else |
---|
143 | { |
---|
144 | for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i) |
---|
145 | { |
---|
146 | if(tab[i].w_suf() > threshold) continue; |
---|
147 | restorecasing(tab[i].form(),tab[i].form(),formcasing); |
---|
148 | char* p = corfield; |
---|
149 | p += sprintf(p," %s%s",output_field_prefix,tab[i].form()); |
---|
150 | if(show_scores) { |
---|
151 | p += sprintf(p,",%1.2f",tab[i].w_suf()); |
---|
152 | } |
---|
153 | p += sprintf(p, "\n"); |
---|
154 | strcpy(outline,line); |
---|
155 | outline[strlen(outline)-1]='\0'; |
---|
156 | strcat(outline,corfield); |
---|
157 | fputs(outline, outputf); |
---|
158 | } |
---|
159 | } |
---|
160 | } |
---|
161 | } |
---|
162 | } |
---|
163 | |
---|
164 | if(args.interactive_flag) fflush(outputf); |
---|
165 | } |
---|
166 | cmdline_parser_free(&args); |
---|
167 | } |
---|