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

Last change on this file since a26cf42 was 2f8d6d8, checked in by to <to@…>, 15 years ago

Poprawki kodu w C++ (nazwy plikow naglowkowych, using ...).

modified: compiledic/aut2fsa.cc
modified: dgp/grammar.hh
modified: dgp/mgraph.hh
modified: dgp/sgraph.hh
modified: dgp/thesymbols.hh
modified: gue/guess.cc
modified: kor/corlist.cc
modified: lem/lem.cc
modified: lib/symtab.cc
modified: lib/tft.h
modified: lib/tfti.h
modified: lib/ttrans.h
modified: lib/word.cc
modified: lib/word.h

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