mirror of
https://github.com/tesseract-ocr/tesseract.git
synced 2024-12-03 00:49:01 +08:00
570af48b8b
git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@87 d0cd1f9f-072b-0410-8dd7-cf729c803f20
168 lines
5.4 KiB
C++
168 lines
5.4 KiB
C++
/* -*-C-*-
|
|
********************************************************************************
|
|
*
|
|
* File: choices.c (Formerly choices.c)
|
|
* Description: Handle the new ratings choices for Wise Owl
|
|
* Author: Mark Seaman, OCR Technology
|
|
* Created: Fri Sep 22 14:05:51 1989
|
|
* Modified: Wed May 22 14:12:34 1991 (Mark Seaman) marks@hpgrlt
|
|
* Language: C
|
|
* Package: N/A
|
|
* Status: Experimental (Do Not Distribute)
|
|
*
|
|
* (c) Copyright 1989, Hewlett-Packard Company.
|
|
** Licensed under the Apache License, Version 2.0 (the "License");
|
|
** you may not use this file except in compliance with the License.
|
|
** You may obtain a copy of the License at
|
|
** http://www.apache.org/licenses/LICENSE-2.0
|
|
** Unless required by applicable law or agreed to in writing, software
|
|
** distributed under the License is distributed on an "AS IS" BASIS,
|
|
** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
** See the License for the specific language governing permissions and
|
|
** limitations under the License.
|
|
*
|
|
*********************************************************************************/
|
|
#include "choices.h"
|
|
#include "structures.h"
|
|
#include "tordvars.h"
|
|
#include "callcpp.h"
|
|
#include "danerror.h"
|
|
#include "host.h"
|
|
|
|
/*----------------------------------------------------------------------
|
|
Variables
|
|
------------------------------------------------------------------------*/
|
|
#define CHOICEBLOCK 100 /* Cells per block */
|
|
|
|
makestructure (newchoice, oldchoice, printchoice, A_CHOICE,
|
|
freechoice, CHOICEBLOCK, "A_CHOICE", choicecount)
|
|
/*----------------------------------------------------------------------
|
|
F u n c t i o n s
|
|
----------------------------------------------------------------------*/
|
|
/**********************************************************************
|
|
* append_choice
|
|
*
|
|
* Create a new choice record. Store the string value in a safe place.
|
|
* Add the new choice record to the list.
|
|
*
|
|
* NB - This is only used by matchers, so permuter is always NO_PERM
|
|
* SPC 16/9/92
|
|
**********************************************************************/
|
|
CHOICES append_choice(CHOICES ratings,
|
|
const char *string,
|
|
const char *lengths,
|
|
float rating,
|
|
float certainty,
|
|
INT8 config) {
|
|
A_CHOICE *this_choice;
|
|
|
|
this_choice = new_choice (string, lengths, rating, certainty, config, NO_PERM);
|
|
ratings = push_last (ratings, (LIST) this_choice);
|
|
return (ratings);
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
* copy_choices
|
|
*
|
|
* Copy a list of choices. This means that there will be two copies
|
|
* in memory.
|
|
**********************************************************************/
|
|
CHOICES copy_choices(CHOICES choices) {
|
|
CHOICES l;
|
|
CHOICES result = NIL;
|
|
|
|
iterate_list(l, choices) {
|
|
result = push (result,
|
|
(LIST) new_choice (class_string (first_node (l)),
|
|
class_lengths (first_node (l)),
|
|
class_probability (first_node (l)),
|
|
class_certainty (first_node (l)),
|
|
class_config (first_node (l)),
|
|
class_permuter (first_node (l))));
|
|
}
|
|
return (reverse_d (result));
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
* free_choice
|
|
*
|
|
* Free up the memory taken by one choice rating.
|
|
**********************************************************************/
|
|
void free_choice(void *arg) { //LIST choice)
|
|
A_CHOICE *this_choice;
|
|
LIST choice = (LIST) arg;
|
|
|
|
this_choice = (A_CHOICE *) choice;
|
|
if (this_choice) {
|
|
if (this_choice->string)
|
|
strfree (this_choice->string);
|
|
if (this_choice->lengths)
|
|
strfree (this_choice->lengths);
|
|
oldchoice(this_choice);
|
|
}
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
* new_choice
|
|
*
|
|
* Create a new choice record. Store the string value in a safe place.
|
|
**********************************************************************/
|
|
A_CHOICE *new_choice(const char *string,
|
|
const char *lengths,
|
|
float rating,
|
|
float certainty,
|
|
INT8 config,
|
|
char permuter) {
|
|
A_CHOICE *this_choice;
|
|
|
|
this_choice = newchoice ();
|
|
this_choice->string = strsave (string);
|
|
this_choice->lengths = strsave (lengths);
|
|
this_choice->rating = rating;
|
|
this_choice->certainty = certainty;
|
|
this_choice->config = config;
|
|
this_choice->permuter = permuter;
|
|
return (this_choice);
|
|
}
|
|
|
|
|
|
/**********************************************************************
|
|
* print_choices
|
|
*
|
|
* Print the probability ratings for a particular blob or word.
|
|
**********************************************************************/
|
|
void print_choices( /* List of (A_CHOICE*) */
|
|
const char *label,
|
|
CHOICES rating) {
|
|
int first_one = TRUE;
|
|
char str[CHARS_PER_LINE];
|
|
int len;
|
|
|
|
cprintf ("%-20s\n", label);
|
|
if (rating == NIL)
|
|
cprintf (" No rating ");
|
|
|
|
iterate(rating) {
|
|
|
|
if (first_one && show_bold) {
|
|
cprintf ("|");
|
|
len = sprintf (str, " %s ", best_string (rating));
|
|
print_bold(str);
|
|
while (len++ < 8)
|
|
cprintf (" ");
|
|
}
|
|
else {
|
|
cprintf ("| %-7s", best_string (rating));
|
|
}
|
|
|
|
cprintf ("%5.2lf ", best_probability (rating));
|
|
|
|
cprintf ("%5.2lf", best_certainty (rating));
|
|
first_one = FALSE;
|
|
}
|
|
cprintf ("\n");
|
|
}
|