source: src/gue/main.cc @ 5f4d9c3

Last change on this file since 5f4d9c3 was 5f4d9c3, checked in by Maciej Prill <mprill@…>, 12 years ago

Rewritten the build system, added lem UTF-8 version.

  • Property mode set to 100644
File size: 6.1 KB
Line 
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
16int 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         
59          if ((tab.count()==0) && (!args.no_fail_flag)) // no guesses - analysis was unsuccessful
60            fputs(line, failedf);
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        }
157      if(args.interactive_flag) 
158        fflush(outputf), fflush(failedf);
159     
160    }
161  cmdline_parser_free(&args);
162}
163
164
165
166
167
168
169
170
171//            while ((i=tab.next()) != -1 && count++<guess_count) {
172//              /* if we have "one-line" flag then everything goes in one segment as many fields,
173//               * if we have "one-field" flag everything goes in one segment as ONE field:
174//               * - diferent lemmas are separated with ';', sequent descriptions to one lemma
175//               *   are separated with ','
176//               */
177//              if ((!first) && (tab[i].w_suf() < cut_off) || (tab[i].w_suf() < delta * last_weight)) {
178//                break;
179//              }
180//              if (first) {
181//                parms_end += sprintf(parms_end, "%s", output_field_prefix);
182//              } else if (!args.one_field_flag)
183//                parms_end += sprintf(parms_end, "%s", output_field_prefix);
184               
185//              if (!args.one_field_flag || strcmp(last_lemma, tab[i].lemma()) != 0) {
186//                if (args.one_field_flag && !first)
187//                  parms_end += sprintf(parms_end, ";");
188//                parms_end += sprintf(parms_end, "%s", tab[i].lemma());
189//                strcpy(last_lemma, tab[i].lemma());
190//              }
191               
192//              first=0;
193               
194//              last_weight = tab[i].w_suf();
195//              if (!weights)
196//                parms_end += sprintf(parms_end, ",%s:%d",  tab[i].descr(), (int)tab[i].w_suf());
197//              else
198//                parms_end += sprintf(parms_end, ",%s", tab[i].descr());
199               
200//              if (!args.one_field_flag) {
201//                seg.addfield(parms);
202//                parms_end = parms;
203//              }
204               
205//              if (!(args.one_field_flag || args.one_line_flag)) {
206//                seg.print(outline);
207//                fputs(outline, outputf);
208//                --seg.auxn;
209//              }
210//              //if (copy_processed)
211//              //  fputs(outline, stdout);
212//            } //while
213             
214//            if (args.one_field_flag)
215//              seg.addfield(parms);
216             
217//            if (args.one_field_flag || args.one_line_flag){
218//              seg.print(outline);
219//              fputs(outline, outputf);
220//            }
221//          } else { // if (process_segment)
222//          // jak to nie jest wyraz - to przepisz token na wyjscie.
223//          //      printtok(line, start, len, cat, form);
224//          seg.print(outline);
225//          fputs(outline, outputf);
226//          if (copy_processed)
227//            fputs(outline, stdout);
228//        }
229//      }
230//       time_t end_time = time(NULL);
231//       if (per_info) {
232//      printf("Liczba s³ów: %d\n", words_count);
233//      printf("Czas analizy: %d sekund\n", end_time-start_time);
234//       }
235//       cmdline_parser_free(&args);
236//     }
237 
Note: See TracBrowser for help on using the repository browser.