tesseract  4.0.0-1-g2a2b
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

 STRING_PARAM_FLAG (input_unicharset, "", "Filename with unicharset to complete and use in encoding")
 
 STRING_PARAM_FLAG (script_dir, "", "Directory name for input script unicharsets")
 
 STRING_PARAM_FLAG (words, "", "File listing words to use for the system dictionary")
 
 STRING_PARAM_FLAG (puncs, "", "File listing punctuation patterns")
 
 STRING_PARAM_FLAG (numbers, "", "File listing number patterns")
 
 STRING_PARAM_FLAG (output_dir, "", "Root directory for output files")
 
 STRING_PARAM_FLAG (version_str, "", "Version string to add to traineddata file")
 
 STRING_PARAM_FLAG (lang, "", "Name of language being processed")
 
 BOOL_PARAM_FLAG (lang_is_rtl, false, "True if lang being processed is written right-to-left")
 
 BOOL_PARAM_FLAG (pass_through_recoder, false, "If true, the recoder is a simple pass-through of the" " unicharset. Otherwise, potentially a compression of it")
 
int main (int argc, char **argv)
 

Function Documentation

◆ BOOL_PARAM_FLAG() [1/2]

BOOL_PARAM_FLAG ( lang_is_rtl  ,
false  ,
"True if lang being processed is written right-to-left"   
)

◆ BOOL_PARAM_FLAG() [2/2]

BOOL_PARAM_FLAG ( pass_through_recoder  ,
false  ,
"If  true,
the recoder is a simple pass-through of the" " unicharset.  Otherwise,
potentially a compression of it"   
)

◆ 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 }
void SetupBasicProperties(bool report_errors, bool decompose, UNICHARSET *unicharset)
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)
int size() const
Definition: unicharset.h:336
void ParseCommandLineFlags(const char *usage, int *argc, char ***argv, const bool remove_flags)
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
STRING ReadFile(const std::string &filename, FileReader reader)
void SetScriptProperties(const std::string &script_dir, UNICHARSET *unicharset)
bool load_from_file(const char *const filename, bool skip_fragments)
Definition: unicharset.h:383

◆ STRING_PARAM_FLAG() [1/8]

STRING_PARAM_FLAG ( input_unicharset  ,
""  ,
"Filename with unicharset to complete and use in encoding"   
)

◆ STRING_PARAM_FLAG() [2/8]

STRING_PARAM_FLAG ( script_dir  ,
""  ,
"Directory name for input script unicharsets"   
)

◆ STRING_PARAM_FLAG() [3/8]

STRING_PARAM_FLAG ( words  ,
""  ,
"File listing words to use for the system dictionary"   
)

◆ STRING_PARAM_FLAG() [4/8]

STRING_PARAM_FLAG ( puncs  ,
""  ,
"File listing punctuation patterns"   
)

◆ STRING_PARAM_FLAG() [5/8]

STRING_PARAM_FLAG ( numbers  ,
""  ,
"File listing number patterns"   
)

◆ STRING_PARAM_FLAG() [6/8]

STRING_PARAM_FLAG ( output_dir  ,
""  ,
"Root directory for output files"   
)

◆ STRING_PARAM_FLAG() [7/8]

STRING_PARAM_FLAG ( version_str  ,
""  ,
"Version string to add to traineddata file"   
)

◆ STRING_PARAM_FLAG() [8/8]

STRING_PARAM_FLAG ( lang  ,
""  ,
"Name of language being processed"   
)