source: app/src/lib/word.h @ 8d3e6ab

help
Last change on this file since 8d3e6ab was 25ae32e, checked in by obrebski <obrebski@…>, 16 years ago

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