tesseract  5.0.0-alpha-619-ge9db
ambiguous_words.cpp File Reference
#include <tesseract/baseapi.h>
#include "commontraining.h"
#include <tesseract/helpers.h>
#include <tesseract/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.c_str(), 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 }
WERD_CHOICE
Definition: ratngs.h:261
STRING
Definition: strngs.h:45
tesseract::TessBaseAPI::Init
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:337
GenericVector::push_back
int push_back(T object)
Definition: genericvector.h:799
STRING::c_str
const char * c_str() const
Definition: strngs.cpp:192
chomp_string
void chomp_string(char *str)
Definition: helpers.h:75
tesseract::TessBaseAPI
Definition: baseapi.h:98
tesseract::Tesseract::getDict
Dict & getDict() override
Definition: tesseractclass.cpp:564
tesseract::TessBaseAPI::Version
static const char * Version()
Definition: baseapi.cpp:233
GenericVector< STRING >
tesseract::Dict
Definition: dict.h:91
tprintf
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:34
tesseract::Dict::getUnicharset
const UNICHARSET & getUnicharset() const
Definition: dict.h:101
tesseract::Dict::NoDangerousAmbig
bool NoDangerousAmbig(WERD_CHOICE *BestChoice, DANGERR *fixpt, bool fix_replaceable, MATRIX *ratings)
Definition: stopper.cpp:158
tesseract::TessBaseAPI::tesseract
Tesseract * tesseract() const
Definition: baseapi.h:798
CHARS_PER_LINE
#define CHARS_PER_LINE
Definition: dict.h:38
tesseract::OEM_TESSERACT_ONLY
Definition: publictypes.h:266