1 /******************************************************************************
2 ** Filename: cutoffs.c
3 ** Purpose: Routines to manipulate an array of class cutoffs.
4 ** Author: Dan Johnson
5 ** History: Wed Feb 20 09:28:51 1991, DSJ, Created.
6 **
7 ** (c) Copyright Hewlett-Packard Company, 1988.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 ******************************************************************************/
18 /**----------------------------------------------------------------------------
19 Include Files and Type Defines
20 ----------------------------------------------------------------------------**/
21 #include "cutoffs.h"
22
23 #include <stdio.h>
24
25 #include "classify.h"
26 #include "efio.h"
27 #include "globals.h"
28 #include "helpers.h"
29 #include "scanutils.h"
30 #include "serialis.h"
31 #include "unichar.h"
32
33 #define REALLY_QUOTE_IT(x) QUOTE_IT(x)
34
35 #define MAX_CUTOFF 1000
36
37 /**----------------------------------------------------------------------------
38 Public Code
39 ----------------------------------------------------------------------------**/
40 /*---------------------------------------------------------------------------*/
41 namespace tesseract {
ReadNewCutoffs(FILE * CutoffFile,inT64 end_offset,CLASS_CUTOFF_ARRAY Cutoffs)42 void Classify::ReadNewCutoffs(FILE *CutoffFile, inT64 end_offset,
43 CLASS_CUTOFF_ARRAY Cutoffs) {
44 /*
45 ** Parameters:
46 ** Filename name of file containing cutoff definitions
47 ** Cutoffs array to put cutoffs into
48 ** Globals: none
49 ** Operation: Open Filename, read in all of the class-id/cutoff pairs
50 ** and insert them into the Cutoffs array. Cutoffs are
51 ** indexed in the array by class id. Unused entries in the
52 ** array are set to an arbitrarily high cutoff value.
53 ** Return: none
54 ** Exceptions: none
55 ** History: Wed Feb 20 09:38:26 1991, DSJ, Created.
56 */
57 char Class[UNICHAR_LEN + 1];
58 CLASS_ID ClassId;
59 int Cutoff;
60 int i;
61
62 for (i = 0; i < MAX_NUM_CLASSES; i++)
63 Cutoffs[i] = MAX_CUTOFF;
64
65 while ((end_offset < 0 || ftell(CutoffFile) < end_offset) &&
66 fscanf(CutoffFile, "%" REALLY_QUOTE_IT(UNICHAR_LEN) "s %d",
67 Class, &Cutoff) == 2) {
68 if (strcmp(Class, "NULL") == 0) {
69 ClassId = unicharset.unichar_to_id(" ");
70 } else {
71 ClassId = unicharset.unichar_to_id(Class);
72 }
73 Cutoffs[ClassId] = Cutoff;
74 SkipNewline(CutoffFile);
75 }
76 } /* ReadNewCutoffs */
77
78 } // namespace tesseract
79