Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTetsuo Kiso <tetsuo-s@is.naist.jp>2012-02-17 04:16:10 +0400
committerTetsuo Kiso <tetsuo-s@is.naist.jp>2012-02-17 04:16:10 +0400
commita7666735b504493ee4e2013f06758e30c7ce9623 (patch)
tree8c884f178f219214c305d7c10566a660a109ba44 /mert/mert.cpp
parent6c003e544af928e3512399a60b5c8c0fb1f2df3f (diff)
Add error checking to setup 'to_optimize'.
mert will check whether the dimension and the number of fetures are equal.
Diffstat (limited to 'mert/mert.cpp')
-rwxr-xr-xmert/mert.cpp39
1 files changed, 24 insertions, 15 deletions
diff --git a/mert/mert.cpp b/mert/mert.cpp
index e47f2e6c1..195615542 100755
--- a/mert/mert.cpp
+++ b/mert/mert.cpp
@@ -358,22 +358,31 @@ int main(int argc, char **argv)
if (option.to_optimize_str.length() > 0) {
cerr << "Weights to optimize: " << option.to_optimize_str << endl;
- // Parse string to get weights to optimize, and set them as active
- string substring;
- int index;
- while (!option.to_optimize_str.empty()) {
- getNextPound(option.to_optimize_str, substring, ",");
- index = data.getFeatureIndex(substring);
- cerr << "FeatNameIndex:" << index << " to insert" << endl;
- //index = strtol(substring.c_str(), NULL, 10);
- if (index >= 0 && index < option.pdim) {
- to_optimize.push_back(index);
- } else {
- cerr << "Index " << index << " is out of bounds. Allowed indexes are [0," << option.pdim - 1 << "]." << endl;
-
- // Note: this is temporary bug fix.
- to_optimize.push_back(index);
+ // Parse the string to get weights to optimize, and set them as active.
+ vector<string> features;
+ Tokenize(option.to_optimize_str.c_str(), ',', &features);
+
+ if (option.pdim != static_cast<int>(features.size())) {
+ cerr << "Error: pdim and the specified number of features are not equal: "
+ << "pdim = " << option.pdim
+ << ", the number of features = " << features.size() << endl;
+ exit(1);
+ }
+
+ for (vector<string>::const_iterator it = features.begin();
+ it != features.end(); ++it) {
+ const int feature_index = data.getFeatureIndex(*it);
+
+ // Note: previous implementaion checked whether
+ // feature_index is less than option.pdim.
+ // However, it does not make sense when we optimize 'discrete' features,
+ // given by '-o' option like -o "d_0,lm_0,tm_2,tm_3,tm_4,w_0".
+ if (feature_index < 0) {
+ cerr << "Error: invalid feature index = " << feature_index << endl;
+ exit(1);
}
+ cerr << "FeatNameIndex: " << feature_index << " to insert" << endl;
+ to_optimize.push_back(feature_index);
}
} else {
//set all weights as active