tesseract  5.0.0
validate_javanese.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: validate_javanese.h
3  * Description: Text validator for Javanese Script - aksara jawa.
4  * Author: Shree Devi Kumar
5  * Created: August 03, 2018
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  * http://www.apache.org/licenses/LICENSE-2.0
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  *
17  **********************************************************************/
18 
19 #ifndef TESSERACT_TRAINING_VALIDATE_JAVANESE_H_
20 #define TESSERACT_TRAINING_VALIDATE_JAVANESE_H_
21 
22 #include "validator.h"
23 
24 namespace tesseract {
25 
26 // Subclass of Validator that validates and segments Javanese scripts
27 
28 class ValidateJavanese : public Validator {
29 public:
30  ValidateJavanese(ViramaScript script, bool report_errors) : Validator(script, report_errors) {}
31  ~ValidateJavanese() override = default;
32 
33 protected:
34  // Returns whether codes matches the pattern for an Javanese Grapheme.
35  // Consumes the next Grapheme in codes_[codes_used_++...] and copies it to
36  // parts_ and output_. Returns true if a valid Grapheme was consumed,
37  // otherwise does not increment codes_used_.
38  bool ConsumeGraphemeIfValid() override;
39  // Returns the CharClass corresponding to the given Unicode ch.
41 
42 private:
43  // Helper consumes/copies a virama and any associated post-virama joiners.
44  bool ConsumeViramaIfValid(IndicPair joiner, bool post_matra);
45  // Helper consumes/copies a series of consonants separated by viramas while
46  // valid, but not any vowel or other modifiers.
47  bool ConsumeConsonantHeadIfValid();
48  // Helper consumes/copies a tail part of a consonant, comprising optional
49  // matra/piece, vowel modifier, vedic mark, terminating virama.
50  bool ConsumeConsonantTailIfValid();
51  // Helper consumes/copies a vowel and optional modifiers.
52  bool ConsumeVowelIfValid();
53 
54  // Some special unicodes used only for Javanese processing.
55  static const char32 kPengkal = 0xa9be; // Javanese Ya
56  static const char32 kCakra = 0xa9bf; // Javanese Ra
57 };
58 
59 } // namespace tesseract
60 
61 #endif // TESSERACT_TRAINING_VALIDATE_JAVANESE_H_
signed int char32
Definition: unichar.h:51
bool ConsumeGraphemeIfValid() override
~ValidateJavanese() override=default
Validator::CharClass UnicodeToCharClass(char32 ch) const override
ValidateJavanese(ViramaScript script, bool report_errors)
std::pair< CharClass, char32 > IndicPair
Definition: validator.h:135