source: _old/app/src/lib/word.cc @ 8f395c8

Last change on this file since 8f395c8 was a6e708f, checked in by tom <tom@…>, 13 years ago

ANULOWANIE POPRZEDNIEGO COMMITU

Revert "Replacing old implementation with working implementation"

This reverts commit 1e121f45e2d091fcd34a893291b8453e350d5884.

Please enter the commit message for your changes. Lines starting
with '#' will be ignored, and an empty message aborts the commit.

Committer: tom <tom@lim.(none)>

On branch master
Changes to be committed:

(use "git reset HEAD <file>..." to unstage)

modified: _old/app/Makefile
deleted: _old/app/conf/Makefile
deleted: _old/app/conf/compiledic.conf
deleted: _old/app/conf/cor.conf
deleted: _old/app/conf/dgc.conf
deleted: _old/app/conf/dgp.conf
deleted: _old/app/conf/gph.conf
deleted: _old/app/conf/grp.conf
deleted: _old/app/conf/gue.conf
deleted: _old/app/conf/kor.conf
deleted: _old/app/conf/lem.conf
deleted: _old/app/conf/mar.conf
deleted: _old/app/conf/ser.conf
deleted: _old/app/conf/utt.conf
modified: _old/app/src/common/Makefile
modified: _old/app/src/compiledic/Makefile
modified: _old/app/src/compiledic/aut2fsa.cc
modified: _old/app/src/cor/Makefile
modified: _old/app/src/dgp/Makefile
new file: _old/app/src/dgp/canonize
new file: _old/app/src/dgp/dgc
modified: _old/app/src/dgp/grammar.hh
modified: _old/app/src/dgp/mgraph.hh
modified: _old/app/src/dgp/sgraph.hh
modified: _old/app/src/dgp/thesymbols.hh
new file: _old/app/src/dgp/tre
modified: _old/app/src/gue/Makefile
modified: _old/app/src/gue/guess.cc
modified: _old/app/src/kor/Makefile
modified: _old/app/src/kor/corlist.cc
modified: _old/app/src/kor/corr.cc
new file: _old/app/src/kor/corr.hh
modified: _old/app/src/kor/main.cc
modified: _old/app/src/lem/Makefile
modified: _old/app/src/lem/lem.cc
modified: _old/app/src/lib/Makefile
modified: _old/app/src/lib/auttools.cc
modified: _old/app/src/lib/symtab.cc
modified: _old/app/src/lib/tft.h
modified: _old/app/src/lib/tfti.h
modified: _old/app/src/lib/ttrans.h
modified: _old/app/src/lib/word.cc
modified: _old/app/src/lib/word.h
modified: _old/app/src/tok.c/Makefile
modified: _old/app/src/tok.c/cmdline_tok.ggo
modified: _old/app/src/tok.c/common_tok.cc
modified: _old/app/src/tok/Makefile
modified: _old/nawszelkiwypadek/tools/aut2fsa
modified: _old/nawszelkiwypadek/tools/cor_dic/makeLabels.pl
modified: _old/nawszelkiwypadek/tools/cor_dic/prep.pl
modified: _old/nawszelkiwypadek/tools/fsm2aut
modified: _old/nawszelkiwypadek/tools/gue_dic/canon.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/compile_user_dict.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/count_prefs.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/cut_prefs.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/makeLabels.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/prep.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/prep_user_dict.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/rmDup.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/stat.pl
modified: _old/nawszelkiwypadek/tools/gue_dic/stat_pre.pl
modified: _old/nawszelkiwypadek/tools/lem_dic/makeLabels.pl
modified: _old/nawszelkiwypadek/tools/lem_dic/prep.pl
modified: auto/defaults
modified: auto/options
modified: auto/output/Makefile
modified: auto/output/config_h
modified: auto/summary
modified: configure

  • Property mode set to 100644
File size: 5.9 KB
Line 
1//---------------------------------------------------------------------------
2#include "word.h"
3#include "auttools.h"
4#include <istream>
5//---------------------------------------------------------------------------
6
7using namespace std;
8
9//---------------------------------------------------------------------------
10
11void Word::autodescr(const char* fo, const char* de)
12{
13  strcpy(f,fo);
14  //  len=strlen(f);
15
16  char lemd[MAXDESCRLEN];
17  int i=strcspn(de,",");
18  strncpy(lemd,de,i);
19  lemd[i]='\0';
20  if(isdigit(lemd[0]))
21    fullform(f,lemd,l);  // je¶li lemat zakodowany
22  else
23    strcpy(l,lemd);     // je¶li lemat w pe³nej postaci
24  strcpy(d,de+i+1);
25}
26
27//---------------------------------------------------------------------------
28bool Word::cmp_w(Word a, Word b) {
29  return (a.w_suf() > b.w_suf());
30}
31//---------------------------------------------------------------------------
32bool Word::cmp_w_rev(Word a, Word b) {
33  return (a.w_suf() < b.w_suf());
34}
35//---------------------------------------------------------------------------
36bool cmp_w_fun(Word a, Word b) {
37  return (a.w_suf() > b.w_suf());
38}
39//---------------------------------------------------------------------------
40bool cmp_w_rev_fun(Word a, Word b) {
41  return (a.w_suf() < b.w_suf());
42}
43//---------------------------------------------------------------------------
44
45istream& operator>>(istream& is, Word& w)
46{
47  char temp[Word::MAXLEN+1];
48  char c;
49
50  int i=0;
51  while(i<Word::MAXLEN && is.get(c) && isalpha(c)) temp[i++]=c;
52  if(i==Word::MAXLEN) {
53    fprintf(stderr, "To long word");
54  }
55  if(i==0) is.clear(ios::badbit);
56  temp[i]='\0';
57  if(is)
58    is.putback(c);
59  strcpy(w.f,temp);
60  //  w.len=i;
61  return is;
62}
63
64//---------------------------------------------------------------------------
65
66ostream& operator<<(ostream& os, Word& w)
67{
68  if(*(w.f))
69    os << "<W " << w.form()
70       << ";" << w.lemma()
71       << ',' << w.descr() << '>';
72  return os;
73}
74
75//---------------------------------------------------------------------------
76Words::~Words() {
77  //   for (int i=0; i<tab.size(); ++i)
78//     delete(tab[i]);
79}
80//---------------------------------------------------------------------------
81
82int Words::find(const char* word) {
83  for (int i=0; i<cnt; ++i) {
84    if (strcmp(word, tab[i].form()) == 0) {
85        return i;
86    }
87  }
88  return -1;
89}
90
91
92//---------------------------------------------------------------------------
93
94int Words::find(const char* word, const char* descr) {
95  for (int i=0; i<cnt; ++i) {
96    if ((strcmp(word, tab[i].form()) == 0) && (strcmp(descr, tab[i].descr()) == 0)) {
97        return i;
98    }
99  }
100  return -1;
101}
102
103//---------------------------------------------------------------------------
104/* zwraca index nastepnego wyniku, podczas pierwszego wywolania
105 * zwraca index wyniku o najwiekszej wadze, przy drugim wywolaniu
106 * wynik z druga najwyzsza waga, itd.
107 * Jezeli nie ma juz wynikow - zwraca -1.
108 */
109int Words::next() {
110  float max = -1;
111  int result = -1;
112  for (int i=0; i<cnt; ++i) {
113    float w = tab[i].w_suf();
114    if (w>max && !tab[i].returned) {
115      max = w;
116      result = i;
117    }
118  }
119  if (result != -1)
120    tab[result].returned = 1;
121  return result;
122}
123
124//---------------------------------------------------------------------------
125void Words::sort() {
126//  sort(tab.begin(), tab.end(), Word::cmp_w); //NIE DZIALA
127}
128
129//---------------------------------------------------------------------------
130void Words::sort_rev() {
131//  sort(tab.begin(), tab.end(), cmp_w_rev_fun); // NIE DZIALA
132}
133
134//---------------------------------------------------------------------------
135
136int Words::add(const char* fo)
137{
138  int i = find(fo);
139  if(i!=-1) {
140    return i;
141  }
142 
143  if (cnt>=tab.capacity()-1)
144    tab.resize(tab.size()*2);
145 
146
147  Word o;
148  o.form(fo);
149  o.w_suf(0.0);
150  tab.push_back(o);
151//  tab[cnt].form(fo);
152//  tab[cnt].w_suf(0.0);
153
154
155  //  if(cnt<MAX-1) {
156  /* tab.push_back(new Word());
157    tab[cnt]->form(fo);
158    tab[cnt]->w_suf(0.0);
159    tab[cnt]->w_pref(0.0);*/
160    return cnt++;
161    //  }
162    //return -1;
163}
164
165//---------------------------------------------------------------------------
166
167 //TYMCZASOWO TAK(DLA CORA)
168int Words::add(const char* fo, float weight)
169{
170  int i = find(fo);
171  if(i!=-1) {
172    return i;
173  }
174 
175  if (cnt>=tab.capacity()-1)
176    tab.resize(tab.size()*2);
177 
178  Word o;
179  o.form(fo);
180  o.w_suf(weight);
181  tab.push_back(o);
182//  tab[cnt].form(fo);
183//  tab[cnt].w_suf(weight);
184 
185    return cnt++;
186    //  }
187    //return -1;
188}
189
190//---------------------------------------------------------------------------
191
192int Words::add(const char* fo, const char* des)
193{
194  char d[Word::MAXDESCRLEN];
195  int l=strcspn(des,",");
196  int ok=1;
197  if( *(des+l) == ',' )
198    {
199      strcpy(d,des+l+1);
200      //  printf("\t%s->%s,\n", des, d);
201      int i=find(fo, d);
202      if(i!=-1)
203        return i;
204    }
205  else
206    ok=0;
207
208  if (cnt>=tab.capacity()-1)
209    tab.resize(tab.size()*2);
210
211  tab[cnt].form(fo);
212  if(ok)
213    tab[cnt].autodescr(fo, des);
214  else
215    tab[cnt].autodescr(fo, "?,?");
216 
217  tab[cnt].w_suf(0.0);
218  tab[cnt].returned = 0;
219  /*
220  //  if(cnt<MAX-1) {
221    tab.push_back(new Word());
222    tab[cnt]->form(fo);
223    tab[cnt]->autodescr(fo,des);
224    tab[cnt]->w_suf(0.0);
225    tab[cnt]->w_pref(0.0);
226    //    printf("ok!\n");*/
227    return cnt++;
228    //  }
229    //  printf("hm\n");
230  return -1;
231}
232
233//---------------------------------------------------------------------------
234void Words::prn(ostream& os)
235{
236  for(int i=0; i<count(); ++i)
237    os << "<W " << tab[i].lemma() << ',' << tab[i].descr() << ">";
238}
239
240//---------------------------------------------------------------------------
241
242ostream& operator<<(ostream& os, Words& tab)
243{
244  /*  for(int i=0; i<tab.count(); ++i)
245    os << i << ". " << tab[i] << '\n';
246    return os;*/
247}
248
249//---------------------------------------------------------------------------
250
Note: See TracBrowser for help on using the repository browser.