Returns the number of samples for the given font,class pair. If randomize is true, returns the number of samples accessible with randomizing on. (Increases the number of samples if small.) OrganizeByFontAndClass must have been already called.
| 154 | // with randomizing on. (Increases the number of samples if small.) |
| 155 | // OrganizeByFontAndClass must have been already called. |
| 156 | int TrainingSampleSet::NumClassSamples(int font_id, int class_id, |
| 157 | bool randomize) const { |
| 158 | ASSERT_HOST(font_class_array_ != NULL); |
| 159 | if (font_id < 0 || class_id < 0 || |
| 160 | font_id >= font_id_map_.SparseSize() || class_id >= unicharset_size_) { |
| 161 | // There are no samples because the font or class doesn't exist. |
| 162 | return 0; |
| 163 | } |
| 164 | int font_index = font_id_map_.SparseToCompact(font_id); |
| 165 | if (font_index < 0) |
| 166 | return 0; // The font has no samples. |
| 167 | if (randomize) |
| 168 | return (*font_class_array_)(font_index, class_id).samples.size(); |
| 169 | else |
| 170 | return (*font_class_array_)(font_index, class_id).num_raw_samples; |
| 171 | } |
| 172 | |
| 173 | // Gets a sample by its index. |
| 174 | const TrainingSample* TrainingSampleSet::GetSample(int index) const { |
no test coverage detected