00001 /* -*-C-*- 00002 ******************************************************************************** 00003 * 00004 * File: choices.h (Formerly choices.h) 00005 * Description: Handle the new ratings choices for Wise Owl 00006 * Author: Mark Seaman, OCR Technology 00007 * Created: Fri Sep 22 14:05:51 1989 00008 * Modified: Fri Jan 4 12:04:01 1991 (Mark Seaman) marks@hpgrlt 00009 * Language: C 00010 * Package: N/A 00011 * Status: Experimental (Do Not Distribute) 00012 * 00013 * (c) Copyright 1989, Hewlett-Packard Company. 00014 ** Licensed under the Apache License, Version 2.0 (the "License"); 00015 ** you may not use this file except in compliance with the License. 00016 ** You may obtain a copy of the License at 00017 ** http://www.apache.org/licenses/LICENSE-2.0 00018 ** Unless required by applicable law or agreed to in writing, software 00019 ** distributed under the License is distributed on an "AS IS" BASIS, 00020 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00021 ** See the License for the specific language governing permissions and 00022 ** limitations under the License. 00023 * 00024 ******************************************************************************** 00025 * 00026 * FUNCTIONS TO CALL 00027 * ----------------- 00028 * append_char_choice - Create a new choice for a character and add it to the list. 00029 * class_rating - Return the rating of a given character class. 00030 * class_string - Return the string corresponding to a character choice. 00031 * free_choice - Free up the memory taken by one choice rating. 00032 * new_choice - Create one choice record one set up the fields. 00033 * 00034 *********************************************************************************/ 00035 00036 #ifndef CHOICES_H 00037 #define CHOICES_H 00038 00039 #include <stdio.h> 00040 #include <string.h> 00041 00042 #include "oldlist.h" 00043 #include "unicharset.h" 00044 00045 /*---------------------------------------------------------------------- 00046 T y p e s 00047 ----------------------------------------------------------------------*/ 00048 typedef LIST CHOICES; /* CHOICES */ 00049 //typedef float PROBABILITY; /* PROBABILITY */ 00050 //typedef char PERM_TYPE; /* PERMUTER CODE */ 00051 00052 typedef struct choicestruct 00053 { /* A_CHOICE */ 00054 float rating; 00055 float certainty; 00056 char permuter; 00057 inT8 config; 00058 char *string; 00059 char *lengths; // length of each unichar in the string 00060 int script_id; 00061 char *fragment_lengths; // length of fragments for each unichar in string 00062 bool fragment_mark; // if true, indicates that this choice 00063 // was chosen over a better one that 00064 // contained a fragment 00065 } A_CHOICE; 00066 00067 /*---------------------------------------------------------------------- 00068 M a c r o s 00069 ----------------------------------------------------------------------*/ 00070 /********************************************************************** 00071 * best_string 00072 * 00073 * Return the string corresponding to the best choice. 00074 **********************************************************************/ 00075 #define best_string(choices) \ 00076 (first_node (choices) ? ((A_CHOICE*) (first_node (choices)))->string : NULL) 00077 00078 /********************************************************************** 00079 * best_lengths 00080 * 00081 * Return the lengths corresponding to the best choice. 00082 **********************************************************************/ 00083 #define best_lengths(choices) \ 00084 (first_node (choices) ? ((A_CHOICE*) (first_node (choices)))->lengths : NULL) 00085 00086 /********************************************************************** 00087 * best_rating 00088 * 00089 * Return the rating of the best choice. 00090 **********************************************************************/ 00091 #define best_rating(choices) \ 00092 (((A_CHOICE*) (first_node (choices)))->rating) 00093 00094 /********************************************************************** 00095 * best_certainty 00096 * 00097 * Return the certainty of the best choice. 00098 **********************************************************************/ 00099 #define best_certainty(choices) \ 00100 (((A_CHOICE*) (first_node (choices)))->certainty) 00101 00102 /********************************************************************** 00103 * class_rating 00104 * 00105 * Return the rating of a given character class. 00106 **********************************************************************/ 00107 #define class_rating(choice) \ 00108 (((A_CHOICE*) (choice))->rating) 00109 00110 /********************************************************************** 00111 * class_certainty 00112 * 00113 * Return the certainty of a given character class. 00114 **********************************************************************/ 00115 #define class_certainty(choice) \ 00116 (((A_CHOICE*) (choice))->certainty) 00117 00118 /********************************************************************** 00119 * class_string 00120 * 00121 * Return the string of a given character class. 00122 **********************************************************************/ 00123 #define class_string(choice) \ 00124 (((A_CHOICE*) (choice))->string) 00125 00126 /********************************************************************** 00127 * class_lengths 00128 * 00129 * Return the lengths of a given character class. 00130 **********************************************************************/ 00131 #define class_lengths(choice) \ 00132 (((A_CHOICE*) (choice))->lengths) 00133 00134 /********************************************************************** 00135 * class_permuter 00136 * 00137 * Return the permuter of a given character class. 00138 **********************************************************************/ 00139 #define class_permuter(choice) \ 00140 (((A_CHOICE*) (choice))->permuter) 00141 00142 /********************************************************************** 00143 * class_config 00144 * 00145 * Return the config of a given character class. 00146 **********************************************************************/ 00147 #define class_config(choice) \ 00148 (((A_CHOICE*) (choice))->config) 00149 00150 /********************************************************************** 00151 * class_script 00152 * 00153 * Return the script of a given character class. 00154 **********************************************************************/ 00155 #define class_script_id(choice) \ 00156 (((A_CHOICE*) (choice))->script_id) 00157 00158 /********************************************************************** 00159 * free_choices 00160 * 00161 * Free a list of choices. 00162 **********************************************************************/ 00163 #define free_choices(c) \ 00164 destroy_nodes ((c), free_choice) 00165 00166 /********************************************************************** 00167 * print_bold 00168 * 00169 * Print a string in bold type by using escape sequences. This only 00170 * works for certain output devices. 00171 **********************************************************************/ 00172 #define print_bold(string) \ 00173 cprintf ("\033&dB%s\033&d@", string) 00174 00175 00176 /*---------------------------------------------------------------------- 00177 F u n c t i o n s 00178 ----------------------------------------------------------------------*/ 00179 00180 // Returns true if fragment_mark is set for the given choice. 00181 inline bool class_fragment_mark(A_CHOICE *choice) { 00182 return choice->fragment_mark; 00183 } 00184 00185 // Sets fragment_mark of choice to the given value. 00186 inline void set_class_fragment_mark(A_CHOICE *choice, bool mark) { 00187 choice->fragment_mark = mark; 00188 } 00189 00190 // Returns fragment_lengths of the given class. 00191 inline const char *class_fragment_lengths(A_CHOICE *choice) { 00192 return choice->fragment_lengths; 00193 } 00194 00195 CHOICES append_char_choice(CHOICES ratings, 00196 const char *string, 00197 const char *lengths, 00198 float rating, 00199 float certainty, 00200 inT8 config, 00201 int script_id); 00202 00203 CHOICES copy_choices(CHOICES choices); 00204 00205 // Copy the given values into corresponding fields of choice. 00206 void clone_choice(A_CHOICE *choice, const char *string, 00207 const char *lengths, float rating, float certainty, 00208 inT8 permuter, bool fragment_mark, 00209 const char *fragment_lengths); 00210 00211 // Copy the contents of choice_1 into choice_2. 00212 inline void clone_choice(A_CHOICE *choice_2, A_CHOICE *choice_1) { 00213 clone_choice(choice_2, class_string(choice_1), class_lengths(choice_1), 00214 class_rating(choice_1), class_certainty(choice_1), 00215 class_permuter(choice_1), class_fragment_mark(choice_1), 00216 class_fragment_lengths(choice_1)); 00217 } 00218 00219 void clear_choice(A_CHOICE *choice); 00220 00221 void free_choice(void *arg); 00222 00223 A_CHOICE *get_best_free_other(A_CHOICE *choice_1, A_CHOICE *choice_2); 00224 00225 A_CHOICE *new_choice(const char *string, 00226 const char *lengths, 00227 float rating, 00228 float certainty, 00229 inT8 config, 00230 int script_id, 00231 char permuter, 00232 bool fragment_mark, 00233 const char *fragment_lengths); 00234 00235 A_CHOICE *new_choice(const char *string, 00236 const char *lengths, 00237 float rating, 00238 float certainty, 00239 inT8 config, 00240 char permuter); 00241 00242 #endif