* This routine allocates a new data structure to hold * a set of character normalization protos. It then fills in * the data structure by reading from the specified File. * @param File open text file to read normalization protos from * @param end_offset * Globals: none * @return Character normalization protos. * @note Exceptions: none * @note History: Wed Dec 19 16:38:49 1990, DSJ, Create
| 243 | * @note History: Wed Dec 19 16:38:49 1990, DSJ, Created. |
| 244 | */ |
| 245 | NORM_PROTOS *Classify::ReadNormProtos(FILE *File, inT64 end_offset) { |
| 246 | NORM_PROTOS *NormProtos; |
| 247 | int i; |
| 248 | char unichar[2 * UNICHAR_LEN + 1]; |
| 249 | UNICHAR_ID unichar_id; |
| 250 | LIST Protos; |
| 251 | int NumProtos; |
| 252 | |
| 253 | /* allocate and initialization data structure */ |
| 254 | NormProtos = (NORM_PROTOS *) Emalloc (sizeof (NORM_PROTOS)); |
| 255 | NormProtos->NumProtos = unicharset.size(); |
| 256 | NormProtos->Protos = (LIST *) Emalloc (NormProtos->NumProtos * sizeof(LIST)); |
| 257 | for (i = 0; i < NormProtos->NumProtos; i++) |
| 258 | NormProtos->Protos[i] = NIL_LIST; |
| 259 | |
| 260 | /* read file header and save in data structure */ |
| 261 | NormProtos->NumParams = ReadSampleSize (File); |
| 262 | NormProtos->ParamDesc = ReadParamDesc (File, NormProtos->NumParams); |
| 263 | |
| 264 | /* read protos for each class into a separate list */ |
| 265 | while ((end_offset < 0 || ftell(File) < end_offset) && |
| 266 | tfscanf(File, "%s %d", unichar, &NumProtos) == 2) { |
| 267 | if (unicharset.contains_unichar(unichar)) { |
| 268 | unichar_id = unicharset.unichar_to_id(unichar); |
| 269 | Protos = NormProtos->Protos[unichar_id]; |
| 270 | for (i = 0; i < NumProtos; i++) |
| 271 | Protos = |
| 272 | push_last (Protos, ReadPrototype (File, NormProtos->NumParams)); |
| 273 | NormProtos->Protos[unichar_id] = Protos; |
| 274 | } else { |
| 275 | cprintf("Error: unichar %s in normproto file is not in unichar set.\n", |
| 276 | unichar); |
| 277 | for (i = 0; i < NumProtos; i++) |
| 278 | FreePrototype(ReadPrototype (File, NormProtos->NumParams)); |
| 279 | } |
| 280 | SkipNewline(File); |
| 281 | } |
| 282 | return (NormProtos); |
| 283 | } /* ReadNormProtos */ |
| 284 | } // namespace tesseract |
nothing calls this directly
no test coverage detected