tesseract  4.0.0-beta.1-59-g2cc4
combine_lang_model.cpp File Reference

Go to the source code of this file.

Functions

 STRING_PARAM_FLAG (input_unicharset, "", "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 
)

This program reads in a text file consisting of feature samples from a training page in the following format:

   FontName UTF8-char-str xmin ymin xmax ymax page-number
    NumberOfFeatureTypes(N)
      FeatureTypeName1 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      FeatureTypeName2 NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
      ...
      FeatureTypeNameN NumberOfFeatures(M)
         Feature1
         ...
         FeatureM
   FontName CharName ...

The result of this program is a binary inttemp file used by the OCR engine.

Parameters
argcnumber of command line arguments
argvarray of command line arguments
Returns
none
Note
Exceptions: none
History: Fri Aug 18 08:56:17 1989, DSJ, Created.
History: Mon May 18 1998, Christy Russson, Revistion started.

Definition at line 40 of file combine_lang_model.cpp.

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

◆ STRING_PARAM_FLAG() [1/8]

STRING_PARAM_FLAG ( input_unicharset  ,
""  ,
"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"   
)