00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #ifndef RATNGS_H
00021 #define RATNGS_H
00022
00023 #include <assert.h>
00024
00025 #include "clst.h"
00026 #include "genericvector.h"
00027 #include "notdll.h"
00028 #include "unichar.h"
00029 #include "unicharset.h"
00030 #include "werd.h"
00031
00032 class BLOB_CHOICE: public ELIST_LINK
00033 {
00034 public:
00035 BLOB_CHOICE() {
00036 unichar_id_ = INVALID_UNICHAR_ID;
00037 config_ = '\0';
00038 rating_ = MAX_FLOAT32;
00039 certainty_ = -MAX_FLOAT32;
00040 script_id_ = -1;
00041 }
00042 BLOB_CHOICE(UNICHAR_ID src_unichar_id,
00043 float src_rating,
00044 float src_cert,
00045 inT8 src_config,
00046 int script_id);
00047 BLOB_CHOICE(const BLOB_CHOICE &other);
00048 ~BLOB_CHOICE() {}
00049 UNICHAR_ID unichar_id() const {
00050 return unichar_id_;
00051 }
00052 float rating() const {
00053 return rating_;
00054 }
00055 float certainty() const {
00056 return certainty_;
00057 }
00058 inT8 config() const {
00059 return config_;
00060 }
00061 int script_id() const {
00062 return script_id_;
00063 }
00064
00065 void set_unichar_id(UNICHAR_ID newunichar_id) {
00066 unichar_id_ = newunichar_id;
00067 }
00068 void set_rating(float newrat) {
00069 rating_ = newrat;
00070 }
00071 void set_certainty(float newrat) {
00072 certainty_ = newrat;
00073 }
00074 void set_config(inT8 newfont) {
00075 config_ = newfont;
00076 }
00077 void set_script(int newscript_id) {
00078 script_id_ = newscript_id;
00079 }
00080
00081 static BLOB_CHOICE* deep_copy(const BLOB_CHOICE* src) {
00082 BLOB_CHOICE* choice = new BLOB_CHOICE;
00083 *choice = *src;
00084 return choice;
00085 }
00086
00087 NEWDELETE
00088 private:
00089 UNICHAR_ID unichar_id_;
00090 char config_;
00091 inT16 junk2_;
00092 float rating_;
00093 float certainty_;
00094 int script_id_;
00095 };
00096
00097
00098 ELISTIZEH (BLOB_CHOICE) CLISTIZEH (BLOB_CHOICE_LIST)
00099
00100
00101 enum PermuterType {
00102 NO_PERM,
00103 PUNC_PERM,
00104 TOP_CHOICE_PERM,
00105 LOWER_CASE_PERM,
00106 UPPER_CASE_PERM,
00107 NUMBER_PERM,
00108 SYSTEM_DAWG_PERM,
00109 DOC_DAWG_PERM,
00110 USER_DAWG_PERM,
00111 FREQ_DAWG_PERM,
00112 COMPOUND_PERM,
00113 };
00114
00115 class WERD_CHOICE {
00116 public:
00117 WERD_CHOICE() { this->init(8); }
00118 WERD_CHOICE(int reserved) { this->init(reserved); }
00119 WERD_CHOICE(const char *src_string,
00120 const char *src_lengths,
00121 float src_rating,
00122 float src_certainty,
00123 uinT8 src_permuter,
00124 const UNICHARSET &unicharset) {
00125 this->init(src_string, src_lengths, src_rating,
00126 src_certainty, src_permuter, unicharset);
00127 }
00128 WERD_CHOICE (const char *src_string, const UNICHARSET &unicharset);
00129 WERD_CHOICE(const WERD_CHOICE &word) {
00130 this->init(word.length());
00131 this->operator=(word);
00132 }
00133 ~WERD_CHOICE();
00134
00135 inline int length() const {
00136 return length_;
00137 }
00138 inline const UNICHAR_ID *unichar_ids() const {
00139 return unichar_ids_;
00140 }
00141 inline const UNICHAR_ID unichar_id(int index) const {
00142 assert(index < length_);
00143 return unichar_ids_[index];
00144 }
00145 inline const char *fragment_lengths() const {
00146 return fragment_lengths_;
00147 }
00148 inline const char fragment_length(int index) const {
00149 assert(index < length_);
00150 return fragment_lengths_[index];
00151 }
00152 inline float rating() const {
00153 return rating_;
00154 }
00155 inline float certainty() const {
00156 return certainty_;
00157 }
00158 inline uinT8 permuter() const {
00159 return permuter_;
00160 }
00161 inline bool fragment_mark() const {
00162 return fragment_mark_;
00163 }
00164 inline BLOB_CHOICE_LIST_CLIST* blob_choices() {
00165 return blob_choices_;
00166 }
00167 inline void set_unichar_id(UNICHAR_ID unichar_id, int index) {
00168 assert(index < length_);
00169 unichar_ids_[index] = unichar_id;
00170 }
00171 inline void set_rating(float new_val) {
00172 rating_ = new_val;
00173 }
00174 inline void set_certainty(float new_val) {
00175 certainty_ = new_val;
00176 }
00177 inline void set_permuter(uinT8 perm) {
00178 permuter_ = perm;
00179 }
00180 inline void set_fragment_mark(bool new_fragment_mark) {
00181 fragment_mark_ = new_fragment_mark;
00182 }
00183 void set_blob_choices(BLOB_CHOICE_LIST_CLIST *blob_choices);
00184
00185
00186 inline void double_the_size() {
00187 unichar_ids_ = GenericVector<UNICHAR_ID>::double_the_size_memcpy(
00188 reserved_, unichar_ids_);
00189 fragment_lengths_ = GenericVector<char>::double_the_size_memcpy(
00190 reserved_, fragment_lengths_);
00191 reserved_ *= 2;
00192 }
00193
00194
00195
00196 inline void init(int reserved) {
00197 reserved_ = reserved;
00198 unichar_ids_ = new UNICHAR_ID[reserved];
00199 fragment_lengths_ = new char[reserved];
00200 length_ = 0;
00201 rating_ = 0.0;
00202 certainty_ = MAX_FLOAT32;
00203 permuter_ = NO_PERM;
00204 fragment_mark_ = false;
00205 blob_choices_ = NULL;
00206 unichar_string_ = "";
00207 unichar_lengths_ = "";
00208 }
00209
00210
00211
00212
00213
00214
00215 void init(const char *src_string, const char *src_lengths,
00216 float src_rating, float src_certainty,
00217 uinT8 src_permuter, const UNICHARSET ¤t_unicharset);
00218
00219
00220 inline void make_bad() {
00221 length_ = 0;
00222 rating_ = MAX_FLOAT32;
00223 certainty_ = -MAX_FLOAT32;
00224 fragment_mark_ = false;
00225 unichar_string_ = "";
00226 unichar_lengths_ = "";
00227 }
00228
00229
00230
00231
00232 inline void append_unichar_id_space_allocated(
00233 UNICHAR_ID unichar_id, char fragment_length,
00234 float rating, float certainty) {
00235 assert(reserved_ > length_);
00236 length_++;
00237 this->set_unichar_id(unichar_id, fragment_length,
00238 rating, certainty, length_-1);
00239 }
00240
00241 void append_unichar_id(UNICHAR_ID unichar_id, char fragment_length,
00242 float rating, float certainty);
00243
00244 inline void set_unichar_id(UNICHAR_ID unichar_id, char fragment_length,
00245 float rating, float certainty, int index) {
00246 assert(index < length_);
00247 unichar_ids_[index] = unichar_id;
00248 fragment_lengths_[index] = fragment_length;
00249 rating_ += rating;
00250 if (certainty < certainty_) {
00251 certainty_ = certainty;
00252 }
00253 }
00254
00255 bool contains_unichar_id(UNICHAR_ID unichar_id) const;
00256 void remove_unichar_ids(int index, int num);
00257 inline void remove_last_unichar_id() { --length_; }
00258 inline void remove_unichar_id(int index) { this->remove_unichar_ids(index, 1); }
00259 void string_and_lengths(const UNICHARSET ¤t_unicharset,
00260 STRING *word_str, STRING *word_lengths_str) const;
00261 const STRING debug_string(const UNICHARSET ¤t_unicharset) const {
00262 STRING word_str;
00263 for (int i = 0; i < length_; ++i) {
00264 word_str += current_unicharset.debug_str(unichar_ids_[i]);
00265 word_str += " ";
00266 }
00267 return word_str;
00268 }
00269
00270
00271
00272 void populate_unichars(const UNICHARSET ¤t_unicharset) {
00273 this->string_and_lengths(current_unicharset, &unichar_string_,
00274 &unichar_lengths_);
00275 }
00276
00277
00278 const STRING &unichar_string() const {
00279 assert(unichar_string_.length() <= 0 ||
00280 unichar_string_.length() >= length_);
00281 return unichar_string_;
00282 }
00283
00284
00285 const STRING &unichar_lengths() const {
00286 assert(unichar_lengths_.length() <= 0 ||
00287 unichar_lengths_.length() == length_);
00288 return unichar_lengths_;
00289 }
00290 const void print() const { this->print(""); }
00291 const void print(const char *msg) const;
00292
00293 WERD_CHOICE& operator+= (
00294 const WERD_CHOICE & second);
00295
00296 WERD_CHOICE& operator= (const WERD_CHOICE& source);
00297
00298 NEWDELETE private:
00299 UNICHAR_ID *unichar_ids_;
00300 char *fragment_lengths_;
00301 int reserved_;
00302 int length_;
00303 float rating_;
00304 float certainty_;
00305 uinT8 permuter_;
00306 bool fragment_mark_;
00307
00308
00309 BLOB_CHOICE_LIST_CLIST *blob_choices_;
00310
00311
00312
00313 STRING unichar_string_;
00314 STRING unichar_lengths_;
00315 bool unichar_info_present;
00316
00317 private:
00318 void delete_blob_choices();
00319 };
00320
00321
00322 ELISTIZEH (WERD_CHOICE)
00323 typedef GenericVector<BLOB_CHOICE_LIST *> BLOB_CHOICE_LIST_VECTOR;
00324 typedef GenericVector<WERD_CHOICE_LIST *> WERD_CHOICE_LIST_VECTOR;
00325
00326 typedef void (*POLY_TESTER) (const STRING&, PBLOB *, DENORM *, BOOL8,
00327 char *, inT32, BLOB_CHOICE_LIST *);
00328
00329 void print_ratings_list(const char *msg, BLOB_CHOICE_LIST *ratings);
00330 void print_ratings_list(
00331 const char *msg,
00332 BLOB_CHOICE_LIST *ratings,
00333 const UNICHARSET ¤t_unicharset
00334
00335 );
00336 void print_ratings_info(
00337 FILE *fp,
00338 BLOB_CHOICE_LIST *ratings,
00339 const UNICHARSET ¤t_unicharset
00340
00341 );
00342 void print_char_choices_list(
00343 const char *msg,
00344 const BLOB_CHOICE_LIST_VECTOR &char_choices,
00345 const UNICHARSET ¤t_unicharset,
00346 BOOL8 detailed
00347 );
00348
00349 #endif