Skip to content

Commit

Permalink
Fixed the dawg crash (edge_char_of/letter_is_okay) issue 128 and dupl…
Browse files Browse the repository at this point in the history
…icates

git-svn-id: https://tesseract-ocr.googlecode.com/svn/trunk@205 d0cd1f9f-072b-0410-8dd7-cf729c803f20
  • Loading branch information
theraysmith committed Dec 24, 2008
1 parent cb3b9b4 commit 04c4620
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 21 deletions.
12 changes: 0 additions & 12 deletions dict/dawg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,6 @@ inT32 def_letter_is_okay(EDGE_ARRAY dawg,
edge = edge_char_of(dawg, *node,
static_cast<unsigned char>(dummy_word[char_index]),
word_end);
#if 0
// TODO(rays) Turn dawg to a class so this can be used properly.
// The maximum value of edge is unknown to this function, but could
// easily be stored in a dawg class.
if ((edge < 0 || edge >= 10000000) // MAX_NUM_EDGES_IN_SQUISHED_DAWG_FILE)
&& edge != NO_EDGE) {
tprintf("Impossible return from edge_char_of: node=" REFFORMAT
", ch=%d, edge=" REFFORMAT "\n",
*node, static_cast<unsigned char>(dummy_word[char_index]), edge);
edge = NO_EDGE;
}
#endif

if (edge != NO_EDGE) { /* Normal edge in DAWG */
if (case_sensative || case_is_okay (dummy_word, char_index)) {
Expand Down
13 changes: 10 additions & 3 deletions dict/permdawg.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,12 @@ void append_next_choice( /*previous option */
better_choice = new_choice (word, unichar_lengths, rating, certainty, -1, permuter);
adjust_word(better_choice, certainty_array);
push_on(*result, better_choice);
if (permuter == SYSTEM_DAWG_PERM) {
// Until dawg is a class, it is only safe to use set_hyphen_word
// on a single dawg type, as it saves permuter state to use on another
// word in hyphen_state, and this *must* apply to the same dawg.
set_hyphen_word(word, unichar_lengths, unichar_offsets, rating, node);
}
}
/* Look up char in DAWG */
else {
Expand Down Expand Up @@ -319,8 +324,7 @@ void dawg_permute_and_select(const char *string,
EDGE_ARRAY dawg,
char permuter,
CHOICES_LIST character_choices,
A_CHOICE *best_choice,
inT16 system_words) {
A_CHOICE *best_choice) {
CHOICES result = NIL;
char word[UNICHAR_LEN * MAX_WERD_LENGTH + 1];
char unichar_lengths[MAX_WERD_LENGTH + 1];
Expand Down Expand Up @@ -352,7 +356,10 @@ void dawg_permute_and_select(const char *string,
unichar_offsets[hyphen_base_size() - 1] +
unichar_lengths[hyphen_base_size() - 1];
char_index = strlen (hyphen_unichar_lengths);
if (system_words)
if (permuter == SYSTEM_DAWG_PERM)
// Until dawg is a class, it is only safe to use set_hyphen_word
// on a single dawg type, as it saves permuter state to use on another
// word in hyphen_state, and this *must* apply to the same dawg.
dawg_node = hyphen_state;
}

Expand Down
3 changes: 1 addition & 2 deletions dict/permdawg.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,7 @@ void dawg_permute_and_select(const char *string,
EDGE_ARRAY dawg,
char permuter,
CHOICES_LIST character_choices,
A_CHOICE *best_choice,
inT16 system_words);
A_CHOICE *best_choice);

void init_permdawg_vars();
void init_permdawg();
Expand Down
7 changes: 3 additions & 4 deletions dict/permute.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1670,14 +1670,13 @@ A_CHOICE *permute_words(CHOICES_LIST char_choices, float rating_limit) {
else {

dawg_permute_and_select ("system words:", word_dawg, SYSTEM_DAWG_PERM,
char_choices, best_choice, TRUE);
char_choices, best_choice);

dawg_permute_and_select ("document_words", document_words,
DOC_DAWG_PERM, char_choices, best_choice,
FALSE);
DOC_DAWG_PERM, char_choices, best_choice);

dawg_permute_and_select ("user words", user_words, USER_DAWG_PERM,
char_choices, best_choice, FALSE);
char_choices, best_choice);
}

return (best_choice);
Expand Down

0 comments on commit 04c4620

Please sign in to comment.