MCPcopy Create free account
hub / github.com/creatale/node-dv / ReadNormProtos

Method ReadNormProtos

deps/tesseract/classify/normmatch.cpp:245–283  ·  view source on GitHub ↗

* 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

Source from the content-addressed store, hash-verified

243 * @note History: Wed Dec 19 16:38:49 1990, DSJ, Created.
244 */
245NORM_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

Callers

nothing calls this directly

Calls 12

EmallocFunction · 0.85
ReadSampleSizeFunction · 0.85
ReadParamDescFunction · 0.85
tfscanfFunction · 0.85
push_lastFunction · 0.85
ReadPrototypeFunction · 0.85
cprintfFunction · 0.85
FreePrototypeFunction · 0.85
SkipNewlineFunction · 0.85
contains_unicharMethod · 0.80
sizeMethod · 0.45
unichar_to_idMethod · 0.45

Tested by

no test coverage detected