source: src/kor/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: 3.8 KB
Line 
1#include <stdlib.h>
2#include <ctype.h>
3#include "../lib/iotools.h"
4#include "common_cor.h"
5#include "corr.hh"
6#include <locale.h>
7
8
9int main(int argc, char** argv) {
10
11//   setlocale(LC_CTYPE,"");
12//   setlocale(LC_COLLATE,"");
13
14  gengetopt_args_info args;
15
16  if(cmdline_parser(argc, argv, &args) != 0)
17    exit(1);
18
19  process_config_files(&args,argv[0]);
20  process_common_options(&args,argv[0]);
21  process_cor_options(&args);
22
23  Corr cor;
24
25  //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
26//  strcpy(dictionary,"cor.bin");
27
28  cor.load(dictionary);
29  cor.t=args.distance_arg;
30
31  //>>>>>>>>>>>>>>>
32  cor.CL.cor_stdcor=1*PREC;
33  cor.CL.cor_xchg=1*PREC;
34  if (cor.load2(file_weights)==-1) return -1;  // moje
35  cor.t=1*PREC; // ODLEGLOSC EDYCYJNA
36  //<<<<<<<<<<<<<<
37
38  char line[MAX_LINE+1];
39  long line_count = 0;
40
41  Segment seg;
42  Words tab;
43  char form1[MAX_LINE];
44  char* form;
45  int formcasing;
46  char corfield[MAX_LINE]="";
47
48  while (fgets(line, MAX_LINE, inputf))
49    {
50      ++line_count;
51      char outline[128];
52
53      if (!process_seg(line, args))
54        fputs(line, outputf);
55      else
56        {
57          char form[MAX_FORM];
58         
59          tab.clear();
60          getfield(line,input_field_prefix,form);
61          if (form==NULL) continue;
62         
63          formcasing=3;
64          cor.correct(form, tab);
65         
66          if( tab.count() == 0 )
67            {
68              formcasing=casing(form);
69              if( formcasing == 1 || formcasing == 2)
70                tolowers(form, form1), cor.correct(form1, tab);
71            }
72         
73          if ( tab.count() == 0)
74            fputs(line, failedf);
75          else 
76            {
77                      tab.sort();
78
79                int max_cnt = 0;
80                if(result_count < 1) {
81                        max_cnt = tab.count();
82                }
83                else {
84                        max_cnt = (tab.count() < result_count) ? tab.count() : result_count;
85                }
86               
87              if(args.replace_flag)
88                {
89                  char corfield[128];
90                  strcpy(corfield, input_field_prefix);
91                  strcat(corfield, form);
92                  seg.aux[seg.auxn]=corfield;
93                  ++seg.auxn;
94                  for(int i=0; i<tab.count(); ++i)
95                    {
96                      seg.form=tab[i].form();
97                      restorecasing(seg.form,seg.form,formcasing);
98                      seg.print(outline);
99                      fputs(outline, outputf);
100                    }
101                  --seg.auxn;
102                }
103              else
104                {
105                  if(one_line)
106                    {
107                      char* p=corfield;
108                      for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i)
109                        {
110                          if(tab[i].w_suf() > threshold) continue;
111                          restorecasing(tab[i].form(),tab[i].form(),formcasing);
112                          p += sprintf(p," %s%s",output_field_prefix,tab[i].form());
113                          if(show_scores) {
114                            p += sprintf(p,",%1.2f",tab[i].w_suf());
115                          }
116                        }
117                      sprintf(p,"\n");
118
119                      strcpy(outline,line);
120                      outline[strlen(outline)-1]='\0';
121                      strcat(outline,corfield);
122                      fputs(outline, outputf);
123                    }
124                  else if(one_field)
125                    {
126                      char* p=corfield;
127                      p += sprintf(p," %s",output_field_prefix);
128                      for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i)
129                        {
130                          if(tab[i].w_suf() > threshold) continue;
131                          restorecasing(tab[i].form(),tab[i].form(),formcasing);
132                          p += sprintf(p,(i==0)?"%s":";%s",tab[i].form());
133                          if(show_scores) {
134                            p += sprintf(p,",%1.2f",tab[i].w_suf());
135                          }
136                        }
137                     
138                      sprintf(p,"\n");
139
140                      strcpy(outline,line);
141                      outline[strlen(outline)-1]='\0';
142                      strcat(outline,corfield);
143                      fputs(outline, outputf);
144                    }
145                  else
146                    {
147                      for(int i=tab.count()-1; i >= tab.count()-max_cnt; --i)
148                        {
149                          if(tab[i].w_suf() > threshold) continue;
150                          restorecasing(tab[i].form(),tab[i].form(),formcasing);
151                          char* p = corfield;
152                          p += sprintf(p," %s%s",output_field_prefix,tab[i].form());
153                          if(show_scores) {
154                                p += sprintf(p,",%1.2f",tab[i].w_suf());
155                          }
156                          p += sprintf(p, "\n");
157                          strcpy(outline,line);
158                          outline[strlen(outline)-1]='\0';
159                          strcat(outline,corfield);
160                          fputs(outline, outputf);
161                        }
162                    }
163                }
164            }
165        }
166     
167      if(args.interactive_flag)
168        {
169        fflush(outputf);
170        fflush(failedf);
171      }
172    }
173  cmdline_parser_free(&args);
174}
Note: See TracBrowser for help on using the repository browser.