From 380f550cf3d2b1150a6868ed6725ce55c1687070 Mon Sep 17 00:00:00 2001 From: Tetsuo Kiso Date: Wed, 1 Feb 2012 16:59:48 +0900 Subject: Create a function to save final weights to a file. --- mert/mert.cpp | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) (limited to 'mert/mert.cpp') diff --git a/mert/mert.cpp b/mert/mert.cpp index 335b5c7ea..2384f1ede 100755 --- a/mert/mert.cpp +++ b/mert/mert.cpp @@ -80,6 +80,19 @@ class OptimizationTask : public Moses::Task { statscore_t m_score; }; +bool WriteFinalWeights(const char* filename, const Point& point) { + ofstream ofs(filename); + if (!ofs) { + cerr << "Cannot open " << filename << endl; + return false; + } + + ofs << point << endl; + + return true; +} + + void usage(int ret) { cerr << "usage: mert -d (mandatory)" << endl; @@ -473,8 +486,10 @@ int main(int argc, char **argv) } cerr << "Best point: " << finalP << " => " << final << endl; - ofstream res(kOutputFile); - res << finalP << endl; + + if (!WriteFinalWeights(kOutputFile, finalP)) { + cerr << "Warning: Failed to write the final point" << endl; + } for (size_t i = 0; i < allTasks.size(); ++i) { allTasks[i][0]->resetOptimizer(); -- cgit v1.2.3