21 #ifndef TESSERACT_CCUTIL_AMBIGS_H_
22 #define TESSERACT_CCUTIL_AMBIGS_H_
30 #define MAX_AMBIG_SIZE 10
36 static const int kUnigramAmbigsBufferSize = 1000;
37 static const char kAmbigNgramSeparator[] = {
' ',
'\0' };
38 static const char kAmbigDelimiters[] =
"\t ";
39 static const char kIllegalMsg[] =
40 "Illegal ambiguity specification on line %d\n";
41 static const char kIllegalUnicharMsg[] =
42 "Illegal unichar %s in ambiguity specification\n";
66 while (*ptr1 != INVALID_UNICHAR_ID && *ptr2 != INVALID_UNICHAR_ID) {
67 if (*ptr1 != *ptr2)
return *ptr1 < *ptr2 ? -1 : 1;
71 if (*ptr1 == INVALID_UNICHAR_ID && *ptr2 == INVALID_UNICHAR_ID)
return 0;
72 return *ptr1 == INVALID_UNICHAR_ID ? -1 : 1;
77 static inline int find_in(
const UnicharIdVector& uid_vec,
79 for (
int i = 0; i < uid_vec.
size(); ++i)
80 if (uid_vec[i] == uid)
return i;
91 }
while (dst[i++] != INVALID_UNICHAR_ID);
100 if (*ptr == INVALID_UNICHAR_ID)
tprintf(
"[Empty]");
101 while (*ptr != INVALID_UNICHAR_ID) {
106 while (*ptr != INVALID_UNICHAR_ID)
tprintf(
"%d ", *ptr++);
123 *
reinterpret_cast<const AmbigSpec *
const *
>(spec1);
125 *
reinterpret_cast<const AmbigSpec *
const *
>(spec2);
127 if (result != 0)
return result;
150 one_to_one_definite_ambigs_.delete_data_pointers();
153 const UnicharAmbigsVector &
dang_ambigs()
const {
return dang_ambigs_; }
158 bool use_ambigs_for_adaption);
176 TFile *ambigs_file,
int debug_level,
177 bool use_ambigs_for_adaption,
UNICHARSET *unicharset);
182 if (one_to_one_definite_ambigs_.empty())
return NULL;
183 return one_to_one_definite_ambigs_[unichar_id];
193 if (ambigs_for_adaption_.empty())
return NULL;
194 return ambigs_for_adaption_[unichar_id];
202 if (reverse_ambigs_for_adaption_.empty())
return NULL;
203 return reverse_ambigs_for_adaption_[unichar_id];
207 bool ParseAmbiguityLine(
int line_num,
int version,
int debug_level,
209 int *test_ambig_part_size,
211 int *replacement_ambig_part_size,
212 char *replacement_string,
int *type);
213 bool InsertIntoTable(UnicharAmbigsVector &table,
214 int test_ambig_part_size,
UNICHAR_ID *test_unichar_ids,
215 int replacement_ambig_part_size,
216 const char *replacement_string,
int type,
219 UnicharAmbigsVector dang_ambigs_;
220 UnicharAmbigsVector replace_ambigs_;
228 #endif // TESSERACT_CCUTIL_AMBIGS_H_
const UnicharIdVector * OneToOneDefiniteAmbigs(UNICHAR_ID unichar_id) const
static int compare(const UNICHAR_ID array1[], const UNICHAR_ID array2[])
static int compare_ambig_specs(const void *spec1, const void *spec2)
const UnicharAmbigsVector & replace_ambigs() const
UNICHAR_ID wrong_ngram[MAX_AMBIG_SIZE+1]
void LoadUniversal(const UNICHARSET &encoder_set, UNICHARSET *unicharset)
GenericVector< AmbigSpec_LIST * > UnicharAmbigsVector
static int copy(const UNICHAR_ID src[], UNICHAR_ID dst[])
void InitUnicharAmbigs(const UNICHARSET &unicharset, bool use_ambigs_for_adaption)
void LoadUnicharAmbigs(const UNICHARSET &encoder_set, TFile *ambigs_file, int debug_level, bool use_ambigs_for_adaption, UNICHARSET *unicharset)
void delete_data_pointers()
const char *const id_to_unichar(UNICHAR_ID id) const
static int find_in(const UnicharIdVector &uid_vec, const UNICHAR_ID uid)
const UnicharAmbigsVector & dang_ambigs() const
UNICHAR_ID correct_fragments[MAX_AMBIG_SIZE+1]
UNICHAR_ID correct_ngram_id
const UnicharIdVector * ReverseAmbigsForAdaption(UNICHAR_ID unichar_id) const
static void print(const UNICHAR_ID array[], const UNICHARSET &unicharset)
const UnicharIdVector * AmbigsForAdaption(UNICHAR_ID unichar_id) const
GenericVector< UNICHAR_ID > UnicharIdVector