81 if (debug_level)
tprintf(
"Reading ambiguities\n");
83 int test_ambig_part_size;
84 int replacement_ambig_part_size;
88 char *buffer =
new char[kBufferSize];
96 ASSERT_HOST(ambig_file->FGets(buffer, kBufferSize) != NULL &&
99 version =
static_cast<int>(strtol(buffer+1, NULL, 10));
102 ambig_file->Rewind();
104 while (ambig_file->FGets(buffer, kBufferSize) != NULL) {
106 if (debug_level > 2)
tprintf(
"read line %s\n", buffer);
108 if (!ParseAmbiguityLine(line_num, version, debug_level, encoder_set,
109 buffer, &test_ambig_part_size, test_unichar_ids,
110 &replacement_ambig_part_size,
111 replacement_string, &type))
continue;
113 AmbigSpec *ambig_spec =
new AmbigSpec();
114 if (!InsertIntoTable((type ==
REPLACE_AMBIG) ? replace_ambigs_
116 test_ambig_part_size, test_unichar_ids,
117 replacement_ambig_part_size, replacement_string, type,
118 ambig_spec, unicharset))
122 if (test_ambig_part_size == 1 &&
124 if (one_to_one_definite_ambigs_[test_unichar_ids[0]] == NULL) {
125 one_to_one_definite_ambigs_[test_unichar_ids[0]] =
new UnicharIdVector();
127 one_to_one_definite_ambigs_[test_unichar_ids[0]]->push_back(
128 ambig_spec->correct_ngram_id);
131 if (use_ambigs_for_adaption) {
135 if (unicharset->
encode_string(replacement_string,
true, &encoding,
137 for (i = 0; i < test_ambig_part_size; ++i) {
138 if (ambigs_for_adaption_[test_unichar_ids[i]] == NULL) {
141 adaption_ambigs_entry = ambigs_for_adaption_[test_unichar_ids[i]];
142 for (
int r = 0; r < encoding.
size(); ++r) {
147 for (j = 0; j < adaption_ambigs_entry->size() &&
148 (*adaption_ambigs_entry)[j] > id_to_insert; ++j);
149 if (j < adaption_ambigs_entry->size()) {
150 if ((*adaption_ambigs_entry)[j] != id_to_insert) {
151 adaption_ambigs_entry->insert(id_to_insert, j);
154 adaption_ambigs_entry->push_back(id_to_insert);
164 if (use_ambigs_for_adaption) {
165 for (i = 0; i < ambigs_for_adaption_.size(); ++i) {
166 adaption_ambigs_entry = ambigs_for_adaption_[i];
167 if (adaption_ambigs_entry == NULL)
continue;
168 for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
169 UNICHAR_ID ambig_id = (*adaption_ambigs_entry)[j];
170 if (reverse_ambigs_for_adaption_[ambig_id] == NULL) {
173 reverse_ambigs_for_adaption_[ambig_id]->push_back(i);
179 if (debug_level > 1) {
180 for (
int tbl = 0; tbl < 2; ++tbl) {
182 (tbl == 0) ? replace_ambigs_ : dang_ambigs_;
183 for (i = 0; i < print_table.size(); ++i) {
184 AmbigSpec_LIST *lst = print_table[i];
185 if (lst == NULL)
continue;
187 tprintf(
"%s Ambiguities for %s:\n",
188 (tbl == 0) ?
"Replaceable" :
"Dangerous",
191 AmbigSpec_IT lst_it(lst);
192 for (lst_it.mark_cycle_pt(); !lst_it.cycled_list(); lst_it.forward()) {
193 AmbigSpec *ambig_spec = lst_it.data();
201 if (use_ambigs_for_adaption) {
202 for (
int vec_id = 0; vec_id < 2; ++vec_id) {
204 ambigs_for_adaption_ : reverse_ambigs_for_adaption_;
205 for (i = 0; i < vec.
size(); ++i) {
206 adaption_ambigs_entry = vec[i];
207 if (adaption_ambigs_entry != NULL) {
208 tprintf(
"%sAmbigs for adaption for %s:\n",
209 (vec_id == 0) ?
"" :
"Reverse ",
211 for (j = 0; j < adaption_ambigs_entry->size(); ++j) {
213 (*adaption_ambigs_entry)[j]).
string());
GenericVector< UNICHAR_ID > UnicharIdVector
static void print(const UNICHAR_ID array[], const UNICHARSET &unicharset)
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
const int kMaxAmbigStringSize
STRING debug_str(UNICHAR_ID id) const
GenericVector< AmbigSpec_LIST * > UnicharAmbigsVector
void chomp_string(char *str)