tesseract  4.1.1
ambiguous_words.cpp File Reference
#include "baseapi.h"
#include "commontraining.h"
#include "helpers.h"
#include "strngs.h"
#include "dict.h"
#include "tesseractclass.h"

Go to the source code of this file.

Functions

int main (int argc, char **argv)
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 30 of file ambiguous_words.cpp.

30  {
31  tesseract::CheckSharedLibraryVersion();
32 
33  // Parse input arguments.
34  if (argc > 1 && (!strcmp(argv[1], "-v") || !strcmp(argv[1], "--version"))) {
35  printf("%s\n", tesseract::TessBaseAPI::Version());
36  return 0;
37  } else if (argc != 4 && (argc != 6 || strcmp(argv[1], "-l") != 0)) {
38  printf("Usage: %s -v | --version | %s [-l lang] tessdata_dir wordlist_file"
39  " output_ambiguous_wordlist_file\n", argv[0], argv[0]);
40  return 1;
41  }
42  int argv_offset = 0;
43  STRING lang;
44  if (argc == 6) {
45  lang = argv[2];
46  argv_offset = 2;
47  } else {
48  lang = "eng";
49  }
50  const char *tessdata_dir = argv[++argv_offset];
51  const char *input_file_str = argv[++argv_offset];
52  const char *output_file_str = argv[++argv_offset];
53 
54  // Initialize Tesseract.
56  GenericVector<STRING> vars_vec;
57  GenericVector<STRING> vars_values;
58  vars_vec.push_back("output_ambig_words_file");
59  vars_values.push_back(output_file_str);
60  api.Init(tessdata_dir, lang.string(), tesseract::OEM_TESSERACT_ONLY, nullptr,
61  0, &vars_vec, &vars_values, false);
62  tesseract::Dict &dict = api.tesseract()->getDict();
63  FILE *input_file = fopen(input_file_str, "rb");
64  if (input_file == nullptr) {
65  tprintf("Failed to open input wordlist file %s\n", input_file_str);
66  exit(1);
67  }
68  char str[CHARS_PER_LINE];
69 
70  // Read word list and call Dict::NoDangerousAmbig() for each word
71  // to record ambiguities in the output file.
72  while (fgets(str, CHARS_PER_LINE, input_file) != nullptr) {
73  chomp_string(str); // remove newline
74  WERD_CHOICE word(str, dict.getUnicharset());
75  dict.NoDangerousAmbig(&word, nullptr, false, nullptr);
76  }
77  // Clean up.
78  fclose(input_file);
79 }
void chomp_string(char *str)
Definition: helpers.h:77
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
#define CHARS_PER_LINE
Definition: dict.h:38
@ OEM_TESSERACT_ONLY
Definition: publictypes.h:269
int push_back(T object)
static const char * Version()
Definition: baseapi.cpp:233
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const GenericVector< STRING > *vars_vec, const GenericVector< STRING > *vars_values, bool set_only_non_debug_params)
Definition: baseapi.cpp:346
Tesseract * tesseract() const
Definition: baseapi.h:801
Dict & getDict() override
Definition: strngs.h:45
const char * string() const
Definition: strngs.cpp:194
const UNICHARSET & getUnicharset() const
Definition: dict.h:101
bool NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
Definition: stopper.cpp:144