void loop (int *queue, int *queue_length, int depth, int *list, int *nmr, int begin, int end, struct pcp_vars *pcp) { int i, k; char *s; for (i = begin; i <= end; ++i) { ++*nmr; list[*nmr] = i; if (*nmr == depth) { if (valid_word (list, depth)) { s = (depth == 1) ? " is" : "s are"; printf ("The component%s ", s); /* one has a complete list of entries to generate a normal word */ for (k = *nmr; k >= 1; --k) printf ("%d ", list[k]); printf ("\n"); evaluate_list (queue, queue_length, list, depth, pcp); } --*nmr; } else { loop (queue, queue_length, depth, list, nmr, first[depth - *nmr], last[depth - *nmr], pcp); } } --*nmr; }
bool Dict::AcceptableResult(const WERD_CHOICE &BestChoice) { float CertaintyThreshold = stopper_nondict_certainty_base - reject_offset_; int WordSize; if (stopper_debug_level >= 1) { tprintf("\nRejecter: %s (word=%c, case=%c, unambig=%c)\n", BestChoice.debug_string(getUnicharset()).string(), (valid_word(BestChoice) ? 'y' : 'n'), (case_ok(BestChoice, getUnicharset()) ? 'y' : 'n'), ((list_rest (best_choices_) != NIL_LIST) ? 'n' : 'y')); } if (BestChoice.length() == 0 || CurrentWordAmbig()) return false; if (BestChoice.fragment_mark()) { if (stopper_debug_level >= 1) { cprintf("AcceptableResult(): a choice with fragments beats BestChoice\n"); } return false; } if (valid_word(BestChoice) && case_ok(BestChoice, getUnicharset())) { WordSize = LengthOfShortestAlphaRun(BestChoice); WordSize -= stopper_smallword_size; if (WordSize < 0) WordSize = 0; CertaintyThreshold += WordSize * stopper_certainty_per_char; } if (stopper_debug_level >= 1) cprintf ("Rejecter: Certainty = %4.1f, Threshold = %4.1f ", BestChoice.certainty(), CertaintyThreshold); if (BestChoice.certainty() > CertaintyThreshold && !stopper_no_acceptable_choices) { if (stopper_debug_level >= 1) cprintf("ACCEPTED\n"); return true; } else { if (stopper_debug_level >= 1) cprintf("REJECTED\n"); return false; } }
bool Dict::AcceptableResult(WERD_RES *word) const { if (word->best_choice == nullptr) return false; float CertaintyThreshold = stopper_nondict_certainty_base - reject_offset_; int WordSize; if (stopper_debug_level >= 1) { tprintf("\nRejecter: %s (word=%c, case=%c, unambig=%c, multiple=%c)\n", word->best_choice->debug_string().string(), (valid_word(*word->best_choice) ? 'y' : 'n'), (case_ok(*word->best_choice, getUnicharset()) ? 'y' : 'n'), word->best_choice->dangerous_ambig_found() ? 'n' : 'y', word->best_choices.singleton() ? 'n' : 'y'); } if (word->best_choice->length() == 0 || !word->best_choices.singleton()) return false; if (valid_word(*word->best_choice) && case_ok(*word->best_choice, getUnicharset())) { WordSize = LengthOfShortestAlphaRun(*word->best_choice); WordSize -= stopper_smallword_size; if (WordSize < 0) WordSize = 0; CertaintyThreshold += WordSize * stopper_certainty_per_char; } if (stopper_debug_level >= 1) tprintf("Rejecter: Certainty = %4.1f, Threshold = %4.1f ", word->best_choice->certainty(), CertaintyThreshold); if (word->best_choice->certainty() > CertaintyThreshold && !stopper_no_acceptable_choices) { if (stopper_debug_level >= 1) tprintf("ACCEPTED\n"); return true; } else { if (stopper_debug_level >= 1) tprintf("REJECTED\n"); return false; } }
// Check whether a word is valid according to Tesseract's language model // returns 0 if the string is invalid, non-zero if valid int TessBaseAPI::IsValidWord(const char *string) { return valid_word(string); }
static int read_config_file () { FILE * config; char * line; int returnValue = -1; line = ber_memcalloc(260, sizeof(char)); if ( line == NULL ) { return returnValue; } if ( (config = fopen(CONFIG_FILE, "r")) == NULL) { #if defined(DEBUG) syslog(LOG_ERR, "check_password: Opening file %s failed", CONFIG_FILE); #endif #if defined(LDEBUG) printf("check_password: Opening file %s failed\n", CONFIG_FILE); #endif ber_memfree(line); return returnValue; } returnValue = 0; while (fgets(line, 256, config) != NULL) { char *start = line; char *word, *value; validator dealer; #if defined(DEBUG) /* Debug traces to syslog. */ syslog(LOG_NOTICE, "check_password: Got line |%s|", line); #endif #if defined(LDEBUG) /* Debug traces. */ char* msg = chomp(line); printf("check_password: Got line |%s|\n", msg); ber_memfree(msg); #endif while (isspace(*start) && isascii(*start)) start++; /* If we've got punctuation, just skip the line. */ if ( ispunct(*start)) { #if defined(DEBUG) /* Debug traces to syslog. */ syslog(LOG_NOTICE, "check_password: Skipped line |%s|", line); #endif #if defined(LDEBUG) /* Debug traces. */ char* msg = chomp(line); printf("check_password: Skipped line |%s|\n", msg); ber_memfree(msg); #endif continue; } if( isascii(*start)) { struct config_entry* centry = config_entries; int i = 0; char* keyWord = centry[i].key; if ((word = strtok(start, " \t")) && (value = strtok(NULL, " \t"))) { while ( keyWord != NULL ) { if ((strncmp(keyWord,word,strlen(keyWord)) == 0) && (dealer = valid_word(word)) ) { #if defined(DEBUG) syslog(LOG_NOTICE, "check_password: Word = %s, value = %s", word, value); #endif #if defined(LDEBUG) printf("check_password: Word = %s, value = %s\n", word, value); #endif centry[i].value = chomp(value); break; } i++; keyWord = centry[i].key; } } } } fclose(config); ber_memfree(line); return returnValue; }
/* play one letters round */ void letters_round(void) { static int turn = 0; int i, j, k; int *player_order; /* stages: pick letters 30 second timer (let dictionary corner think during this time?) reveal word lengths reveal words assign scores dictionary corner words */ printf(" Round %d: Letters round\n", round); printf("It is %s's turn to choose letters.\n", player[turn].name); /* read letter choices and generate letters */ for(i = 0; i < num_letters; i++) get_letter(i); /* let people think */ run_timer(); /* ask each player for their word length */ for(i = 0; i < players; i++) { printf("%s, how long is your word? ", player[(i + turn) % players].name); player[(i + turn) % players].length = atoi(get_line()); } /* get an aray of players sorted by word length */ player_order = malloc(sizeof(int) * players); for(i = 0; i < players; i++) player_order[i] = i; qsort(player_order, players, sizeof(int), length_cmp); /* ask players for their word, shortest first */ for(j = 0; j < players; j++) { i = player_order[j]; if(player[i].length <= 0) { player[i].word = NULL; continue; } printf("%s, what is your %d-letter word? ", player[i].name, player[i].length); player[i].word = strdup(get_line()); if(strlen(player[i].word) != player[i].length || !valid_word(i, letter)) { free(player[i].word); /* try again once if they didn't supply a suitable word */ printf("%s, what is your real %d-letter word? ", player[i].name, player[i].length); player[i].word = strdup(get_line()); if(strlen(player[i].word) != player[i].length || !valid_word(i, letter)) player[i].length = 0; } } /* re-sort to get non-words removed */ qsort(player_order, players, sizeof(int), length_cmp); /* find the best scorers */ for(j = players - 2; j >= 0; j--) { i = player_order[j]; if(player[i].length < player[player_order[players - 1]].length) break; } /* assign points to the scorers */ for(k = players - 1; k > j; k--) { i = player_order[k]; if(player[i].length == num_letters) {/* 9 letters score double */ printf("%d points to %s.\n", num_letters * 2, player[i].name); player[i].score += num_letters * 2; } else { printf("%d points to %s.\n", player[i].length, player[i].name); player[i].score += player[i].length; } } /* TODO: display best word in the blue and white style */ /* ask dictionary corner if they got anything better */ dict_solve(letter); /* TODO: display dictionary corner's word in blue and white */ /* increment the player whose turn it is to choose letters */ round++; turn++; if(turn >= players) turn = 0; /* tidy up */ free(player_order); for(i = 0; i < players; i++) free(player[i].word); }