tesseract 4.1.1
Loading...
Searching...
No Matches
combine_lang_model.cpp File Reference
#include "commandlineflags.h"
#include "commontraining.h"
#include "lang_model_helpers.h"
#include "tprintf.h"
#include "unicharset_training_utils.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 42 of file combine_lang_model.cpp.

42 {
43 // Sets properties on the input unicharset file, and writes:
44 // rootdir/lang/lang.charset_size=ddd.txt
45 // rootdir/lang/lang.traineddata
46 // rootdir/lang/lang.unicharset
47 // If the 3 word lists are provided, the dawgs are also added
48 // to the traineddata file.
49 // The output unicharset and charset_size files are just for
50 // human readability.
51 tesseract::CheckSharedLibraryVersion();
52 tesseract::ParseCommandLineFlags(argv[0], &argc, &argv, true);
53
54 GenericVector<STRING> words, puncs, numbers;
55 // If these reads fail, we get a warning message and an empty list of words.
56 tesseract::ReadFile(FLAGS_words.c_str(), nullptr).split('\n', &words);
57 tesseract::ReadFile(FLAGS_puncs.c_str(), nullptr).split('\n', &puncs);
58 tesseract::ReadFile(FLAGS_numbers.c_str(), nullptr).split('\n', &numbers);
59 // Load the input unicharset
60 UNICHARSET unicharset;
61 if (!unicharset.load_from_file(FLAGS_input_unicharset.c_str(), false)) {
62 tprintf("Failed to load unicharset from %s\n",
63 FLAGS_input_unicharset.c_str());
64 return 1;
65 }
66 tprintf("Loaded unicharset of size %d from file %s\n", unicharset.size(),
67 FLAGS_input_unicharset.c_str());
68
69 // Set unichar properties
70 tprintf("Setting unichar properties\n");
71 tesseract::SetupBasicProperties(/*report_errors*/ true,
72 /*decompose (NFD)*/ false, &unicharset);
73 tprintf("Setting script properties\n");
74 tesseract::SetScriptProperties(FLAGS_script_dir.c_str(), &unicharset);
75 // Combine everything into a traineddata file.
77 unicharset, FLAGS_script_dir.c_str(), FLAGS_version_str.c_str(),
78 FLAGS_output_dir.c_str(), FLAGS_lang.c_str(), FLAGS_pass_through_recoder,
79 words, puncs, numbers, FLAGS_lang_is_rtl, /*reader*/ nullptr,
80 /*writer*/ nullptr);
81}
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:35
void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, const bool remove_flags)
int CombineLangModel(const UNICHARSET &unicharset, const std::string &script_dir, const std::string &version_str, const std::string &output_dir, const std::string &lang, bool pass_through_recoder, const GenericVector< STRING > &words, const GenericVector< STRING > &puncs, const GenericVector< STRING > &numbers, bool lang_is_rtl, FileReader reader, FileWriter writer)
void SetScriptProperties(const std::string &script_dir, UNICHARSET *unicharset)
void SetupBasicProperties(bool report_errors, bool decompose, UNICHARSET *unicharset)
STRING ReadFile(const std::string &filename, FileReader reader)
void split(char c, GenericVector< STRING > *splited)
Definition: strngs.cpp:282
int size() const
Definition: unicharset.h:341
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:388