[5f4d9c3] | 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 | |
---|
| 16 | int main(int argc, char** argv) { |
---|
| 17 | |
---|
| 18 | // int non_standard_config=0; |
---|
| 19 | |
---|
| 20 | gengetopt_args_info args; |
---|
| 21 | |
---|
| 22 | if(cmdline_parser(argc, argv, &args) != 0) |
---|
| 23 | exit(1); |
---|
| 24 | |
---|
| 25 | process_config_files(&args,argv[0]); |
---|
| 26 | process_common_options(&args,argv[0]); |
---|
| 27 | process_guess_options(&args); |
---|
| 28 | |
---|
| 29 | char line[MAX_LINE]; |
---|
| 30 | char outline[MAX_LINE]; |
---|
| 31 | char parms[MAX_LINE], desc[MAX_LINE], lemma[MAX_LINE]; |
---|
| 32 | long line_count = 0; |
---|
| 33 | |
---|
| 34 | Guess guess(dictionary); |
---|
| 35 | int words_count=0; |
---|
| 36 | time_t start_time = time(NULL); |
---|
| 37 | |
---|
| 38 | // Segment seg; |
---|
| 39 | Words tab; |
---|
| 40 | while (fgets(line, MAX_LINE, inputf)) |
---|
| 41 | { |
---|
| 42 | line_count++; |
---|
| 43 | int start, len; |
---|
| 44 | |
---|
| 45 | // line[strlen(line)-1] = '\0'; |
---|
| 46 | |
---|
| 47 | if (!process_seg(line, args)) |
---|
| 48 | fputs(line,outputf); |
---|
| 49 | else |
---|
| 50 | { |
---|
| 51 | char form[MAX_FORM]; |
---|
| 52 | words_count++; |
---|
| 53 | tab.clear(); |
---|
| 54 | getfield(line,input_field_prefix,form); |
---|
| 55 | if (form==NULL) continue;//BZDURA |
---|
| 56 | |
---|
| 57 | guess.ana(form, tab); |
---|
| 58 | |
---|
[e0cd003] | 59 | if ((tab.count()==0)) // no guesses - analysis was unsuccessful |
---|
| 60 | fputs(line, outputf); |
---|
[5f4d9c3] | 61 | else |
---|
| 62 | { |
---|
| 63 | |
---|
| 64 | // if (copy_processed) |
---|
| 65 | // fputs(line, stdout); |
---|
| 66 | // continue; |
---|
| 67 | // } |
---|
| 68 | // we've got some guesses. Do we want to print it? |
---|
| 69 | // if (args.only_fail_flag) |
---|
| 70 | // continue; |
---|
| 71 | |
---|
| 72 | float last_weight=0; |
---|
| 73 | int i=0; |
---|
| 74 | int count=0; |
---|
| 75 | unsigned first=1; |
---|
| 76 | char* parms_end = parms; |
---|
| 77 | char last_lemma[MAX_LINE]; |
---|
| 78 | |
---|
| 79 | count = 1; |
---|
| 80 | |
---|
| 81 | tab.sort(); |
---|
| 82 | |
---|
| 83 | while (count < tab.count() && count <= guess_count) |
---|
| 84 | if (first || tab[count].w_suf() >= cut_off && tab[count].w_suf() >= delta * last_weight) |
---|
| 85 | { |
---|
| 86 | first=0; |
---|
| 87 | last_weight = tab[i].w_suf(); |
---|
| 88 | count++; |
---|
| 89 | } |
---|
| 90 | else |
---|
| 91 | break; |
---|
| 92 | |
---|
| 93 | // drukujemy count pierwszych z tab |
---|
| 94 | |
---|
| 95 | |
---|
| 96 | if(one_line) |
---|
| 97 | { |
---|
| 98 | char* descp=desc; |
---|
| 99 | for (int i=0; i< count; ++i) |
---|
| 100 | { |
---|
| 101 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 102 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 103 | } |
---|
| 104 | strcpy(outline,line); |
---|
| 105 | outline[strlen(outline)-1]='\0'; |
---|
| 106 | strcat(outline,desc); |
---|
| 107 | strcat(outline,"\n"); |
---|
| 108 | fputs(outline, outputf); |
---|
| 109 | if (copy_processed) |
---|
| 110 | fputs(line,outputf); |
---|
| 111 | } |
---|
| 112 | else if(one_field) |
---|
| 113 | { |
---|
| 114 | char* descp=desc; |
---|
| 115 | for (int i=0; i< count; ++i) |
---|
| 116 | if(i==0) |
---|
| 117 | { |
---|
| 118 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 119 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 120 | } |
---|
| 121 | else |
---|
| 122 | { |
---|
| 123 | if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0) |
---|
| 124 | descp += sprintf(descp,",%s",tab[i].descr()); |
---|
| 125 | else |
---|
| 126 | descp += sprintf(descp,";%s,%s",tab[i].lemma(),tab[i].descr()); |
---|
| 127 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 128 | } |
---|
| 129 | |
---|
| 130 | strcpy(outline,line); |
---|
| 131 | outline[strlen(outline)-1]='\0'; |
---|
| 132 | strcat(outline,desc); |
---|
| 133 | strcat(outline,"\n"); |
---|
| 134 | fputs(outline, outputf); |
---|
| 135 | if (copy_processed) |
---|
| 136 | fputs(line,outputf); |
---|
| 137 | } |
---|
| 138 | else |
---|
| 139 | { |
---|
| 140 | for (int i=0; i< count; ++i) |
---|
| 141 | { |
---|
| 142 | // kolejne opisy - kolejne linie. |
---|
| 143 | char* descp=desc; |
---|
| 144 | descp += sprintf(desc, " %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
| 145 | if(weights) descp += sprintf(descp,":%d",(int)tab[i].w_suf()); |
---|
| 146 | descp += sprintf(descp,"\n"); |
---|
| 147 | strcpy(outline,line); |
---|
| 148 | outline[strlen(outline)-1]='\0'; |
---|
| 149 | strcat(outline,desc); |
---|
| 150 | fputs(outline, outputf); |
---|
| 151 | } |
---|
| 152 | if (copy_processed) |
---|
| 153 | fputs(line,outputf); |
---|
| 154 | } |
---|
| 155 | } |
---|
| 156 | } |
---|
[e0cd003] | 157 | if(args.interactive_flag) fflush(outputf); |
---|
[5f4d9c3] | 158 | |
---|
| 159 | } |
---|
| 160 | cmdline_parser_free(&args); |
---|
| 161 | } |
---|
| 162 | |
---|
| 163 | |
---|
| 164 | |
---|
| 165 | |
---|
| 166 | |
---|
| 167 | |
---|
| 168 | |
---|
| 169 | |
---|
| 170 | // while ((i=tab.next()) != -1 && count++<guess_count) { |
---|
| 171 | // /* if we have "one-line" flag then everything goes in one segment as many fields, |
---|
| 172 | // * if we have "one-field" flag everything goes in one segment as ONE field: |
---|
| 173 | // * - diferent lemmas are separated with ';', sequent descriptions to one lemma |
---|
| 174 | // * are separated with ',' |
---|
| 175 | // */ |
---|
| 176 | // if ((!first) && (tab[i].w_suf() < cut_off) || (tab[i].w_suf() < delta * last_weight)) { |
---|
| 177 | // break; |
---|
| 178 | // } |
---|
| 179 | // if (first) { |
---|
| 180 | // parms_end += sprintf(parms_end, "%s", output_field_prefix); |
---|
| 181 | // } else if (!args.one_field_flag) |
---|
| 182 | // parms_end += sprintf(parms_end, "%s", output_field_prefix); |
---|
| 183 | |
---|
| 184 | // if (!args.one_field_flag || strcmp(last_lemma, tab[i].lemma()) != 0) { |
---|
| 185 | // if (args.one_field_flag && !first) |
---|
| 186 | // parms_end += sprintf(parms_end, ";"); |
---|
| 187 | // parms_end += sprintf(parms_end, "%s", tab[i].lemma()); |
---|
| 188 | // strcpy(last_lemma, tab[i].lemma()); |
---|
| 189 | // } |
---|
| 190 | |
---|
| 191 | // first=0; |
---|
| 192 | |
---|
| 193 | // last_weight = tab[i].w_suf(); |
---|
| 194 | // if (!weights) |
---|
| 195 | // parms_end += sprintf(parms_end, ",%s:%d", tab[i].descr(), (int)tab[i].w_suf()); |
---|
| 196 | // else |
---|
| 197 | // parms_end += sprintf(parms_end, ",%s", tab[i].descr()); |
---|
| 198 | |
---|
| 199 | // if (!args.one_field_flag) { |
---|
| 200 | // seg.addfield(parms); |
---|
| 201 | // parms_end = parms; |
---|
| 202 | // } |
---|
| 203 | |
---|
| 204 | // if (!(args.one_field_flag || args.one_line_flag)) { |
---|
| 205 | // seg.print(outline); |
---|
| 206 | // fputs(outline, outputf); |
---|
| 207 | // --seg.auxn; |
---|
| 208 | // } |
---|
| 209 | // //if (copy_processed) |
---|
| 210 | // // fputs(outline, stdout); |
---|
| 211 | // } //while |
---|
| 212 | |
---|
| 213 | // if (args.one_field_flag) |
---|
| 214 | // seg.addfield(parms); |
---|
| 215 | |
---|
| 216 | // if (args.one_field_flag || args.one_line_flag){ |
---|
| 217 | // seg.print(outline); |
---|
| 218 | // fputs(outline, outputf); |
---|
| 219 | // } |
---|
| 220 | // } else { // if (process_segment) |
---|
| 221 | // // jak to nie jest wyraz - to przepisz token na wyjscie. |
---|
| 222 | // // printtok(line, start, len, cat, form); |
---|
| 223 | // seg.print(outline); |
---|
| 224 | // fputs(outline, outputf); |
---|
| 225 | // if (copy_processed) |
---|
| 226 | // fputs(outline, stdout); |
---|
| 227 | // } |
---|
| 228 | // } |
---|
| 229 | // time_t end_time = time(NULL); |
---|
| 230 | // if (per_info) { |
---|
| 231 | // printf("Liczba s³ów: %d\n", words_count); |
---|
| 232 | // printf("Czas analizy: %d sekund\n", end_time-start_time); |
---|
| 233 | // } |
---|
| 234 | // cmdline_parser_free(&args); |
---|
| 235 | // } |
---|
| 236 | |
---|