tesseract  3.05.02
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;
44  fold_set_len_ = NULL;
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  delete []fold_sets_[fold_set];
53  }
54  delete []fold_sets_;
55  fold_sets_ = NULL;
56  }
57  delete []fold_set_len_;
58  fold_set_len_ = NULL;
59  delete feat_extract_;
60  feat_extract_ = NULL;
61  }
62 
63  // pure virtual functions that need to be implemented by any inheriting class
64  virtual CharAltList * Classify(CharSamp *char_samp) = 0;
65  virtual int CharCost(CharSamp *char_samp) = 0;
66  virtual bool Train(CharSamp *char_samp, int ClassID) = 0;
67  virtual bool SetLearnParam(char *var_name, float val) = 0;
68  virtual bool Init(const string &data_file_path, const string &lang,
69  LangModel *lang_mod) = 0;
70 
71  // accessors
73  inline bool CaseSensitive() const { return case_sensitive_; }
74  inline void SetCaseSensitive(bool case_sensitive) {
75  case_sensitive_ = case_sensitive;
76  }
77 
78  protected:
79  virtual void Fold() = 0;
80  virtual bool LoadFoldingSets(const string &data_file_path,
81  const string &lang,
82  LangModel *lang_mod) = 0;
86  int **fold_sets_;
89  bool init_;
91 };
92 } // tesseract
93 
94 #endif // CHAR_CLASSIFIER_BASE_H
virtual CharAltList * Classify(CharSamp *char_samp)=0
void SetCaseSensitive(bool case_sensitive)
virtual bool LoadFoldingSets(const string &data_file_path, const string &lang, LangModel *lang_mod)=0
virtual void Fold()=0
virtual bool SetLearnParam(char *var_name, float val)=0
FeatureBase * FeatureExtractor()
CharClassifier(CharSet *char_set, TuningParams *params, FeatureBase *feat_extract)
virtual bool Init(const string &data_file_path, const string &lang, LangModel *lang_mod)=0
virtual int CharCost(CharSamp *char_samp)=0
virtual bool Train(CharSamp *char_samp, int ClassID)=0