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 | |
---|
17 | int non_standard_config=0; |
---|
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 | |
---|
26 | process_common_options(&args,argv[0]); |
---|
27 | process_guess_options(&args); |
---|
28 | |
---|
29 | |
---|
30 | // PONIŻEJ POPRZEDNI KOD (JUSTYNY) |
---|
31 | // //preliminary command-line parsing - for configuration file info only |
---|
32 | // gengetopt_args_info pre_args; |
---|
33 | |
---|
34 | // if (cmdline_parser(argc, argv, &pre_args) != 0) |
---|
35 | // exit(1); |
---|
36 | // if(pre_args.config_given){ |
---|
37 | // printf("podano config: %s\n",pre_args.config_arg); |
---|
38 | // non_standard_config=1; |
---|
39 | // } |
---|
40 | |
---|
41 | |
---|
42 | // //configuration file 1 parsing |
---|
43 | // struct cmdline_parser_params *params; |
---|
44 | // params = cmdline_parser_params_init(); |
---|
45 | // params->initialize = 1; |
---|
46 | // if(cmdline_parser_config_file(CONFIGFILE1,&args, params)!=0){ |
---|
47 | // printf("System-wide configuration file parsing error!\n"); |
---|
48 | // exit(1); |
---|
49 | // } |
---|
50 | |
---|
51 | // //configuration file 2 parsing-overriding |
---|
52 | // params->initialize=0; |
---|
53 | // params->override=1; |
---|
54 | // char* config2=(non_standard_config)?pre_args.config_arg:CONFIGFILE2; |
---|
55 | // if(cmdline_parser_config_file(config2,&args, params)!=0){ |
---|
56 | // printf("User configuration file parsing error!\n"); |
---|
57 | // return 1; |
---|
58 | // } |
---|
59 | |
---|
60 | // params->initialize=0; |
---|
61 | // params->override=1; |
---|
62 | // //params->check_required=1; |
---|
63 | |
---|
64 | // free(params); |
---|
65 | |
---|
66 | // //command-line options parsing-overriding |
---|
67 | // if (cmdline_parser(argc, argv, &args) != 0) |
---|
68 | // exit(1); |
---|
69 | |
---|
70 | |
---|
71 | char line[MAX_LINE]; |
---|
72 | char outline[MAX_LINE]; |
---|
73 | char parms[MAX_LINE], desc[MAX_LINE], lemma[MAX_LINE]; |
---|
74 | long line_count = 0; |
---|
75 | // printf("d_f=%s\n", dict_file); |
---|
76 | Guess guess(dictionary); |
---|
77 | int words_count=0; |
---|
78 | time_t start_time = time(NULL); |
---|
79 | |
---|
80 | Segment seg; |
---|
81 | Words tab; |
---|
82 | char* form; //[MAX_FORM]; |
---|
83 | while (fgets(line, MAX_LINE, inputf)==line) { |
---|
84 | line_count++; |
---|
85 | int start, len; |
---|
86 | |
---|
87 | line[strlen(line)-1] = '\0'; |
---|
88 | |
---|
89 | if (!seg.parse(line)) { |
---|
90 | fprintf(stderr, "B³±d w wej¶ciu (linia: %d)\n", line_count); |
---|
91 | return -1; |
---|
92 | } |
---|
93 | |
---|
94 | if (process_seg(seg, args)) { |
---|
95 | words_count++; |
---|
96 | tab.clear(); |
---|
97 | if (args.input_field_given>0) { |
---|
98 | form = getInput(args.input_field_arg, args.input_field_given, seg); |
---|
99 | } else |
---|
100 | form = seg.form; |
---|
101 | |
---|
102 | if (NULL == form) { |
---|
103 | continue; |
---|
104 | } |
---|
105 | |
---|
106 | guess.ana(form, tab); |
---|
107 | |
---|
108 | if ((tab.count()==0) && (!args.no_fail_flag)) { |
---|
109 | // no guesses - analysis was unsuccessful |
---|
110 | seg.print(outline); //this is necessary - seg.parse destroys line... |
---|
111 | fputs(outline, failedf); |
---|
112 | if (copy_processed) |
---|
113 | fputs(line, stdout); |
---|
114 | continue; |
---|
115 | } |
---|
116 | // we've got some guesses. Do we want to print it? |
---|
117 | if (args.only_fail_flag) |
---|
118 | continue; |
---|
119 | |
---|
120 | float last_weight=0; |
---|
121 | int i=0; |
---|
122 | int count=0; |
---|
123 | unsigned first=1; |
---|
124 | char* parms_end = parms; |
---|
125 | char last_lemma[MAX_LINE]; |
---|
126 | |
---|
127 | while ((i=tab.next()) != -1 && count++<guess_count) { |
---|
128 | /* if we have "one-line" flag then everything goes in one segment as many fields, |
---|
129 | * if we have "one-field" flag everything goes in one segment as ONE field: |
---|
130 | * - diferent lemmas are separated with ';', sequent descriptions to one lemma |
---|
131 | * are separated with ',' |
---|
132 | */ |
---|
133 | if ((!first) && (tab[i].w_suf() < cut_off) || (tab[i].w_suf() < delta * last_weight)) { |
---|
134 | break; |
---|
135 | } |
---|
136 | if (first) { |
---|
137 | parms_end += sprintf(parms_end, "%s", field_prefix); |
---|
138 | } else if (!args.one_field_flag) |
---|
139 | parms_end += sprintf(parms_end, "%s", field_prefix); |
---|
140 | |
---|
141 | if (!args.one_field_flag || strcmp(last_lemma, tab[i].lemma()) != 0) { |
---|
142 | if (args.one_field_flag && !first) |
---|
143 | parms_end += sprintf(parms_end, ";"); |
---|
144 | parms_end += sprintf(parms_end, "%s", tab[i].lemma()); |
---|
145 | strcpy(last_lemma, tab[i].lemma()); |
---|
146 | } |
---|
147 | |
---|
148 | first=0; |
---|
149 | |
---|
150 | last_weight = tab[i].w_suf(); |
---|
151 | if (!weights) |
---|
152 | parms_end += sprintf(parms_end, ",%s:%d", tab[i].descr(), (int)tab[i].w_suf()); |
---|
153 | else |
---|
154 | parms_end += sprintf(parms_end, ",%s", tab[i].descr()); |
---|
155 | |
---|
156 | if (!args.one_field_flag) { |
---|
157 | seg.addfield(parms); |
---|
158 | parms_end = parms; |
---|
159 | } |
---|
160 | |
---|
161 | if (!(args.one_field_flag || args.one_line_flag)) { |
---|
162 | seg.print(outline); |
---|
163 | fputs(outline, outputf); |
---|
164 | --seg.auxn; |
---|
165 | } |
---|
166 | //if (copy_processed) |
---|
167 | // fputs(outline, stdout); |
---|
168 | } //while |
---|
169 | |
---|
170 | if (args.one_field_flag) |
---|
171 | seg.addfield(parms); |
---|
172 | |
---|
173 | if (args.one_field_flag || args.one_line_flag){ |
---|
174 | seg.print(outline); |
---|
175 | fputs(outline, outputf); |
---|
176 | } |
---|
177 | } else { // if (process_segment) |
---|
178 | // jak to nie jest wyraz - to przepisz token na wyjscie. |
---|
179 | // printtok(line, start, len, cat, form); |
---|
180 | seg.print(outline); |
---|
181 | fputs(outline, outputf); |
---|
182 | if (copy_processed) |
---|
183 | fputs(outline, stdout); |
---|
184 | } |
---|
185 | } |
---|
186 | time_t end_time = time(NULL); |
---|
187 | if (per_info) { |
---|
188 | printf("Liczba s³ów: %d\n", words_count); |
---|
189 | printf("Czas analizy: %d sekund\n", end_time-start_time); |
---|
190 | } |
---|
191 | cmdline_parser_free(&args); |
---|
192 | } |
---|