tesseract  4.0.0-1-g2a2b
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 31 of file ambiguous_words.cpp.

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