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