tesseract v5.3.3.20231005
hyphen.cpp
Go to the documentation of this file.
1/******************************************************************************
2 * File: hyphen.cpp (Formerly hyphen.c)
3 * Description: Functions for maintaining information about hyphenated words.
4 * Author: Mark Seaman, OCR Technology
5 * Status: Reusable Software Component
6 *
7 * (c) Copyright 1987, Hewlett-Packard Company.
8 ** Licensed under the Apache License, Version 2.0 (the "License");
9 ** you may not use this file except in compliance with the License.
10 ** You may obtain a copy of the License at
11 ** http://www.apache.org/licenses/LICENSE-2.0
12 ** Unless required by applicable law or agreed to in writing, software
13 ** distributed under the License is distributed on an "AS IS" BASIS,
14 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 ** See the License for the specific language governing permissions and
16 ** limitations under the License.
17 *
18 *****************************************************************************/
19
20#include "dict.h"
21
22namespace tesseract {
23
24// Unless the previous word was the last one on the line, and the current
25// one is not (thus it is the first one on the line), erase hyphen_word_,
26// clear hyphen_active_dawgs_, hyphen_constraints_ update last_word_on_line_.
27void Dict::reset_hyphen_vars(bool last_word_on_line) {
28 if (!(last_word_on_line_ == true && last_word_on_line == false)) {
29 if (hyphen_word_ != nullptr) {
30 delete hyphen_word_;
31 hyphen_word_ = nullptr;
32 hyphen_active_dawgs_.clear();
33 }
34 }
35 if (hyphen_debug_level) {
36 tprintf("reset_hyphen_vars: last_word_on_line %d -> %d\n", last_word_on_line_,
37 last_word_on_line);
38 }
39 last_word_on_line_ = last_word_on_line;
40}
41
42// Update hyphen_word_, and copy the given DawgPositionVectors into
43// hyphen_active_dawgs_.
44void Dict::set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs) {
45 if (hyphen_word_ == nullptr) {
46 hyphen_word_ = new WERD_CHOICE(word.unicharset());
47 hyphen_word_->make_bad();
48 }
49 if (hyphen_word_->rating() > word.rating()) {
50 *hyphen_word_ = word;
51 // Remove the last unichar id as it is a hyphen, and remove
52 // any unichar_string/lengths that are present.
53 hyphen_word_->remove_last_unichar_id();
54 hyphen_active_dawgs_ = active_dawgs;
55 }
56 if (hyphen_debug_level) {
57 hyphen_word_->print("set_hyphen_word: ");
58 }
59}
60} // namespace tesseract
void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void make_bad()
Set the fields in this choice to be default (bad) values.
Definition: ratngs.h:419
const UNICHARSET * unicharset() const
Definition: ratngs.h:281
void remove_last_unichar_id()
Definition: ratngs.h:455
void print() const
Definition: ratngs.h:561
float rating() const
Definition: ratngs.h:312
void reset_hyphen_vars(bool last_word_on_line)
Definition: hyphen.cpp:27
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
Definition: hyphen.cpp:44