tesseract  5.0.0
ambiguous_words.cpp File Reference
#include "commontraining.h"
#include "dict.h"
#include "tesseractclass.h"
#include <tesseract/baseapi.h>
#include "helpers.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(
39  "Usage: %s -v | --version | %s [-l lang] tessdata_dir wordlist_file"
40  " output_ambiguous_wordlist_file\n",
41  argv[0], argv[0]);
42  return 1;
43  }
44  int argv_offset = 0;
45  std::string lang;
46  if (argc == 6) {
47  lang = argv[2];
48  argv_offset = 2;
49  } else {
50  lang = "eng";
51  }
52  const char *tessdata_dir = argv[++argv_offset];
53  const char *input_file_str = argv[++argv_offset];
54  const char *output_file_str = argv[++argv_offset];
55 
56  // Initialize Tesseract.
58  std::vector<std::string> vars_vec;
59  std::vector<std::string> vars_values;
60  vars_vec.emplace_back("output_ambig_words_file");
61  vars_values.emplace_back(output_file_str);
62  api.Init(tessdata_dir, lang.c_str(), tesseract::OEM_TESSERACT_ONLY, nullptr, 0, &vars_vec,
63  &vars_values, false);
64  tesseract::Dict &dict = api.tesseract()->getDict();
65  FILE *input_file = fopen(input_file_str, "rb");
66  if (input_file == nullptr) {
67  tesseract::tprintf("Failed to open input wordlist file %s\n", input_file_str);
68  exit(1);
69  }
70  char str[CHARS_PER_LINE];
71 
72  // Read word list and call Dict::NoDangerousAmbig() for each word
73  // to record ambiguities in the output file.
74  while (fgets(str, CHARS_PER_LINE, input_file) != nullptr) {
75  tesseract::chomp_string(str); // remove newline
76  tesseract::WERD_CHOICE word(str, dict.getUnicharset());
77  dict.NoDangerousAmbig(&word, nullptr, false, nullptr);
78  }
79  // Clean up.
80  fclose(input_file);
81 }
#define CHARS_PER_LINE
Definition: dict.h:44
@ OEM_TESSERACT_ONLY
Definition: publictypes.h:266
void tprintf(const char *format,...)
Definition: tprintf.cpp:41
void chomp_string(char *str)
Definition: helpers.h:89
static const char * Version()
Definition: baseapi.cpp:238
int Init(const char *datapath, const char *language, OcrEngineMode mode, char **configs, int configs_size, const std::vector< std::string > *vars_vec, const std::vector< std::string > *vars_values, bool set_only_non_debug_params)
Definition: baseapi.cpp:365
Tesseract * tesseract() const
Definition: baseapi.h:713
Dict & getDict() override
const UNICHARSET & getUnicharset() const
Definition: dict.h:104
bool NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
Definition: stopper.cpp:158