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 INT_VAR(hyphen_debug_level, 0, "Debug level for hyphenated words.");
28
29 namespace tesseract {
30
31 // Unless the previous word was the last one on the line, and the current
32 // one is not (thus it is the first one on the line), erase hyphen_word_,
33 // clear hyphen_active_dawgs_, hyphen_constraints_ update last_word_on_line_.
reset_hyphen_vars(bool last_word_on_line)34 void Dict::reset_hyphen_vars(bool last_word_on_line) {
35 if (!(last_word_on_line_ == true && last_word_on_line == false)) {
36 if (hyphen_word_ != NULL) {
37 delete hyphen_word_;
38 hyphen_word_ = NULL;
39 hyphen_active_dawgs_.clear();
40 hyphen_constraints_.clear();
41 }
42 }
43 if (hyphen_debug_level) {
44 tprintf("reset_hyphen_vars: last_word_on_line %d -> %d\n",
45 last_word_on_line_, last_word_on_line);
46 }
47 last_word_on_line_ = last_word_on_line;
48 }
49
50 // Update hyphen_word_, and copy the given DawgInfoVectors into
51 // hyphen_active_dawgs_ and hyphen_constraints_.
set_hyphen_word(const WERD_CHOICE & word,const DawgInfoVector & active_dawgs,const DawgInfoVector & constraints)52 void Dict::set_hyphen_word(const WERD_CHOICE &word,
53 const DawgInfoVector &active_dawgs,
54 const DawgInfoVector &constraints) {
55 if (hyphen_word_ == NULL) {
56 hyphen_word_ = new WERD_CHOICE();
57 hyphen_word_->make_bad();
58 }
59 if (hyphen_word_->rating() > word.rating()) {
60 *hyphen_word_ = word;
61 hyphen_word_->remove_last_unichar_id(); // last unichar id is a hyphen
62 hyphen_active_dawgs_ = active_dawgs;
63 hyphen_constraints_ = constraints;
64 }
65 if (hyphen_debug_level) {
66 hyphen_word_->print("set_hyphen_word: ");
67 }
68 }
69 } // namespace tesseract
70