2007-03-08 04:03:40 +08:00
|
|
|
/**********************************************************************
|
|
|
|
* File: tessbox.cpp (Formerly tessbox.c)
|
|
|
|
* Description: Black boxed Tess for developing a resaljet.
|
|
|
|
* Author: Ray Smith
|
|
|
|
* Created: Thu Apr 23 11:03:36 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.
|
|
|
|
*
|
|
|
|
**********************************************************************/
|
|
|
|
|
2010-05-26 18:22:27 +08:00
|
|
|
#ifdef _MSC_VER
|
|
|
|
#pragma warning(disable:4244) // Conversion warnings
|
|
|
|
#endif
|
|
|
|
|
2007-03-08 04:03:40 +08:00
|
|
|
#include "mfoutline.h"
|
2013-09-23 23:26:50 +08:00
|
|
|
#include "tessbox.h"
|
2009-07-11 10:03:51 +08:00
|
|
|
#include "tesseractclass.h"
|
2007-03-08 04:03:40 +08:00
|
|
|
|
|
|
|
#define EXTERN
|
|
|
|
|
2010-07-28 08:38:09 +08:00
|
|
|
/**
|
2013-09-23 23:26:50 +08:00
|
|
|
* @name tess_segment_pass_n
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
2013-09-23 23:26:50 +08:00
|
|
|
* Segment a word using the pass_n conditions of the tess segmenter.
|
|
|
|
* @param pass_n pass number
|
2010-11-24 02:34:14 +08:00
|
|
|
* @param word word to do
|
2010-07-28 08:38:09 +08:00
|
|
|
*/
|
2007-03-08 04:03:40 +08:00
|
|
|
|
2009-07-11 10:03:51 +08:00
|
|
|
namespace tesseract {
|
2013-09-23 23:26:50 +08:00
|
|
|
void Tesseract::tess_segment_pass_n(int pass_n, WERD_RES *word) {
|
2007-03-08 04:03:40 +08:00
|
|
|
int saved_enable_assoc = 0;
|
|
|
|
int saved_chop_enable = 0;
|
|
|
|
|
2010-11-24 02:34:14 +08:00
|
|
|
if (word->word->flag(W_DONT_CHOP)) {
|
2009-07-11 10:03:51 +08:00
|
|
|
saved_enable_assoc = wordrec_enable_assoc;
|
2007-03-08 04:03:40 +08:00
|
|
|
saved_chop_enable = chop_enable;
|
2009-07-11 10:03:51 +08:00
|
|
|
wordrec_enable_assoc.set_value(0);
|
|
|
|
chop_enable.set_value(0);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2013-09-23 23:26:50 +08:00
|
|
|
if (pass_n == 1)
|
|
|
|
set_pass1();
|
|
|
|
else
|
|
|
|
set_pass2();
|
|
|
|
recog_word(word);
|
2016-12-13 00:19:35 +08:00
|
|
|
if (word->best_choice == nullptr)
|
2013-09-23 23:26:50 +08:00
|
|
|
word->SetupFake(*word->uch_set);
|
2010-11-24 02:34:14 +08:00
|
|
|
if (word->word->flag(W_DONT_CHOP)) {
|
2009-07-11 10:03:51 +08:00
|
|
|
wordrec_enable_assoc.set_value(saved_enable_assoc);
|
|
|
|
chop_enable.set_value(saved_chop_enable);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-07-28 08:38:09 +08:00
|
|
|
/**
|
2010-08-13 02:55:59 +08:00
|
|
|
* @name tess_acceptable_word
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
2010-08-13 02:55:59 +08:00
|
|
|
* @return true if the word is regarded as "good enough".
|
|
|
|
* @param word_choice after context
|
|
|
|
* @param raw_choice before context
|
2010-07-28 08:38:09 +08:00
|
|
|
*/
|
2013-09-23 23:26:50 +08:00
|
|
|
bool Tesseract::tess_acceptable_word(WERD_RES* word) {
|
|
|
|
return getDict().AcceptableResult(word);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-07-28 08:38:09 +08:00
|
|
|
/**
|
2010-08-13 02:55:59 +08:00
|
|
|
* @name tess_add_doc_word
|
2007-03-08 04:03:40 +08:00
|
|
|
*
|
|
|
|
* Add the given word to the document dictionary
|
2010-07-28 08:38:09 +08:00
|
|
|
*/
|
2009-07-11 10:03:51 +08:00
|
|
|
void Tesseract::tess_add_doc_word(WERD_CHOICE *word_choice) {
|
|
|
|
getDict().add_document_word(*word_choice);
|
2007-03-08 04:03:40 +08:00
|
|
|
}
|
2009-07-11 10:03:51 +08:00
|
|
|
} // namespace tesseract
|