• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* -*-C-*-
2  ********************************************************************************
3  *
4  * File:        choices.h  (Formerly choices.h)
5  * Description:  Handle the new ratings choices for Wise Owl
6  * Author:       Mark Seaman, OCR Technology
7  * Created:      Fri Sep 22 14:05:51 1989
8  * Modified:     Fri Jan  4 12:04:01 1991 (Mark Seaman) marks@hpgrlt
9  * Language:     C
10  * Package:      N/A
11  * Status:       Experimental (Do Not Distribute)
12  *
13  * (c) Copyright 1989, Hewlett-Packard Company.
14  ** Licensed under the Apache License, Version 2.0 (the "License");
15  ** you may not use this file except in compliance with the License.
16  ** You may obtain a copy of the License at
17  ** http://www.apache.org/licenses/LICENSE-2.0
18  ** Unless required by applicable law or agreed to in writing, software
19  ** distributed under the License is distributed on an "AS IS" BASIS,
20  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21  ** See the License for the specific language governing permissions and
22  ** limitations under the License.
23  *
24  ********************************************************************************
25  *
26  *                         FUNCTIONS TO CALL
27  *                         -----------------
28  * append_char_choice - Create a new choice for a character and add it to the list.
29  * class_rating       - Return the rating of a given character class.
30  * class_string       - Return the string corresponding to a character choice.
31  * free_choice        - Free up the memory taken by one choice rating.
32  * new_choice         - Create one choice record one set up the fields.
33  *
34  *********************************************************************************/
35 
36 #ifndef CHOICES_H
37 #define CHOICES_H
38 
39 #include <stdio.h>
40 #include <string.h>
41 
42 #include "oldlist.h"
43 #include "unicharset.h"
44 
45 /*----------------------------------------------------------------------
46                 T y p e s
47 ----------------------------------------------------------------------*/
48 typedef LIST CHOICES;            /* CHOICES */
49 //typedef float PROBABILITY;       /* PROBABILITY */
50 //typedef char PERM_TYPE;          /* PERMUTER CODE */
51 
52 typedef struct choicestruct
53 {                                /* A_CHOICE */
54   float rating;
55   float certainty;
56   char permuter;
57   inT8 config;
58   char *string;
59   char *lengths;           // length of each unichar in the string
60   int script_id;
61   char *fragment_lengths;  // length of fragments for each unichar in string
62   bool fragment_mark;      // if true, indicates that this choice
63                            // was chosen over a better one that
64                            // contained a fragment
65 } A_CHOICE;
66 
67 /*----------------------------------------------------------------------
68                 M a c r o s
69 ----------------------------------------------------------------------*/
70 /**********************************************************************
71  * best_string
72  *
73  * Return the string corresponding to the best choice.
74  **********************************************************************/
75 #define best_string(choices)  \
76 (first_node (choices) ? ((A_CHOICE*) (first_node (choices)))->string : NULL)
77 
78 /**********************************************************************
79  * best_lengths
80  *
81  * Return the lengths corresponding to the best choice.
82  **********************************************************************/
83 #define best_lengths(choices)  \
84 (first_node (choices) ? ((A_CHOICE*) (first_node (choices)))->lengths : NULL)
85 
86 /**********************************************************************
87  * best_rating
88  *
89  * Return the rating of the best choice.
90  **********************************************************************/
91 #define best_rating(choices)  \
92 (((A_CHOICE*) (first_node (choices)))->rating)
93 
94 /**********************************************************************
95  * best_certainty
96  *
97  * Return the certainty of the best choice.
98  **********************************************************************/
99 #define best_certainty(choices)  \
100 (((A_CHOICE*) (first_node (choices)))->certainty)
101 
102 /**********************************************************************
103  * class_rating
104  *
105  * Return the rating of a given character class.
106  **********************************************************************/
107 #define class_rating(choice)  \
108 (((A_CHOICE*) (choice))->rating)
109 
110 /**********************************************************************
111  * class_certainty
112  *
113  * Return the certainty of a given character class.
114  **********************************************************************/
115 #define class_certainty(choice)  \
116 (((A_CHOICE*) (choice))->certainty)
117 
118 /**********************************************************************
119  * class_string
120  *
121  * Return the string of a given character class.
122  **********************************************************************/
123 #define class_string(choice)  \
124 (((A_CHOICE*) (choice))->string)
125 
126 /**********************************************************************
127  * class_lengths
128  *
129  * Return the lengths of a given character class.
130  **********************************************************************/
131 #define class_lengths(choice)  \
132 (((A_CHOICE*) (choice))->lengths)
133 
134 /**********************************************************************
135  * class_permuter
136  *
137  * Return the permuter of a given character class.
138  **********************************************************************/
139 #define class_permuter(choice)  \
140 (((A_CHOICE*) (choice))->permuter)
141 
142 /**********************************************************************
143  * class_config
144  *
145  * Return the config of a given character class.
146  **********************************************************************/
147 #define class_config(choice)  \
148 (((A_CHOICE*) (choice))->config)
149 
150 /**********************************************************************
151  * class_script
152  *
153  * Return the script of a given character class.
154  **********************************************************************/
155 #define class_script_id(choice)  \
156 (((A_CHOICE*) (choice))->script_id)
157 
158 /**********************************************************************
159  * free_choices
160  *
161  * Free a list of choices.
162  **********************************************************************/
163 #define free_choices(c)  \
164 destroy_nodes ((c), free_choice)
165 
166 /**********************************************************************
167  * print_bold
168  *
169  * Print a string in bold type by using escape sequences.  This only
170  * works for certain output devices.
171  **********************************************************************/
172 #define print_bold(string)               \
173 cprintf ("\033&dB%s\033&d@", string)
174 
175 
176 /*----------------------------------------------------------------------
177               F u n c t i o n s
178 ----------------------------------------------------------------------*/
179 
180 // Returns true if fragment_mark is set for the given choice.
class_fragment_mark(A_CHOICE * choice)181 inline bool class_fragment_mark(A_CHOICE *choice) {
182   return choice->fragment_mark;
183 }
184 
185 // Sets fragment_mark of choice to the given value.
set_class_fragment_mark(A_CHOICE * choice,bool mark)186 inline void set_class_fragment_mark(A_CHOICE *choice, bool mark) {
187   choice->fragment_mark = mark;
188 }
189 
190 // Returns fragment_lengths of the given class.
class_fragment_lengths(A_CHOICE * choice)191 inline const char *class_fragment_lengths(A_CHOICE *choice) {
192   return choice->fragment_lengths;
193 }
194 
195 CHOICES append_char_choice(CHOICES ratings,
196                            const char *string,
197                            const char *lengths,
198                            float rating,
199                            float certainty,
200                            inT8 config,
201                            int script_id);
202 
203 CHOICES copy_choices(CHOICES choices);
204 
205 // Copy the given values into corresponding fields of choice.
206 void clone_choice(A_CHOICE *choice, const char *string,
207                   const char *lengths, float rating, float certainty,
208                   inT8 permuter, bool fragment_mark,
209                   const char *fragment_lengths);
210 
211 // Copy the contents of choice_1 into choice_2.
clone_choice(A_CHOICE * choice_2,A_CHOICE * choice_1)212 inline void clone_choice(A_CHOICE *choice_2, A_CHOICE *choice_1) {
213   clone_choice(choice_2, class_string(choice_1), class_lengths(choice_1),
214                class_rating(choice_1), class_certainty(choice_1),
215                class_permuter(choice_1), class_fragment_mark(choice_1),
216                class_fragment_lengths(choice_1));
217 }
218 
219 void clear_choice(A_CHOICE *choice);
220 
221 void free_choice(void *arg);
222 
223 A_CHOICE *get_best_free_other(A_CHOICE *choice_1, A_CHOICE *choice_2);
224 
225 A_CHOICE *new_choice(const char *string,
226                      const char *lengths,
227                      float rating,
228                      float certainty,
229                      inT8 config,
230                      int script_id,
231                      char permuter,
232                      bool fragment_mark,
233                      const char *fragment_lengths);
234 
235 A_CHOICE *new_choice(const char *string,
236                      const char *lengths,
237                      float rating,
238                      float certainty,
239                      inT8 config,
240                      char permuter);
241 
242 #endif
243