2
********************************************************************************
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
11
* Status: Experimental (Do Not Distribute)
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.
24
********************************************************************************
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.
34
*********************************************************************************/
43
#include "unicharset.h"
45
/*----------------------------------------------------------------------
47
----------------------------------------------------------------------*/
48
typedef LIST CHOICES; /* CHOICES */
49
//typedef float PROBABILITY; /* PROBABILITY */
50
//typedef char PERM_TYPE; /* PERMUTER CODE */
52
typedef struct choicestruct
59
char *lengths; // length of each unichar in the string
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
67
/*----------------------------------------------------------------------
69
----------------------------------------------------------------------*/
70
/**********************************************************************
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)
78
/**********************************************************************
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)
86
/**********************************************************************
89
* Return the rating of the best choice.
90
**********************************************************************/
91
#define best_rating(choices) \
92
(((A_CHOICE*) (first_node (choices)))->rating)
94
/**********************************************************************
97
* Return the certainty of the best choice.
98
**********************************************************************/
99
#define best_certainty(choices) \
100
(((A_CHOICE*) (first_node (choices)))->certainty)
102
/**********************************************************************
105
* Return the rating of a given character class.
106
**********************************************************************/
107
#define class_rating(choice) \
108
(((A_CHOICE*) (choice))->rating)
110
/**********************************************************************
113
* Return the certainty of a given character class.
114
**********************************************************************/
115
#define class_certainty(choice) \
116
(((A_CHOICE*) (choice))->certainty)
118
/**********************************************************************
121
* Return the string of a given character class.
122
**********************************************************************/
123
#define class_string(choice) \
124
(((A_CHOICE*) (choice))->string)
126
/**********************************************************************
129
* Return the lengths of a given character class.
130
**********************************************************************/
131
#define class_lengths(choice) \
132
(((A_CHOICE*) (choice))->lengths)
134
/**********************************************************************
137
* Return the permuter of a given character class.
138
**********************************************************************/
139
#define class_permuter(choice) \
140
(((A_CHOICE*) (choice))->permuter)
142
/**********************************************************************
145
* Return the config of a given character class.
146
**********************************************************************/
147
#define class_config(choice) \
148
(((A_CHOICE*) (choice))->config)
150
/**********************************************************************
153
* Return the script of a given character class.
154
**********************************************************************/
155
#define class_script_id(choice) \
156
(((A_CHOICE*) (choice))->script_id)
158
/**********************************************************************
161
* Free a list of choices.
162
**********************************************************************/
163
#define free_choices(c) \
164
destroy_nodes ((c), free_choice)
166
/**********************************************************************
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)
176
/*----------------------------------------------------------------------
178
----------------------------------------------------------------------*/
180
// Returns true if fragment_mark is set for the given choice.
181
inline bool class_fragment_mark(A_CHOICE *choice) {
182
return choice->fragment_mark;
185
// Sets fragment_mark of choice to the given value.
186
inline void set_class_fragment_mark(A_CHOICE *choice, bool mark) {
187
choice->fragment_mark = mark;
190
// Returns fragment_lengths of the given class.
191
inline const char *class_fragment_lengths(A_CHOICE *choice) {
192
return choice->fragment_lengths;
195
CHOICES append_char_choice(CHOICES ratings,
203
CHOICES copy_choices(CHOICES choices);
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);
211
// Copy the contents of choice_1 into choice_2.
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));
219
void clear_choice(A_CHOICE *choice);
221
void free_choice(void *arg);
223
A_CHOICE *get_best_free_other(A_CHOICE *choice_1, A_CHOICE *choice_2);
225
A_CHOICE *new_choice(const char *string,
233
const char *fragment_lengths);
235
A_CHOICE *new_choice(const char *string,