1 | #include "../lib/iotools.h" |
---|
2 | #define _CMDLINE_FILE "../lem/cmdline.h" |
---|
3 | #include "../common/common.h" |
---|
4 | #include "common_lem.h" |
---|
5 | #include "lem.h" |
---|
6 | #include "cmdline.h" |
---|
7 | #include <locale.h> |
---|
8 | |
---|
9 | int main(int argc, char** argv) { |
---|
10 | |
---|
11 | // setlocale(LC_CTYPE,""); //PO CO TO? |
---|
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_lem_options(&args); |
---|
22 | |
---|
23 | char line[MAX_LINE+1]; |
---|
24 | char outline[MAX_LINE+1]; |
---|
25 | char parms[MAX_LINE+1], desc[MAX_LINE+1], lemma[MAX_LINE+1]; |
---|
26 | long line_count = 0; |
---|
27 | |
---|
28 | Lem* lem; |
---|
29 | |
---|
30 | if(strcmp(dictionary+strlen(dictionary)-4,".bin")==0) |
---|
31 | lem = new Lem(dictionary); |
---|
32 | else if(strcmp(dictionary+strlen(dictionary)-4,".dic")==0) |
---|
33 | lem = new AuxLem(dictionary); |
---|
34 | else |
---|
35 | fprintf(stderr,"lem: Invalid dictionary file extension.\n"); |
---|
36 | |
---|
37 | Words tab; |
---|
38 | // Segment seg; |
---|
39 | |
---|
40 | while (fgets(line, MAX_LINE, inputf)) |
---|
41 | { |
---|
42 | // strcpy(outline,line); |
---|
43 | ++line_count; |
---|
44 | |
---|
45 | int start, len; |
---|
46 | |
---|
47 | if (!process_seg(line, args)) // TO POWINNO BYC WCZESNIEJ ZABEZPIECZONE |
---|
48 | fputs(line, outputf); |
---|
49 | else |
---|
50 | { |
---|
51 | char form[MAX_FORM]; |
---|
52 | |
---|
53 | tab.clear(); |
---|
54 | getfield(line,input_field_prefix,form); |
---|
55 | if (form==NULL) continue; |
---|
56 | |
---|
57 | lem->ana(form, tab); |
---|
58 | if(tab.count()==0) |
---|
59 | { |
---|
60 | char form1[MAX_FORM]; // tymczasowo tak, trzeba zmienic ana |
---|
61 | char* p; |
---|
62 | strcpy(form1,form); |
---|
63 | for(p=form1;*p;++p) *p=tolower(*p); |
---|
64 | p=form1; |
---|
65 | lem->ana(p,tab); |
---|
66 | } |
---|
67 | |
---|
68 | if (tab.count() == 0) |
---|
69 | fputs(line, failedf); |
---|
70 | else |
---|
71 | { // mamy jakies opisy w slowniku |
---|
72 | |
---|
73 | if(one_line) |
---|
74 | { |
---|
75 | char* descp=desc; |
---|
76 | for (int i=0; i< tab.count(); ++i) |
---|
77 | { |
---|
78 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
79 | } |
---|
80 | strcpy(outline,line); |
---|
81 | outline[strlen(outline)-1]='\0'; |
---|
82 | strcat(outline,desc); |
---|
83 | strcat(outline,"\n"); |
---|
84 | fputs(outline, outputf); |
---|
85 | if (copy_processed) |
---|
86 | fputs(line,outputf); |
---|
87 | } |
---|
88 | else if(one_field) |
---|
89 | { |
---|
90 | char* descp=desc; |
---|
91 | for (int i=0; i< tab.count(); ++i) |
---|
92 | if(i==0) |
---|
93 | descp += sprintf(descp," %s%s,%s", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
94 | else |
---|
95 | { |
---|
96 | if(strcmp(tab[i].lemma(),tab[i-1].lemma())==0) |
---|
97 | descp += sprintf(descp,",%s",tab[i].descr()); |
---|
98 | else |
---|
99 | descp += sprintf(descp,";%s,%s",tab[i].lemma(),tab[i].descr()); |
---|
100 | } |
---|
101 | |
---|
102 | strcpy(outline,line); |
---|
103 | outline[strlen(outline)-1]='\0'; |
---|
104 | strcat(outline,desc); |
---|
105 | strcat(outline,"\n"); |
---|
106 | fputs(outline, outputf); |
---|
107 | if (copy_processed) |
---|
108 | fputs(line,outputf); |
---|
109 | } |
---|
110 | else |
---|
111 | { |
---|
112 | for (int i=0; i< tab.count(); ++i) |
---|
113 | { |
---|
114 | // kolejne opisy - kolejne linie. |
---|
115 | sprintf(desc, " %s%s,%s\n", output_field_prefix, tab[i].lemma(), tab[i].descr()); |
---|
116 | strcpy(outline,line); |
---|
117 | outline[strlen(outline)-1]='\0'; |
---|
118 | strcat(outline,desc); |
---|
119 | fputs(outline, outputf); |
---|
120 | } |
---|
121 | if (copy_processed) |
---|
122 | fputs(line,outputf); |
---|
123 | } |
---|
124 | } |
---|
125 | } |
---|
126 | |
---|
127 | if(args.interactive_flag) |
---|
128 | fflush(outputf), fflush(failedf); |
---|
129 | |
---|
130 | } |
---|
131 | cmdline_parser_free(&args); |
---|
132 | } |
---|