58 string tuning_params_file;
59 tuning_params_file = data_file_path +
lang;
60 tuning_params_file +=
".cube.params";
62 if (!obj->
Load(tuning_params_file)) {
63 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Create): unable to " 64 "load tuning parameters from %s\n", tuning_params_file.c_str());
78 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): unable to read " 79 "file %s\n", tuning_params_file.c_str());
84 vector<string> str_vec;
86 if (str_vec.size() < 8) {
87 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): number of rows " 88 "in parameter file is too low\n");
93 for (
int entry = 0; entry < str_vec.size(); entry++) {
95 vector<string> str_tok;
99 if (str_tok.size() != 2) {
100 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid format in " 101 "line: %s.\n", str_vec[entry].c_str());
106 char peekchar = (str_tok[1].c_str())[0];
107 if ((peekchar >=
'0' && peekchar <=
'9') ||
108 peekchar ==
'-' || peekchar ==
'+' ||
111 if (sscanf(str_tok[1].c_str(),
"%lf", &val) != 1) {
112 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid format " 113 "in line: %s.\n", str_vec[entry].c_str());
119 if (str_tok[0] ==
"RecoWgt") {
121 }
else if (str_tok[0] ==
"SizeWgt") {
123 }
else if (str_tok[0] ==
"CharBigramsWgt") {
125 }
else if (str_tok[0] ==
"WordUnigramsWgt") {
127 }
else if (str_tok[0] ==
"MaxSegPerChar") {
129 }
else if (str_tok[0] ==
"BeamWidth") {
131 }
else if (str_tok[0] ==
"Classifier") {
132 if (str_tok[1] ==
"NN") {
134 }
else if (str_tok[1] ==
"HYBRID_NN") {
137 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid " 138 "classifier type in line: %s.\n", str_vec[entry].c_str());
141 }
else if (str_tok[0] ==
"FeatureType") {
142 if (str_tok[1] ==
"BMP") {
144 }
else if (str_tok[1] ==
"CHEBYSHEV") {
146 }
else if (str_tok[1] ==
"HYBRID") {
149 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid feature " 150 "type in line: %s.\n", str_vec[entry].c_str());
153 }
else if (str_tok[0] ==
"ConvGridSize") {
155 }
else if (str_tok[0] ==
"HistWindWid") {
157 }
else if (str_tok[0] ==
"MinConCompSize") {
159 }
else if (str_tok[0] ==
"MaxWordAspectRatio") {
161 }
else if (str_tok[0] ==
"MinSpaceHeightRatio") {
163 }
else if (str_tok[0] ==
"MaxSpaceHeightRatio") {
165 }
else if (str_tok[0] ==
"CombinerRunThresh") {
167 }
else if (str_tok[0] ==
"CombinerClassifierThresh") {
169 }
else if (str_tok[0] ==
"OODWgt") {
171 }
else if (str_tok[0] ==
"NumWgt") {
174 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): unknown parameter " 175 "in line: %s.\n", str_vec[entry].c_str());
185 FILE *params_file = fopen(file_name.c_str(),
"wb");
186 if (params_file == NULL) {
187 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Save): error opening file " 188 "%s for write.\n", file_name.c_str());
192 fprintf(params_file,
"RecoWgt=%.4f\n",
reco_wgt_);
193 fprintf(params_file,
"SizeWgt=%.4f\n",
size_wgt_);
197 fprintf(params_file,
"BeamWidth=%d\n",
beam_width_);
205 fprintf(params_file,
"CombinerClassifierThresh=%.4f\n",
207 fprintf(params_file,
"OODWgt=%.4f\n", ood_wgt_);
208 fprintf(params_file,
"NumWgt=%.4f\n", num_wgt_);
bool Save(string file_name)
type_classifer tp_classifier_
bool Load(string file_name)
double word_unigrams_wgt_
static bool ReadFileToString(const string &file_name, string *str)
double combiner_classifier_thresh_
static CubeTuningParams * Create(const string &data_file, const string &lang)
double min_space_height_ratio_
static void SplitStringUsing(const string &str, const string &delims, vector< string > *str_vec)
double combiner_run_thresh_
double max_word_aspect_ratio_
double max_space_height_ratio_