Tesseract
3.02
|
00001 /********************************************************************** 00002 * File: char_altlist.h 00003 * Description: Declaration of a Character Alternate List Class 00004 * Author: Ahmad Abdulkader 00005 * Created: 2007 00006 * 00007 * (C) Copyright 2008, Google Inc. 00008 ** Licensed under the Apache License, Version 2.0 (the "License"); 00009 ** you may not use this file except in compliance with the License. 00010 ** You may obtain a copy of the License at 00011 ** http://www.apache.org/licenses/LICENSE-2.0 00012 ** Unless required by applicable law or agreed to in writing, software 00013 ** distributed under the License is distributed on an "AS IS" BASIS, 00014 ** WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00015 ** See the License for the specific language governing permissions and 00016 ** limitations under the License. 00017 * 00018 **********************************************************************/ 00019 00020 #ifndef CHAR_ALT_LIST_H 00021 #define CHAR_ALT_LIST_H 00022 00023 // The CharAltList class holds the list of class alternates returned from 00024 // a character classifier. Each alternate represents a class ID. 00025 // It inherits from the AltList class. 00026 // The CharAltList owns a CharSet object that maps a class-id to a string. 00027 00028 #include "altlist.h" 00029 #include "char_set.h" 00030 00031 namespace tesseract { 00032 class CharAltList : public AltList { 00033 public: 00034 CharAltList(const CharSet *char_set, int max_alt = kMaxCharAlt); 00035 ~CharAltList(); 00036 00037 // Sort the alternate list based on cost 00038 void Sort(); 00039 // insert a new alternate with the specified class-id, cost and tag 00040 bool Insert(int class_id, int cost, void *tag = NULL); 00041 // returns the cost of a specific class ID 00042 inline int ClassCost(int class_id) const { 00043 if (class_id_cost_ == NULL || 00044 class_id < 0 || 00045 class_id >= char_set_->ClassCount()) { 00046 return WORST_COST; 00047 } 00048 return class_id_cost_[class_id]; 00049 } 00050 // returns the alternate class-id corresponding to an alternate index 00051 inline int Alt(int alt_idx) const { return class_id_alt_[alt_idx]; } 00052 // set the cost of a certain alternate 00053 void SetAltCost(int alt_idx, int cost) { 00054 alt_cost_[alt_idx] = cost; 00055 class_id_cost_[class_id_alt_[alt_idx]] = cost; 00056 } 00057 00058 private: 00059 // character set object. Passed at construction time 00060 const CharSet *char_set_; 00061 // array of alternate class-ids 00062 int *class_id_alt_; 00063 // array of alternate costs 00064 int *class_id_cost_; 00065 // default max count of alternates 00066 static const int kMaxCharAlt = 256; 00067 }; 00068 } 00069 00070 #endif // CHAR_ALT_LIST_H