77 if (debug_level)
tprintf(
"Reading ambiguities\n");
79 int test_ambig_part_size;
80 int replacement_ambig_part_size;
84 char *buffer =
new char[kBufferSize];
92 ASSERT_HOST(ambig_file->FGets(buffer, kBufferSize) !=
nullptr &&
95 version =
static_cast<int>(strtol(buffer+1,
nullptr, 10));
100 while (ambig_file->FGets(buffer, kBufferSize) !=
nullptr) {
102 if (debug_level > 2)
tprintf(
"read line %s\n", buffer);
104 if (!ParseAmbiguityLine(line_num, version, debug_level, encoder_set,
105 buffer, &test_ambig_part_size, test_unichar_ids,
106 &replacement_ambig_part_size,
107 replacement_string, &type))
continue;
109 AmbigSpec *ambig_spec =
new AmbigSpec();
110 if (!InsertIntoTable((type ==
REPLACE_AMBIG) ? replace_ambigs_
112 test_ambig_part_size, test_unichar_ids,
113 replacement_ambig_part_size, replacement_string, type,
114 ambig_spec, unicharset))
118 if (test_ambig_part_size == 1 &&
120 if (one_to_one_definite_ambigs_[test_unichar_ids[0]] ==
nullptr) {
121 one_to_one_definite_ambigs_[test_unichar_ids[0]] =
new UnicharIdVector();
123 one_to_one_definite_ambigs_[test_unichar_ids[0]]->push_back(
124 ambig_spec->correct_ngram_id);
127 if (use_ambigs_for_adaption) {
131 if (unicharset->
encode_string(replacement_string,
true, &encoding,
133 for (i = 0; i < test_ambig_part_size; ++i) {
134 if (ambigs_for_adaption_[test_unichar_ids[i]] ==
nullptr) {
137 adaption_ambigs_entry = ambigs_for_adaption_[test_unichar_ids[i]];
138 for (
int r = 0; r < encoding.
size(); ++r) {
143 for (j = 0; j < adaption_ambigs_entry->size() &&
144 (*adaption_ambigs_entry)[j] > id_to_insert; ++j);
145 if (j < adaption_ambigs_entry->size()) {
146 if ((*adaption_ambigs_entry)[j] != id_to_insert) {
147 adaption_ambigs_entry->insert(id_to_insert, j);
150 adaption_ambigs_entry->push_back(id_to_insert);
160 if (use_ambigs_for_adaption) {
161 for (i = 0; i < ambigs_for_adaption_.size(); ++i) {
162 adaption_ambigs_entry = ambigs_for_adaption_[i];
163 if (adaption_ambigs_entry ==
nullptr)
continue;
164 for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
165 UNICHAR_ID ambig_id = (*adaption_ambigs_entry)[j];
166 if (reverse_ambigs_for_adaption_[ambig_id] ==
nullptr) {
169 reverse_ambigs_for_adaption_[ambig_id]->push_back(i);
175 if (debug_level > 1) {
176 for (
int tbl = 0; tbl < 2; ++tbl) {
178 (tbl == 0) ? replace_ambigs_ : dang_ambigs_;
179 for (i = 0; i < print_table.size(); ++i) {
180 AmbigSpec_LIST *lst = print_table[i];
181 if (lst ==
nullptr)
continue;
183 tprintf(
"%s Ambiguities for %s:\n",
184 (tbl == 0) ?
"Replaceable" :
"Dangerous",
187 AmbigSpec_IT lst_it(lst);
188 for (lst_it.mark_cycle_pt(); !lst_it.cycled_list(); lst_it.forward()) {
189 AmbigSpec *ambig_spec = lst_it.data();
197 if (use_ambigs_for_adaption) {
198 for (
int vec_id = 0; vec_id < 2; ++vec_id) {
200 ambigs_for_adaption_ : reverse_ambigs_for_adaption_;
201 for (i = 0; i < vec.
size(); ++i) {
202 adaption_ambigs_entry = vec[i];
203 if (adaption_ambigs_entry !=
nullptr) {
204 tprintf(
"%sAmbigs for adaption for %s:\n",
205 (vec_id == 0) ?
"" :
"Reverse ",
207 for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
209 (*adaption_ambigs_entry)[j]).
string());
const int kMaxAmbigStringSize
bool encode_string(const char *str, bool give_up_on_failure, GenericVector< UNICHAR_ID > *encoding, GenericVector< char > *lengths, int *encoded_length) const
const char * string() const
GenericVector< UNICHAR_ID > UnicharIdVector
void chomp_string(char *str)
static void print(const UNICHAR_ID array[], const UNICHARSET &unicharset)
STRING debug_str(UNICHAR_ID id) const
DLLSYM void tprintf(const char *format,...)
GenericVector< AmbigSpec_LIST * > UnicharAmbigsVector