2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: ratngs.cpp (Formerly ratings.c)
|
|
|
|
* Description: Code to manipulate the BLOB_CHOICE and WERD_CHOICE classes.
|
|
|
|
* Author: Ray Smith
|
|
|
|
* Created: Thu Apr 23 13:23:29 BST 1992
|
|
|
|
*
|
|
|
|
* (C) Copyright 1992, Hewlett-Packard Ltd.
|
|
|
|
** 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 "mfcpch.h"
|
|
|
|
//#include "ipeerr.h"
|
|
|
|
#include "callcpp.h"
|
|
|
|
#include "ratngs.h"
|
|
|
|
//#include "tordvars.h"
|
|
|
|
extern FILE *matcher_fp;
|
|
|
|
|
|
|
|
ELISTIZE (BLOB_CHOICE) CLISTIZE (BLOB_CHOICE_LIST) CLISTIZE (WERD_CHOICE)
|
|
|
|
//extern FILE* matcher_fp;
|
|
|
|
/**********************************************************************
|
|
|
|
* BLOB_CHOICE::BLOB_CHOICE
|
|
|
|
*
|
|
|
|
* Constructor to build a BLOB_CHOICE from a char, rating and certainty.
|
|
|
|
**********************************************************************/
|
|
|
|
BLOB_CHOICE::BLOB_CHOICE( //constructor
|
2007-07-18 09:15:07 +08:00
|
|
|
char *src_unichar, //character
|
2007-03-08 04:03:40 +08:00
|
|
|
float src_rating, //rating
|
|
|
|
float src_cert, //certainty
|
|
|
|
INT8 src_config //config (font)
|
|
|
|
) {
|
2007-07-18 09:15:07 +08:00
|
|
|
strcpy(blob_unichar, src_unichar);
|
2007-03-08 04:03:40 +08:00
|
|
|
blob_rating = src_rating;
|
|
|
|
blob_certainty = src_cert; //just copy them
|
|
|
|
blob_config = src_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* WERD_CHOICE::WERD_CHOICE
|
|
|
|
*
|
|
|
|
* Constructor to build a WERD_CHOICE from a char, rating and certainty.
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
WERD_CHOICE::WERD_CHOICE (
|
|
|
|
//constructor
|
|
|
|
const char *src_string, //word string
|
2007-07-18 09:15:07 +08:00
|
|
|
const char *src_lengths, //unichar lengths
|
2007-03-08 04:03:40 +08:00
|
|
|
float src_rating, //rating
|
|
|
|
float src_cert, //certainty
|
|
|
|
UINT8 src_permuter //permuter code
|
|
|
|
):
|
2007-07-18 09:15:07 +08:00
|
|
|
word_string(src_string),
|
|
|
|
word_lengths(src_lengths) {
|
2007-03-08 04:03:40 +08:00
|
|
|
word_rating = src_rating;
|
|
|
|
word_certainty = src_cert;
|
|
|
|
word_permuter = src_permuter; //just copy them
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* WERD_CHOICE::operator+=
|
|
|
|
*
|
|
|
|
* Cat a second word rating on the end of this current one.
|
|
|
|
* The ratings are added and the confidence is the min.
|
|
|
|
* If the permuters are NOT the same the permuter is set to COMPOUND_PERM
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
//add one on
|
|
|
|
WERD_CHOICE & WERD_CHOICE::operator+= (
|
|
|
|
const WERD_CHOICE & second //second word
|
|
|
|
) {
|
|
|
|
if (word_string.length () == 0 || second.word_string.length () == 0) {
|
|
|
|
word_string = NULL; //make it empty
|
2007-07-18 09:15:07 +08:00
|
|
|
word_lengths = NULL;
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
else {
|
|
|
|
//add ratings
|
|
|
|
word_rating += second.word_rating;
|
|
|
|
if (second.word_certainty < word_certainty)
|
|
|
|
//take min
|
|
|
|
word_certainty = second.word_certainty;
|
|
|
|
//cat strings
|
|
|
|
word_string += second.word_string;
|
2007-07-18 09:15:07 +08:00
|
|
|
word_lengths += second.word_lengths;
|
2007-03-08 04:03:40 +08:00
|
|
|
if (second.word_permuter != word_permuter)
|
|
|
|
word_permuter = COMPOUND_PERM;
|
|
|
|
}
|
|
|
|
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* print_ratings_list
|
|
|
|
*
|
|
|
|
* Send all the ratings out to the logfile.
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
void print_ratings_list( //print whole list
|
|
|
|
const char *msg, //intro message
|
|
|
|
BLOB_CHOICE_LIST *ratings //list of results
|
|
|
|
) {
|
|
|
|
BLOB_CHOICE_IT
|
|
|
|
c_it = ratings; //iterator
|
|
|
|
|
|
|
|
switch (ratings->length ()) {
|
|
|
|
case 0:
|
|
|
|
tprintf ("%s:<none>", msg);
|
|
|
|
break;
|
|
|
|
case 1:
|
2007-07-18 09:15:07 +08:00
|
|
|
tprintf ("%s:%s/%g/%g", msg,
|
|
|
|
c_it.data ()->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data ()->rating (), c_it.data ()->certainty ());
|
|
|
|
break;
|
|
|
|
case 2:
|
2007-07-18 09:15:07 +08:00
|
|
|
tprintf ("%s:%s/%g/%g %s/%g/%g", msg,
|
|
|
|
c_it.data ()->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data ()->rating (),
|
|
|
|
c_it.data ()->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (1)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (1)->rating (),
|
|
|
|
c_it.data_relative (1)->certainty ());
|
|
|
|
break;
|
|
|
|
case 3:
|
2007-07-18 09:15:07 +08:00
|
|
|
tprintf ("%s:%s/%g/%g %s/%g/%g %s/%g/%g", msg,
|
|
|
|
c_it.data ()->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data ()->rating (),
|
|
|
|
c_it.data ()->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (1)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (1)->rating (),
|
|
|
|
c_it.data_relative (1)->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (2)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (2)->rating (),
|
|
|
|
c_it.data_relative (2)->certainty ());
|
|
|
|
break;
|
|
|
|
case 4:
|
2007-07-18 09:15:07 +08:00
|
|
|
tprintf ("%s:%s/%g/%g %s/%g/%g %s/%g/%g %s/%g/%g", msg,
|
|
|
|
c_it.data ()->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data ()->rating (),
|
|
|
|
c_it.data ()->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (1)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (1)->rating (),
|
|
|
|
c_it.data_relative (1)->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (2)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (2)->rating (),
|
|
|
|
c_it.data_relative (2)->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (3)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (3)->rating (),
|
|
|
|
c_it.data_relative (3)->certainty ());
|
|
|
|
break;
|
|
|
|
default:
|
2007-07-18 09:15:07 +08:00
|
|
|
tprintf ("%s:%s/%g/%g %s/%g/%g %s/%g/%g %s/%g/%g %s/%g/%g", msg,
|
|
|
|
c_it.data ()->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data ()->rating (),
|
|
|
|
c_it.data ()->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (1)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (1)->rating (),
|
|
|
|
c_it.data_relative (1)->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (2)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (2)->rating (),
|
|
|
|
c_it.data_relative (2)->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (3)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (3)->rating (),
|
|
|
|
c_it.data_relative (3)->certainty (),
|
2007-07-18 09:15:07 +08:00
|
|
|
c_it.data_relative (4)->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data_relative (4)->rating (),
|
|
|
|
c_it.data_relative (4)->certainty ());
|
|
|
|
c_it.forward ();
|
|
|
|
c_it.forward ();
|
|
|
|
c_it.forward ();
|
|
|
|
c_it.forward ();
|
|
|
|
while (!c_it.at_last ()) {
|
|
|
|
c_it.forward ();
|
2007-07-18 09:15:07 +08:00
|
|
|
tprintf ("%s/%g/%g",
|
|
|
|
c_it.data ()->unichar (),
|
2007-03-08 04:03:40 +08:00
|
|
|
c_it.data ()->rating (), c_it.data ()->certainty ());
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**********************************************************************
|
|
|
|
* print_ratings_info
|
|
|
|
*
|
|
|
|
* Send all the ratings out to the logfile.
|
|
|
|
**********************************************************************/
|
|
|
|
|
|
|
|
void print_ratings_info( //print summary info
|
|
|
|
FILE *fp, //file to use
|
|
|
|
BLOB_CHOICE_LIST *ratings //list of results
|
|
|
|
) {
|
|
|
|
INT32
|
|
|
|
index; //to list
|
|
|
|
INT32
|
|
|
|
best_index; //to list
|
|
|
|
FLOAT32
|
|
|
|
best_rat; //rating
|
|
|
|
FLOAT32
|
|
|
|
best_cert; //certainty
|
2007-07-18 09:15:07 +08:00
|
|
|
const char*
|
|
|
|
first_char = NULL; //character
|
2007-03-08 04:03:40 +08:00
|
|
|
FLOAT32
|
|
|
|
first_rat; //rating
|
|
|
|
FLOAT32
|
|
|
|
first_cert; //certainty
|
2007-07-18 09:15:07 +08:00
|
|
|
const char*
|
|
|
|
sec_char = NULL; //character
|
2007-03-08 04:03:40 +08:00
|
|
|
FLOAT32
|
|
|
|
sec_rat = 0.0f; //rating
|
|
|
|
FLOAT32
|
|
|
|
sec_cert = 0.0f; //certainty
|
|
|
|
BLOB_CHOICE_IT
|
|
|
|
c_it = ratings; //iterator
|
|
|
|
|
|
|
|
index = ratings->length ();
|
|
|
|
if (index > 0) {
|
2007-07-18 09:15:07 +08:00
|
|
|
first_char = c_it.data ()->unichar ();
|
2007-03-08 04:03:40 +08:00
|
|
|
first_rat = c_it.data ()->rating ();
|
|
|
|
first_cert = -c_it.data ()->certainty ();
|
|
|
|
if (index > 1) {
|
2007-07-18 09:15:07 +08:00
|
|
|
sec_char = c_it.data_relative (1)->unichar ();
|
2007-03-08 04:03:40 +08:00
|
|
|
sec_rat = c_it.data_relative (1)->rating ();
|
|
|
|
sec_cert = -c_it.data_relative (1)->certainty ();
|
|
|
|
}
|
|
|
|
else {
|
2007-07-18 09:15:07 +08:00
|
|
|
sec_char = NULL;
|
2007-03-08 04:03:40 +08:00
|
|
|
sec_rat = -1;
|
|
|
|
sec_cert = -1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else {
|
2007-07-18 09:15:07 +08:00
|
|
|
first_char = NULL;
|
2007-03-08 04:03:40 +08:00
|
|
|
first_rat = -1;
|
|
|
|
first_cert = -1;
|
|
|
|
}
|
|
|
|
best_index = -1;
|
|
|
|
best_rat = -1;
|
|
|
|
best_cert = -1;
|
|
|
|
for (index = 0, c_it.mark_cycle_pt (); !c_it.cycled_list ();
|
|
|
|
c_it.forward (), index++) {
|
2007-07-18 09:15:07 +08:00
|
|
|
if (strcmp(c_it.data ()->unichar (), blob_answer) == 0) {
|
2007-03-08 04:03:40 +08:00
|
|
|
best_index = index;
|
|
|
|
best_rat = c_it.data ()->rating ();
|
|
|
|
best_cert = -c_it.data ()->certainty ();
|
|
|
|
}
|
|
|
|
}
|
2007-07-18 09:15:07 +08:00
|
|
|
if (first_char != NULL && (*first_char == '\0' || *first_char == ' '))
|
|
|
|
first_char = NULL;
|
|
|
|
if (sec_char != NULL && (*sec_char == '\0' || *sec_char == ' '))
|
|
|
|
sec_char = NULL;
|
2007-03-08 04:03:40 +08:00
|
|
|
fprintf (matcher_fp,
|
2007-07-18 09:15:07 +08:00
|
|
|
" " INT32FORMAT " " INT32FORMAT " %g %g %s %g %g %s %g %g\n",
|
|
|
|
ratings->length (), best_index, best_rat, best_cert, first_char != NULL ? first_char : "~",
|
|
|
|
first_rat, first_cert, sec_char != NULL ? sec_char : "~", sec_rat, sec_cert);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|