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 | 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; |
---|
74 | |
---|
75 | Guess guess(dictionary); |
---|
76 | int words_count=0; |
---|
77 | time_t start_time = time(NULL); |
---|
78 | |
---|
79 | // Segment seg; |
---|
80 | Words tab; |
---|
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]; |
---|
119 | |
---|
120 | while ((i=tab.next()) != -1 && count++<guess_count) { |
---|
121 | /* if we have "one-line" flag then everything goes in one segment as many fields, |
---|
122 | * if we have "one-field" flag everything goes in one segment as ONE field: |
---|
123 | * - diferent lemmas are separated with ';', sequent descriptions to one lemma |
---|
124 | * are separated with ',' |
---|
125 | */ |
---|
126 | if ((!first) && (tab[i].w_suf() < cut_off) || (tab[i].w_suf() < delta * last_weight)) { |
---|
127 | break; |
---|
128 | } |
---|
129 | if (first) { |
---|
130 | parms_end += sprintf(parms_end, "%s", field_prefix); |
---|
131 | } else if (!args.one_field_flag) |
---|
132 | parms_end += sprintf(parms_end, "%s", field_prefix); |
---|
133 | |
---|
134 | if (!args.one_field_flag || strcmp(last_lemma, tab[i].lemma()) != 0) { |
---|
135 | if (args.one_field_flag && !first) |
---|
136 | parms_end += sprintf(parms_end, ";"); |
---|
137 | parms_end += sprintf(parms_end, "%s", tab[i].lemma()); |
---|
138 | strcpy(last_lemma, tab[i].lemma()); |
---|
139 | } |
---|
140 | |
---|
141 | first=0; |
---|
142 | |
---|
143 | last_weight = tab[i].w_suf(); |
---|
144 | if (!weights) |
---|
145 | parms_end += sprintf(parms_end, ",%s:%d", tab[i].descr(), (int)tab[i].w_suf()); |
---|
146 | else |
---|
147 | parms_end += sprintf(parms_end, ",%s", tab[i].descr()); |
---|
148 | |
---|
149 | if (!args.one_field_flag) { |
---|
150 | seg.addfield(parms); |
---|
151 | parms_end = parms; |
---|
152 | } |
---|
153 | |
---|
154 | if (!(args.one_field_flag || args.one_line_flag)) { |
---|
155 | seg.print(outline); |
---|
156 | fputs(outline, outputf); |
---|
157 | --seg.auxn; |
---|
158 | } |
---|
159 | //if (copy_processed) |
---|
160 | // fputs(outline, stdout); |
---|
161 | } //while |
---|
162 | |
---|
163 | if (args.one_field_flag) |
---|
164 | seg.addfield(parms); |
---|
165 | |
---|
166 | if (args.one_field_flag || args.one_line_flag){ |
---|
167 | seg.print(outline); |
---|
168 | fputs(outline, outputf); |
---|
169 | } |
---|
170 | } else { // if (process_segment) |
---|
171 | // jak to nie jest wyraz - to przepisz token na wyjscie. |
---|
172 | // printtok(line, start, len, cat, form); |
---|
173 | seg.print(outline); |
---|
174 | fputs(outline, outputf); |
---|
175 | if (copy_processed) |
---|
176 | fputs(outline, stdout); |
---|
177 | } |
---|
178 | } |
---|
179 | time_t end_time = time(NULL); |
---|
180 | if (per_info) { |
---|
181 | printf("Liczba s³ów: %d\n", words_count); |
---|
182 | printf("Czas analizy: %d sekund\n", end_time-start_time); |
---|
183 | } |
---|
184 | cmdline_parser_free(&args); |
---|
185 | } |
---|
186 | |
---|