source: src/lib/word.h @ 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: 4.2 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>
9#include <cstring>
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  static bool cmp_w_rev(Word a, Word b);
43
44  Word() : _len_suf(-1) { *f='\0'; returned=0; };
45  Word(const char* fo, const char* des) : _len_suf(-1) { autodescr(fo,des); _w_suf=1.0; returned=0; };
46
47  Word(const Word& w);
48
49  char* form() { return f; }  // przywrocic const
50  char* lemma() { return l; } // przywrocic const
51  char* descr() { return d; }
52  float w_suf() { return _w_suf; };
53  int len_suf() { return _len_suf; }
54
55
56  void form(const char* s) { strcpy(f,s); }
57  void lemma(const char* s) { strcpy(l,s); }
58  void descr(const char* s) { strcpy(d,s); };
59  void w_suf(float x) { _w_suf=x; };
60  void len_suf(int n) { _len_suf=n; };
61
62  bool operator==(const Word& w);
63  bool operator!=(const Word& w);
64  int cmp(const Word&);
65  int cmpi(const Word&);
66
67  char* operator!() { return f; };
68
69  operator bool() { return _len_suf>0; };
70
71  char* str() { return f; }
72
73  void autodescr(const char* fo, const char* des);
74
75  friend istream& operator>>(istream& is, Word& m);
76  friend ostream& operator<<(ostream& os, Word& m);
77
78  bool returned;
79
80};
81
82
83inline Word::Word(const Word& word)
84{ strcpy(f,word.f); strcpy(l,word.l); strcpy(d,word.d); _len_suf=word._len_suf; _w_suf=word._w_suf; returned = 0; }
85
86//---------------------------------------------------------------------------
87
88inline bool Word::operator==(const Word& w)
89{return _len_suf==w._len_suf && 
90   !strcmp(f,w.f) && !strcmp(l,w.l) && !strcmp(d,w.d); }
91
92//---------------------------------------------------------------------------
93
94inline bool Word::operator!=(const Word& w)
95{return _len_suf!=w._len_suf || 
96   strcmp(f,w.f) || strcmp(l,w.l) || strcmp(d,w.d);}
97
98//---------------------------------------------------------------------------
99
100inline int Word::cmp(const Word& w) { return strcmp(f,w.f); }
101
102//---------------------------------------------------------------------------
103
104//inline int Word::cmpi(const Word& w) { return PL.cmpi(f,w.f); }
105
106//---------------------------------------------------------------------------
107
108
109
110
111bool cmp_w_fun(Word a, Word b);
112bool cmp_w_rev_fun(Word a, Word b);
113
114
115//---------------------------------------------------------------------------
116//---------------------------------------------------------------------------
117
118class Words
119{
120 private:
121  int find(const char* word);
122  int find(const char* word, const char* descr);
123 public:
124
125  static const int MAX=1024;
126
127  Words() : cnt(0) {tab.resize(MAX); };
128  ~Words();
129  Word& operator[](int i) { return tab[i]; }
130  int count() const { return cnt; }
131  void clear() { cnt=0; tab.clear(); }
132  int add(const char* fo);
133  int add(const char* fo, float weight);
134  int add(const char* fo, const char* des);
135
136  /* zwraca index nastepnego wyniku, podczas pierwszego wywolania
137   * zwraca index wyniku o najwiekszej wadze, przy drugim wywolaniu
138   * wynik z druga najwyzsza waga, itd.
139   * Jezeli nie ma juz wynikow - zwraca -1.
140   */
141  int next();
142
143  void sort();
144  void sort_rev();
145
146  void prn(ostream& os);
147
148//  friend class Lem;
149//  friend class AuxLem;
150  friend ostream& operator<<(ostream& os, Words& tab);
151  vector<Word> tab;
152  int cnt;
153
154};
155
156//---------------------------------------------------------------------------
157
158#endif
159
Note: See TracBrowser for help on using the repository browser.