All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
dawg2wordlist.cpp File Reference
#include "dawg.h"
#include "host.h"
#include "tesscallback.h"
#include "trie.h"
#include "unicharset.h"

Go to the source code of this file.

Classes

class  WordOutputter
 

Functions

tesseract::DawgLoadSquishedDawg (const UNICHARSET &unicharset, const char *filename)
 
int WriteDawgAsWordlist (const UNICHARSET &unicharset, const tesseract::Dawg *dawg, const char *outfile_name)
 
int main (int argc, char *argv[])
 

Variables

const int kDictDebugLevel = 1
 

Function Documentation

tesseract::Dawg* LoadSquishedDawg ( const UNICHARSET unicharset,
const char *  filename 
)

Definition at line 28 of file dawg2wordlist.cpp.

29  {
30  const int kDictDebugLevel = 1;
31  FILE *dawg_file = fopen(filename, "rb");
32  if (dawg_file == NULL) {
33  tprintf("Could not open %s for reading.\n", filename);
34  return NULL;
35  }
36  tprintf("Loading word list from %s\n", filename);
39  kDictDebugLevel);
40  tprintf("Word list loaded.\n");
41  fclose(dawg_file);
42  return retval;
43 }
#define tprintf(...)
Definition: tprintf.h:31
#define NULL
Definition: host.h:144
const int kDictDebugLevel
int main ( int  argc,
char *  argv[] 
)

Definition at line 70 of file dawg2wordlist.cpp.

70  {
71  if (argc != 4) {
72  tprintf("Print all the words in a given dawg.\n");
73  tprintf("Usage: %s <unicharset> <dawgfile> <wordlistfile>\n",
74  argv[0]);
75  return 1;
76  }
77  const char *unicharset_file = argv[1];
78  const char *dawg_file = argv[2];
79  const char *wordlist_file = argv[3];
80  UNICHARSET unicharset;
81  if (!unicharset.load_from_file(unicharset_file)) {
82  tprintf("Error loading unicharset from %s.\n", unicharset_file);
83  return 1;
84  }
85  tesseract::Dawg *dict = LoadSquishedDawg(unicharset, dawg_file);
86  if (dict == NULL) {
87  tprintf("Error loading dictionary from %s.\n", dawg_file);
88  return 1;
89  }
90  int retval = WriteDawgAsWordlist(unicharset, dict, wordlist_file);
91  delete dict;
92  return retval;
93 }
int WriteDawgAsWordlist(const UNICHARSET &unicharset, const tesseract::Dawg *dawg, const char *outfile_name)
#define tprintf(...)
Definition: tprintf.h:31
tesseract::Dawg * LoadSquishedDawg(const UNICHARSET &unicharset, const char *filename)
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:346
#define NULL
Definition: host.h:144
int WriteDawgAsWordlist ( const UNICHARSET unicharset,
const tesseract::Dawg dawg,
const char *  outfile_name 
)

Definition at line 54 of file dawg2wordlist.cpp.

56  {
57  FILE *out = fopen(outfile_name, "wb");
58  if (out == NULL) {
59  tprintf("Could not open %s for writing.\n", outfile_name);
60  return 1;
61  }
62  WordOutputter outputter(out);
63  TessCallback1<const char *> *print_word_cb =
65  dawg->iterate_words(unicharset, print_word_cb);
66  delete print_word_cb;
67  return fclose(out);
68 }
#define tprintf(...)
Definition: tprintf.h:31
void output_word(const char *word)
void iterate_words(const UNICHARSET &unicharset, TessCallback1< const WERD_CHOICE * > *cb) const
Definition: dawg.cpp:106
_ConstTessMemberResultCallback_0_0< false, R, T1 >::base * NewPermanentTessCallback(const T1 *obj, R(T2::*member)() const)
Definition: tesscallback.h:116
#define NULL
Definition: host.h:144

Variable Documentation

const int kDictDebugLevel = 1

Definition at line 26 of file dawg2wordlist.cpp.