source: app/src/lib/word.h @ ac7d970

help
Last change on this file since ac7d970 was ac7d970, checked in by pawelk <pawelk@…>, 16 years ago

Uaktualnilismy kora.

git-svn-id: svn://atos.wmid.amu.edu.pl/utt@23 e293616e-ec6a-49c2-aa92-f4a8b91c5d16

  • Property mode set to 100644
File size: 4.0 KB
Line 
1//---------------------------------------------------------------------------
2#ifndef _Word_h
3#define _Word_h
4//---------------------------------------------------------------------------
5//#include "alphabet.h"
6//#include "erro.h"
7#include "const.h"
8#include <iostream.h>
9
10#include <vector>
11//---------------------------------------------------------------------------
12
13using namespace std;
14
15
16
17class Word
18{
19public:
20  static const int MAXLEN=64;          // dac do global
21  static const int MAXDESCRLEN=80;     // dac do global
22
23private:
24  /// word form
25  char f[MAX_FORM];                // w wolnej chwili nazwy mozna zamienic na dluzsze
26
27  /// length
28  int _len_suf;  // dlugosc dopasowania koncowki...
29  //  int _len_pref; // ... i prefiksu
30
31  /// lemma
32  char l[MAX_FORM];
33
34  /// description
35  char d[MAX_DESC];
36
37  /// weight (probability)
38  float _w_suf; 
39  //  float _w_pref;
40public:
41  static bool cmp_w(Word a, Word b);
42
43  Word() : _len_suf(-1) { *f='\0'; returned=0; };
44  Word(const char* fo, const char* des) : _len_suf(-1) { autodescr(fo,des); _w_suf=1.0; returned=0; };
45
46  Word(const Word& w);
47
48  char* form() { return f; }  // przywrocic const
49  char* lemma() { return l; } // przywrocic const
50  char* descr() { return d; }
51  float w_suf() { return _w_suf; };
52  int len_suf() { return _len_suf; }
53
54
55  void form(const char* s) { strcpy(f,s); }
56  void lemma(const char* s) { strcpy(l,s); }
57  void descr(const char* s) { strcpy(d,s); };
58  void w_suf(float x) { _w_suf=x; };
59  void len_suf(int n) { _len_suf=n; };
60
61  bool operator==(const Word& w);
62  bool operator!=(const Word& w);
63  int cmp(const Word&);
64  int cmpi(const Word&);
65
66  char* operator!() { return f; };
67
68  operator bool() { return _len_suf>0; };
69
70  char* str() { return f; }
71
72  void autodescr(const char* fo, const char* des);
73
74  friend istream& operator>>(istream& is, Word& m);
75  friend ostream& operator<<(ostream& os, Word& m);
76
77  bool returned;
78
79};
80
81
82inline Word::Word(const Word& word)
83{ strcpy(f,word.f); strcpy(l,word.l); strcpy(d,word.d); _len_suf=word._len_suf; _w_suf=word._w_suf; returned = 0; }
84
85//---------------------------------------------------------------------------
86
87inline bool Word::operator==(const Word& w)
88{return _len_suf==w._len_suf && 
89   !strcmp(f,w.f) && !strcmp(l,w.l) && !strcmp(d,w.d); }
90
91//---------------------------------------------------------------------------
92
93inline bool Word::operator!=(const Word& w)
94{return _len_suf!=w._len_suf || 
95   strcmp(f,w.f) || strcmp(l,w.l) || strcmp(d,w.d);}
96
97//---------------------------------------------------------------------------
98
99inline int Word::cmp(const Word& w) { return strcmp(f,w.f); }
100
101//---------------------------------------------------------------------------
102
103//inline int Word::cmpi(const Word& w) { return PL.cmpi(f,w.f); }
104
105//---------------------------------------------------------------------------
106//---------------------------------------------------------------------------
107//---------------------------------------------------------------------------
108
109class Words
110{
111 private:
112  int find(const char* word);
113  int find(const char* word, const char* descr);
114 public:
115
116  static const int MAX=1024;
117
118  Words() : cnt(0) {tab.resize(MAX); };
119  ~Words();
120  Word& operator[](int i) { return tab[i]; }
121  int count() const { return cnt; }
122  void clear() { cnt=0; tab.clear(); }
123  int add(const char* fo);
124  int add(const char* fo, float weight);
125  int add(const char* fo, const char* des);
126
127  /* zwraca index nastepnego wyniku, podczas pierwszego wywolania
128   * zwraca index wyniku o najwiekszej wadze, przy drugim wywolaniu
129   * wynik z druga najwyzsza waga, itd.
130   * Jezeli nie ma juz wynikow - zwraca -1.
131   */
132  int next();
133
134  void sort();
135
136  void prn(ostream& os);
137
138//  friend class Lem;
139//  friend class AuxLem;
140  friend ostream& operator<<(ostream& os, Words& tab);
141  vector<Word> tab;
142  int cnt;
143
144};
145
146//---------------------------------------------------------------------------
147
148#endif
149
Note: See TracBrowser for help on using the repository browser.