[25ae32e] | 1 | #include <time.h> |
---|
| 2 | #include <stdlib.h> |
---|
| 3 | #include "../lib/iotools.h" |
---|
| 4 | #define _CMDLINE_FILE "../gue/cmdline.h" |
---|
| 5 | #define CONFIGFILE1 "/home/ynka/utt/utt-0.9/conf/gue.conf" |
---|
| 6 | #define CONFIGFILE2 "/home/ynka/utt/utt-0.9/conf/gue.conf" |
---|
| 7 | #include "../common/common.h" |
---|
| 8 | #include "common_guess.h" |
---|
| 9 | #include "guess.h" |
---|
| 10 | #include "cmdline.h" |
---|
| 11 | |
---|
| 12 | #define W_SUFF 0.6 |
---|
| 13 | #define W_PREF 0.4 |
---|
| 14 | |
---|
| 15 | int main(int argc, char** argv) { |
---|
| 16 | |
---|
[8abee07] | 17 | // int non_standard_config=0; |
---|
[25ae32e] | 18 | |
---|
| 19 | gengetopt_args_info args; |
---|
| 20 | |
---|
| 21 | if(cmdline_parser(argc, argv, &args) != 0) |
---|
| 22 | exit(1); |
---|
| 23 | |
---|
| 24 | process_config_files(&args,argv[0]); |
---|
| 25 | process_common_options(&args,argv[0]); |
---|
| 26 | process_guess_options(&args); |
---|
| 27 | |
---|
| 28 | |
---|
| 29 | // PONIŻEJ POPRZEDNI KOD (JUSTYNY) |
---|
| 30 | // //preliminary command-line parsing - for configuration file info only |
---|
| 31 | // gengetopt_args_info pre_args; |
---|
| 32 | |
---|
| 33 | // if (cmdline_parser(argc, argv, &pre_args) != 0) |
---|
| 34 | // exit(1); |
---|
| 35 | // if(pre_args.config_given){ |
---|
| 36 | // printf("podano config: %s\n",pre_args.config_arg); |
---|
| 37 | // non_standard_config=1; |
---|
| 38 | // } |
---|
| 39 | |
---|
| 40 | |
---|
| 41 | // //configuration file 1 parsing |
---|
| 42 | // struct cmdline_parser_params *params; |
---|
| 43 | // params = cmdline_parser_params_init(); |
---|
| 44 | // params->initialize = 1; |
---|
| 45 | // if(cmdline_parser_config_file(CONFIGFILE1,&args, params)!=0){ |
---|
| 46 | // printf("System-wide configuration file parsing error!\n"); |
---|
| 47 | // exit(1); |
---|
| 48 | // } |
---|
| 49 | |
---|
| 50 | // //configuration file 2 parsing-overriding |
---|
| 51 | // params->initialize=0; |
---|
| 52 | // params->override=1; |
---|
| 53 | // char* config2=(non_standard_config)?pre_args.config_arg:CONFIGFILE2; |
---|
| 54 | // if(cmdline_parser_config_file(config2,&args, params)!=0){ |
---|
| 55 | // printf("User configuration file parsing error!\n"); |
---|
| 56 | // return 1; |
---|
| 57 | // } |
---|
| 58 | |
---|
| 59 | // params->initialize=0; |
---|
| 60 | // params->override=1; |
---|
| 61 | // //params->check_required=1; |
---|
| 62 | |
---|
| 63 | // free(params); |
---|
| 64 | |
---|
| 65 | // //command-line options parsing-overriding |
---|
| 66 | // if (cmdline_parser(argc, argv, &args) != 0) |
---|
| 67 | // exit(1); |
---|
| 68 | |
---|
| 69 | |
---|
| 70 | char line[MAX_LINE]; |
---|
| 71 | char outline[MAX_LINE]; |
---|
| 72 | char parms[MAX_LINE], desc[MAX_LINE], lemma[MAX_LINE]; |
---|
| 73 | long line_count = 0; |
---|
[8abee07] | 74 | |
---|
[25ae32e] | 75 | Guess guess(dictionary); |
---|
| 76 | int words_count=0; |
---|
| 77 | time_t start_time = time(NULL); |
---|
[8abee07] | 78 | |
---|
| 79 | // Segment seg; |
---|
[25ae32e] | 80 | Words tab; |
---|
[8abee07] | 81 | while (fgets(line, MAX_LINE, inputf)) |
---|
| 82 | { |
---|
| 83 | line_count++; |
---|
| 84 | int start, len; |
---|
| 85 | |
---|
| 86 | line[strlen(line)-1] = '\0'; |
---|
| 87 | |
---|
| 88 | if (!process_seg(line, args)) |
---|
| 89 | fputs(line,outputf); |
---|
| 90 | else |
---|
| 91 | { |
---|
| 92 | char form[MAX_FORM]; |
---|
| 93 | words_count++; |
---|
| 94 | tab.clear(); |
---|
| 95 | getfield(line,input_field_prefix,form); |
---|
| 96 | if (form==NULL) continue;//BZDURA |
---|
| 97 | |
---|
| 98 | guess.ana(form, tab); |
---|
| 99 | |
---|
| 100 | if ((tab.count()==0) && (!args.no_fail_flag)) // no guesses - analysis was unsuccessful |
---|
| 101 | fputs(line, failedf); |
---|
| 102 | else |
---|
| 103 | { |
---|
| 104 | |
---|
| 105 | // if (copy_processed) |
---|
| 106 | // fputs(line, stdout); |
---|
| 107 | // continue; |
---|
| 108 | // } |
---|
| 109 | // we've got some guesses. Do we want to print it? |
---|
| 110 | // if (args.only_fail_flag) |
---|
| 111 | // continue; |
---|
| 112 | |
---|
| 113 | float last_weight=0; |
---|
| 114 | int i=0; |
---|
| 115 | int count=0; |
---|
| 116 | unsigned first=1; |
---|
| 117 | char* parms_end = parms; |
---|
| 118 | char last_lemma[MAX_LINE]; |
---|
[10c74af] | 119 | |
---|
| 120 | count = 1; |
---|
[8abee07] | 121 | |
---|
[10c74af] | 122 | while (count < tab.count() && count <= guess_count) |
---|
| 123 | if (first || tab[count].w_suf() >= cut_off && tab[count].w_suf() >= delta * last_weight) |
---|
| 124 | { |
---|
| 125 | first=0; |
---|
| 126 | last_weight = tab[i].w_suf(); |
---|
| 127 | count++; |
---|
| 128 | } |
---|
| 129 | else |
---|
[8abee07] | 130 | break; |
---|
[10c74af] | 131 | |
---|
| 132 | // drukujemy count pierwszych z tab |
---|
| 133 | |
---|
| 134 | |
---|
| 135 | if(one_line) |
---|
| 136 | { |
---|
| 137 | char* descp=desc; |
---|
| 138 | for (int i=0; i< count; ++i) |
---|
| 139 | { |
---|
| 140 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 141 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 142 | } |
---|
| 143 | strcpy(outline,line); |
---|
| 144 | outline[strlen(outline)-1]='\0'; |
---|
| 145 | strcat(outline,desc); |
---|
| 146 | strcat(outline,"\n"); |
---|
| 147 | fputs(outline, outputf); |
---|
| 148 | if (copy_processed) |
---|
| 149 | fputs(line,outputf); |
---|
[8abee07] | 150 | } |
---|
[10c74af] | 151 | else if(one_field) |
---|
| 152 | { |
---|
| 153 | char* descp=desc; |
---|
| 154 | for (int i=0; i< count; ++i) |
---|
| 155 | if(i==0) |
---|
| 156 | { |
---|
| 157 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 158 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 159 | } |
---|
| 160 | else |
---|
| 161 | { |
---|
| 162 | if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0) |
---|
| 163 | descp += sprintf(descp,",%s",tab[i].descr()); |
---|
| 164 | else |
---|
| 165 | descp += sprintf(descp,";%s,%s",tab[i].lemma(),tab[i].descr()); |
---|
| 166 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 167 | } |
---|
| 168 | |
---|
| 169 | strcpy(outline,line); |
---|
| 170 | outline[strlen(outline)-1]='\0'; |
---|
| 171 | strcat(outline,desc); |
---|
| 172 | strcat(outline,"\n"); |
---|
| 173 | fputs(outline, outputf); |
---|
| 174 | if (copy_processed) |
---|
| 175 | fputs(line,outputf); |
---|
| 176 | } |
---|
| 177 | else |
---|
| 178 | { |
---|
| 179 | for (int i=0; i< tab.count(); ++i) |
---|
| 180 | { |
---|
| 181 | // kolejne opisy - kolejne linie. |
---|
| 182 | char* descp=desc; |
---|
| 183 | descp += sprintf(desc, " %s%s,%s\n", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 184 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 185 | strcpy(outline,line); |
---|
| 186 | outline[strlen(outline)-1]='\0'; |
---|
| 187 | strcat(outline,desc); |
---|
| 188 | fputs(outline, outputf); |
---|
| 189 | } |
---|
| 190 | if (copy_processed) |
---|
| 191 | fputs(line,outputf); |
---|
[8abee07] | 192 | } |
---|
[10c74af] | 193 | } |
---|
| 194 | } |
---|
| 195 | if(args.interactive_flag) |
---|
| 196 | fflush(outputf), fflush(failedf); |
---|
| 197 | |
---|
| 198 | } |
---|
| 199 | cmdline_parser_free(&args); |
---|
| 200 | } |
---|
| 201 | |
---|
| 202 | |
---|
| 203 | |
---|
| 204 | |
---|
| 205 | |
---|
| 206 | |
---|
| 207 | |
---|
| 208 | |
---|
| 209 | // while ((i=tab.next()) != -1 && count++<guess_count) { |
---|
| 210 | // /* if we have "one-line" flag then everything goes in one segment as many fields, |
---|
| 211 | // * if we have "one-field" flag everything goes in one segment as ONE field: |
---|
| 212 | // * - diferent lemmas are separated with ';', sequent descriptions to one lemma |
---|
| 213 | // * are separated with ',' |
---|
| 214 | // */ |
---|
| 215 | // if ((!first) && (tab[i].w_suf() < cut_off) || (tab[i].w_suf() < delta * last_weight)) { |
---|
| 216 | // break; |
---|
| 217 | // } |
---|
| 218 | // if (first) { |
---|
| 219 | // parms_end += sprintf(parms_end, "%s", output_field_prefix); |
---|
| 220 | // } else if (!args.one_field_flag) |
---|
| 221 | // parms_end += sprintf(parms_end, "%s", output_field_prefix); |
---|
[8abee07] | 222 | |
---|
[10c74af] | 223 | // if (!args.one_field_flag || strcmp(last_lemma, tab[i].lemma()) != 0) { |
---|
| 224 | // if (args.one_field_flag && !first) |
---|
| 225 | // parms_end += sprintf(parms_end, ";"); |
---|
| 226 | // parms_end += sprintf(parms_end, "%s", tab[i].lemma()); |
---|
| 227 | // strcpy(last_lemma, tab[i].lemma()); |
---|
| 228 | // } |
---|
[8abee07] | 229 | |
---|
[10c74af] | 230 | // first=0; |
---|
[8abee07] | 231 | |
---|
[10c74af] | 232 | // last_weight = tab[i].w_suf(); |
---|
| 233 | // if (!weights) |
---|
| 234 | // parms_end += sprintf(parms_end, ",%s:%d", tab[i].descr(), (int)tab[i].w_suf()); |
---|
| 235 | // else |
---|
| 236 | // parms_end += sprintf(parms_end, ",%s", tab[i].descr()); |
---|
[8abee07] | 237 | |
---|
[10c74af] | 238 | // if (!args.one_field_flag) { |
---|
| 239 | // seg.addfield(parms); |
---|
| 240 | // parms_end = parms; |
---|
| 241 | // } |
---|
| 242 | |
---|
| 243 | // if (!(args.one_field_flag || args.one_line_flag)) { |
---|
| 244 | // seg.print(outline); |
---|
| 245 | // fputs(outline, outputf); |
---|
| 246 | // --seg.auxn; |
---|
| 247 | // } |
---|
| 248 | // //if (copy_processed) |
---|
| 249 | // // fputs(outline, stdout); |
---|
| 250 | // } //while |
---|
[8abee07] | 251 | |
---|
[10c74af] | 252 | // if (args.one_field_flag) |
---|
| 253 | // seg.addfield(parms); |
---|
[8abee07] | 254 | |
---|
[10c74af] | 255 | // if (args.one_field_flag || args.one_line_flag){ |
---|
| 256 | // seg.print(outline); |
---|
| 257 | // fputs(outline, outputf); |
---|
| 258 | // } |
---|
| 259 | // } else { // if (process_segment) |
---|
| 260 | // // jak to nie jest wyraz - to przepisz token na wyjscie. |
---|
| 261 | // // printtok(line, start, len, cat, form); |
---|
| 262 | // seg.print(outline); |
---|
| 263 | // fputs(outline, outputf); |
---|
| 264 | // if (copy_processed) |
---|
| 265 | // fputs(outline, stdout); |
---|
| 266 | // } |
---|
| 267 | // } |
---|
| 268 | // time_t end_time = time(NULL); |
---|
| 269 | // if (per_info) { |
---|
| 270 | // printf("Liczba s³ów: %d\n", words_count); |
---|
| 271 | // printf("Czas analizy: %d sekund\n", end_time-start_time); |
---|
| 272 | // } |
---|
| 273 | // cmdline_parser_free(&args); |
---|
| 274 | // } |
---|
[8abee07] | 275 | |
---|