tesseract  v4.0.0-17-g361f3264
Open Source OCR Engine
validate_grapheme.h
1 #ifndef TESSERACT_TRAINING_VALIDATE_GRAPHEME_H_
2 #define TESSERACT_TRAINING_VALIDATE_GRAPHEME_H_
3 
4 #include "validator.h"
5 
6 namespace tesseract {
7 
8 // Subclass of Validator that validates and segments generic unicode into
9 // grapheme clusters, including Latin with diacritics.
10 class ValidateGrapheme : public Validator {
11  public:
12  ValidateGrapheme(ViramaScript script, bool report_errors)
13  : Validator(script, report_errors) {}
15 
16  protected:
17  // Consumes the next Grapheme in codes_[codes_used_++...] and copies it to
18  // parts_ and output_. Returns true if a valid Grapheme was consumed,
19  // otherwise does not increment codes_used_.
20  bool ConsumeGraphemeIfValid() override;
21  // Returns the CharClass corresponding to the given Unicode ch.
22  CharClass UnicodeToCharClass(char32 ch) const override;
23 
24  private:
25  // Helper returns true if the sequence prev_ch,ch is invalid.
26  bool IsBadlyFormed(char32 prev_ch, char32 ch);
27  // Helper returns true if the sequence prev_ch,ch is an invalid Indic vowel.
28  static bool IsBadlyFormedIndicVowel(char32 prev_ch, char32 ch);
29  // Helper returns true if the sequence prev_ch,ch is invalid Thai.
30  static bool IsBadlyFormedThai(char32 prev_ch, char32 ch);
31 };
32 
33 } // namespace tesseract
34 
35 #endif // TESSERACT_TRAINING_VALIDATE_GRAPHEME_H_
ValidateGrapheme(ViramaScript script, bool report_errors)
Definition: validate_grapheme.h:12
signed int char32
Definition: unichar.h:52
Definition: baseapi.cpp:94
CharClass UnicodeToCharClass(char32 ch) const override
Definition: validate_grapheme.cpp:48
static bool IsBadlyFormedThai(char32 prev_ch, char32 ch)
Definition: validate_grapheme.cpp:133
ViramaScript
Definition: validator.h:53
CharClass
Definition: validator.h:112
~ValidateGrapheme()
Definition: validate_grapheme.h:14
bool ConsumeGraphemeIfValid() override
Definition: validate_grapheme.cpp:7
bool IsBadlyFormed(char32 prev_ch, char32 ch)
Definition: validate_grapheme.cpp:65
Definition: validate_grapheme.h:10
static bool IsBadlyFormedIndicVowel(char32 prev_ch, char32 ch)
Definition: validate_grapheme.cpp:92
Definition: validator.h:72