All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
classifier_base.h
Go to the documentation of this file.
1 /**********************************************************************
2  * File: classifier_base.h
3  * Description: Declaration of the Base Character Classifier
4  * Author: Ahmad Abdulkader
5  * Created: 2007
6  *
7  * (C) Copyright 2008, Google Inc.
8  ** Licensed under the Apache License, Version 2.0 (the "License");
9  ** you may not use this file except in compliance with the License.
10  ** You may obtain a copy of the License at
11  ** http://www.apache.org/licenses/LICENSE-2.0
12  ** Unless required by applicable law or agreed to in writing, software
13  ** distributed under the License is distributed on an "AS IS" BASIS,
14  ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  ** See the License for the specific language governing permissions and
16  ** limitations under the License.
17  *
18  **********************************************************************/
19 
20 // The CharClassifier class is the abstract class for any character/grapheme
21 // classifier.
22 
23 #ifndef CHAR_CLASSIFIER_BASE_H
24 #define CHAR_CLASSIFIER_BASE_H
25 
26 #include <string>
27 #include "char_samp.h"
28 #include "char_altlist.h"
29 #include "char_set.h"
30 #include "feature_base.h"
31 #include "lang_model.h"
32 #include "tuning_params.h"
33 
34 namespace tesseract {
36  public:
37  CharClassifier(CharSet *char_set, TuningParams *params,
38  FeatureBase *feat_extract) {
39  char_set_ = char_set;
40  params_ = params;
41  feat_extract_ = feat_extract;
42  fold_sets_ = NULL;
43  fold_set_cnt_ = 0;
45  init_ = false;
46  case_sensitive_ = true;
47  }
48 
49  virtual ~CharClassifier() {
50  if (fold_sets_ != NULL) {
51  for (int fold_set = 0; fold_set < fold_set_cnt_; fold_set++) {
52  if (fold_sets_[fold_set] != NULL) {
53  delete []fold_sets_[fold_set];
54  }
55  }
56  delete []fold_sets_;
57  fold_sets_ = NULL;
58  }
59  if (fold_set_len_ != NULL) {
60  delete []fold_set_len_;
62  }
63  if (feat_extract_ != NULL) {
64  delete feat_extract_;
66  }
67  }
68 
69  // pure virtual functions that need to be implemented by any inheriting class
70  virtual CharAltList * Classify(CharSamp *char_samp) = 0;
71  virtual int CharCost(CharSamp *char_samp) = 0;
72  virtual bool Train(CharSamp *char_samp, int ClassID) = 0;
73  virtual bool SetLearnParam(char *var_name, float val) = 0;
74  virtual bool Init(const string &data_file_path, const string &lang,
75  LangModel *lang_mod) = 0;
76 
77  // accessors
79  inline bool CaseSensitive() const { return case_sensitive_; }
80  inline void SetCaseSensitive(bool case_sensitive) {
81  case_sensitive_ = case_sensitive;
82  }
83 
84  protected:
85  virtual void Fold() = 0;
86  virtual bool LoadFoldingSets(const string &data_file_path,
87  const string &lang,
88  LangModel *lang_mod) = 0;
92  int **fold_sets_;
95  bool init_;
97 };
98 } // tesseract
99 
100 #endif // CHAR_CLASSIFIER_BASE_H
CharClassifier(CharSet *char_set, TuningParams *params, FeatureBase *feat_extract)
virtual bool SetLearnParam(char *var_name, float val)=0
virtual bool LoadFoldingSets(const string &data_file_path, const string &lang, LangModel *lang_mod)=0
virtual int CharCost(CharSamp *char_samp)=0
virtual CharAltList * Classify(CharSamp *char_samp)=0
virtual void Fold()=0
void SetCaseSensitive(bool case_sensitive)
virtual bool Train(CharSamp *char_samp, int ClassID)=0
FeatureBase * FeatureExtractor()
virtual bool Init(const string &data_file_path, const string &lang, LangModel *lang_mod)=0
#define NULL
Definition: host.h:144