tesseract
5.0.0-alpha-619-ge9db
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
22
namespace
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_.
27
void
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"
,
37
last_word_on_line_, 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_.
44
void
Dict::set_hyphen_word
(
const
WERD_CHOICE
&word,
45
const
DawgPositionVector
&active_dawgs) {
46
if
(hyphen_word_ ==
nullptr
) {
47
hyphen_word_ =
new
WERD_CHOICE
(word.
unicharset
());
48
hyphen_word_->
make_bad
();
49
}
50
if
(hyphen_word_->
rating
() > word.
rating
()) {
51
*hyphen_word_ = word;
52
// Remove the last unichar id as it is a hyphen, and remove
53
// any unichar_string/lengths that are present.
54
hyphen_word_->
remove_last_unichar_id
();
55
hyphen_active_dawgs_ = active_dawgs;
56
}
57
if
(
hyphen_debug_level
) {
58
hyphen_word_->
print
(
"set_hyphen_word: "
);
59
}
60
}
61
}
// namespace tesseract
tesseract::DawgPositionVector::clear
void clear()
Definition:
dawg.h:377
dict.h
WERD_CHOICE
Definition:
ratngs.h:261
WERD_CHOICE::make_bad
void make_bad()
Set the fields in this choice to be default (bad) values.
Definition:
ratngs.h:431
WERD_CHOICE::unicharset
const UNICHARSET * unicharset() const
Definition:
ratngs.h:288
tesseract::Dict::set_hyphen_word
void set_hyphen_word(const WERD_CHOICE &word, const DawgPositionVector &active_dawgs)
Definition:
hyphen.cpp:59
tesseract
Definition:
baseapi.h:65
tesseract::DawgPositionVector
Definition:
dawg.h:373
WERD_CHOICE::remove_last_unichar_id
void remove_last_unichar_id()
Definition:
ratngs.h:471
WERD_CHOICE::print
void print() const
Definition:
ratngs.h:568
tesseract::Dict::reset_hyphen_vars
void reset_hyphen_vars(bool last_word_on_line)
Definition:
hyphen.cpp:42
tprintf
DLLSYM void tprintf(const char *format,...)
Definition:
tprintf.cpp:34
WERD_CHOICE::rating
float rating() const
Definition:
ratngs.h:315
tesseract::Dict::hyphen_debug_level
int hyphen_debug_level
Definition:
dict.h:623
src
dict
hyphen.cpp
Generated on Thu Jan 30 2020 14:22:20 for tesseract by
1.8.16