58 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Create): unable to "
59 "allocate new tuning params object\n");
63 string tuning_params_file;
64 tuning_params_file = data_file_path +
lang;
65 tuning_params_file +=
".cube.params";
67 if (!obj->
Load(tuning_params_file)) {
68 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Create): unable to "
69 "load tuning parameters from %s\n", tuning_params_file.c_str());
83 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): unable to read "
84 "file %s\n", tuning_params_file.c_str());
89 vector<string> str_vec;
91 if (str_vec.size() < 8) {
92 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): number of rows "
93 "in parameter file is too low\n");
98 for (
int entry = 0; entry < str_vec.size(); entry++) {
100 vector<string> str_tok;
104 if (str_tok.size() != 2) {
105 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid format in "
106 "line: %s.\n", str_vec[entry].c_str());
111 char peekchar = (str_tok[1].c_str())[0];
112 if ((peekchar >=
'0' && peekchar <=
'9') ||
113 peekchar ==
'-' || peekchar ==
'+' ||
116 if (sscanf(str_tok[1].c_str(),
"%lf", &val) != 1) {
117 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid format "
118 "in line: %s.\n", str_vec[entry].c_str());
124 if (str_tok[0] ==
"RecoWgt") {
126 }
else if (str_tok[0] ==
"SizeWgt") {
128 }
else if (str_tok[0] ==
"CharBigramsWgt") {
130 }
else if (str_tok[0] ==
"WordUnigramsWgt") {
132 }
else if (str_tok[0] ==
"MaxSegPerChar") {
134 }
else if (str_tok[0] ==
"BeamWidth") {
136 }
else if (str_tok[0] ==
"Classifier") {
137 if (str_tok[1] ==
"NN") {
139 }
else if (str_tok[1] ==
"HYBRID_NN") {
142 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid "
143 "classifier type in line: %s.\n", str_vec[entry].c_str());
146 }
else if (str_tok[0] ==
"FeatureType") {
147 if (str_tok[1] ==
"BMP") {
149 }
else if (str_tok[1] ==
"CHEBYSHEV") {
151 }
else if (str_tok[1] ==
"HYBRID") {
154 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): invalid feature "
155 "type in line: %s.\n", str_vec[entry].c_str());
158 }
else if (str_tok[0] ==
"ConvGridSize") {
160 }
else if (str_tok[0] ==
"HistWindWid") {
162 }
else if (str_tok[0] ==
"MinConCompSize") {
164 }
else if (str_tok[0] ==
"MaxWordAspectRatio") {
166 }
else if (str_tok[0] ==
"MinSpaceHeightRatio") {
168 }
else if (str_tok[0] ==
"MaxSpaceHeightRatio") {
170 }
else if (str_tok[0] ==
"CombinerRunThresh") {
172 }
else if (str_tok[0] ==
"CombinerClassifierThresh") {
174 }
else if (str_tok[0] ==
"OODWgt") {
176 }
else if (str_tok[0] ==
"NumWgt") {
179 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Load): unknown parameter "
180 "in line: %s.\n", str_vec[entry].c_str());
190 FILE *params_file = fopen(file_name.c_str(),
"wb");
191 if (params_file ==
NULL) {
192 fprintf(stderr,
"Cube ERROR (CubeTuningParams::Save): error opening file "
193 "%s for write.\n", file_name.c_str());
197 fprintf(params_file,
"RecoWgt=%.4f\n",
reco_wgt_);
198 fprintf(params_file,
"SizeWgt=%.4f\n",
size_wgt_);
202 fprintf(params_file,
"BeamWidth=%d\n",
beam_width_);
210 fprintf(params_file,
"CombinerClassifierThresh=%.4f\n",
212 fprintf(params_file,
"OODWgt=%.4f\n", ood_wgt_);
213 fprintf(params_file,
"NumWgt=%.4f\n", num_wgt_);
double max_word_aspect_ratio_
static bool ReadFileToString(const string &file_name, string *str)
double min_space_height_ratio_
double word_unigrams_wgt_
static void SplitStringUsing(const string &str, const string &delims, vector< string > *str_vec)
bool Load(string file_name)
type_classifer tp_classifier_
double max_space_height_ratio_
double combiner_run_thresh_
bool Save(string file_name)
double combiner_classifier_thresh_
static CubeTuningParams * Create(const string &data_file, const string &lang)