tesseract  4.0.0-1-g2a2b
tesseract::ValidateGrapheme Class Reference

#include <validate_grapheme.h>

Inheritance diagram for tesseract::ValidateGrapheme:
tesseract::Validator

Public Member Functions

 ValidateGrapheme (ViramaScript script, bool report_errors)
 
 ~ValidateGrapheme ()
 
- Public Member Functions inherited from tesseract::Validator
virtual ~Validator ()
 

Protected Member Functions

bool ConsumeGraphemeIfValid () override
 
CharClass UnicodeToCharClass (char32 ch) const override
 
- Protected Member Functions inherited from tesseract::Validator
 Validator (ViramaScript script, bool report_errors)
 
bool ValidateCleanAndSegmentInternal (GraphemeNormMode g_mode, const std::vector< char32 > &src, std::vector< std::vector< char32 >> *dest)
 
void MoveResultsToDest (GraphemeNormMode g_mode, std::vector< std::vector< char32 >> *dest)
 
bool IsSubscriptScript () const
 
bool CodeOnlyToOutput ()
 
void MultiCodePart (int length)
 
bool UseMultiCode (int length)
 
void ComputeClassCodes (const std::vector< char32 > &text)
 
void Clear ()
 

Additional Inherited Members

- Static Public Member Functions inherited from tesseract::Validator
static bool ValidateCleanAndSegment (GraphemeNormMode g_mode, bool report_errors, const std::vector< char32 > &src, std::vector< std::vector< char32 >> *dest)
 
static bool IsZeroWidthMark (char32 ch)
 
- Static Public Attributes inherited from tesseract::Validator
static const char32 kZeroWidthSpace = 0x200B
 
static const char32 kZeroWidthNonJoiner = 0x200C
 
static const char32 kZeroWidthJoiner = 0x200D
 
static const char32 kLeftToRightMark = 0x200E
 
static const char32 kRightToLeftMark = 0x200F
 
static const char32 kInvalid = 0xfffd
 
- Protected Types inherited from tesseract::Validator
enum  CharClass {
  CharClass::kConsonant = 'C', CharClass::kVowel = 'V', CharClass::kVirama = 'H', CharClass::kMatra = 'M',
  CharClass::kMatraPiece = 'P', CharClass::kVowelModifier = 'D', CharClass::kZeroWidthNonJoiner = 'z', CharClass::kZeroWidthJoiner = 'Z',
  CharClass::kVedicMark = 'v', CharClass::kNukta = 'N', CharClass::kRobat = 'R', CharClass::kOther = 'O',
  CharClass::kWhitespace = ' ', CharClass::kCombiner = 'c'
}
 
using IndicPair = std::pair< CharClass, char32 >
 
- Static Protected Member Functions inherited from tesseract::Validator
static std::unique_ptr< ValidatorScriptValidator (ViramaScript script, bool report_errors)
 
static ViramaScript MostFrequentViramaScript (const std::vector< char32 > &utf32)
 
static bool IsVirama (char32 unicode)
 
static bool IsVedicAccent (char32 unicode)
 
- Protected Attributes inherited from tesseract::Validator
ViramaScript script_
 
std::vector< IndicPaircodes_
 
std::vector< std::vector< char32 > > parts_
 
std::vector< char32output_
 
int codes_used_
 
int output_used_
 
bool report_errors_
 
- Static Protected Attributes inherited from tesseract::Validator
static const int kIndicCodePageSize = 128
 
static const char32 kMinIndicUnicode = 0x900
 
static const char32 kMaxSinhalaUnicode = 0xdff
 
static const char32 kMaxViramaScriptUnicode = 0x17ff
 
static const char32 kSinhalaVirama = 0xdca
 
static const char32 kMyanmarVirama = 0x1039
 
static const char32 kKhmerVirama = 0x17d2
 
static const char32 kJavaneseVirama = 0xa9c0
 
static const char32 kMaxJavaneseUnicode = 0xa9df
 

Detailed Description

Definition at line 10 of file validate_grapheme.h.

Constructor & Destructor Documentation

◆ ValidateGrapheme()

tesseract::ValidateGrapheme::ValidateGrapheme ( ViramaScript  script,
bool  report_errors 
)
inline

Definition at line 12 of file validate_grapheme.h.

13  : Validator(script, report_errors) {}
Validator(ViramaScript script, bool report_errors)
Definition: validator.h:136

◆ ~ValidateGrapheme()

tesseract::ValidateGrapheme::~ValidateGrapheme ( )
inline

Definition at line 14 of file validate_grapheme.h.

14 {}

Member Function Documentation

◆ ConsumeGraphemeIfValid()

bool tesseract::ValidateGrapheme::ConsumeGraphemeIfValid ( )
overrideprotectedvirtual

Implements tesseract::Validator.

Definition at line 7 of file validate_grapheme.cpp.

7  {
8  int num_codes = codes_.size();
9  char32 prev_prev_ch = ' ';
10  char32 prev_ch = ' ';
12  int num_codes_in_grapheme = 0;
13  while (codes_used_ < num_codes) {
14  CharClass cc = codes_[codes_used_].first;
15  char32 ch = codes_[codes_used_].second;
16  const bool is_combiner =
18  // Reject easily detected badly formed sequences.
19  if (prev_cc == CharClass::kWhitespace && is_combiner) {
20  if (report_errors_) tprintf("Word started with a combiner:0x%x\n", ch);
21  return false;
22  }
23  if (prev_cc == CharClass::kVirama && cc == CharClass::kVirama) {
24  if (report_errors_)
25  tprintf("Two grapheme links in a row:0x%x 0x%x\n", prev_ch, ch);
26  return false;
27  }
28  if (prev_cc != CharClass::kWhitespace && cc != CharClass::kWhitespace &&
29  IsBadlyFormed(prev_ch, ch)) {
30  return false;
31  }
32  bool prev_is_fwd_combiner =
33  prev_ch == kZeroWidthJoiner || prev_cc == CharClass::kVirama ||
34  (prev_ch == kZeroWidthNonJoiner &&
35  (cc == CharClass::kVirama || prev_prev_ch == kZeroWidthJoiner));
36  if (num_codes_in_grapheme > 0 && !is_combiner && !prev_is_fwd_combiner)
37  break;
39  ++num_codes_in_grapheme;
40  prev_prev_ch = prev_ch;
41  prev_ch = ch;
42  prev_cc = cc;
43  }
44  if (num_codes_in_grapheme > 0) MultiCodePart(num_codes_in_grapheme);
45  return true;
46 }
std::vector< IndicPair > codes_
Definition: validator.h:232
signed int char32
static const char32 kZeroWidthNonJoiner
Definition: validator.h:96
void MultiCodePart(int length)
Definition: validator.h:182
DLLSYM void tprintf(const char *format,...)
Definition: tprintf.cpp:37
static const char32 kZeroWidthJoiner
Definition: validator.h:97

◆ UnicodeToCharClass()

Validator::CharClass tesseract::ValidateGrapheme::UnicodeToCharClass ( char32  ch) const
overrideprotectedvirtual

Implements tesseract::Validator.

Definition at line 48 of file validate_grapheme.cpp.

48  {
49  if (IsVedicAccent(ch)) return CharClass::kVedicMark;
50  // The ZeroWidth[Non]Joiner characters are mapped to kCombiner as they
51  // always combine with the previous character.
52  if (u_hasBinaryProperty(ch, UCHAR_GRAPHEME_LINK)) return CharClass::kVirama;
53  if (u_isUWhiteSpace(ch)) return CharClass::kWhitespace;
54  // Workaround for Javanese Aksara's Taling, do not label it as a combiner
55  if (ch == 0xa9ba) return CharClass::kConsonant;
56  int char_type = u_charType(ch);
57  if (char_type == U_NON_SPACING_MARK || char_type == U_ENCLOSING_MARK ||
58  char_type == U_COMBINING_SPACING_MARK || ch == kZeroWidthNonJoiner ||
59  ch == kZeroWidthJoiner)
60  return CharClass::kCombiner;
61  return CharClass::kOther;
62 }
static bool IsVedicAccent(char32 unicode)
Definition: validator.cpp:191
static const char32 kZeroWidthNonJoiner
Definition: validator.h:96
static const char32 kZeroWidthJoiner
Definition: validator.h:97

The documentation for this class was generated from the following files: