File size: 1,471 Bytes
158b61b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
#include "tool.h"

#include <cstdlib>
#include <iostream>
#include <sstream>

#include <boost/program_options/cmdline.hpp>

namespace MosesTraining {
namespace Syntax {

int Tool::MosesOptionStyle() {
  namespace cls = boost::program_options::command_line_style;
  return cls::allow_long | cls::long_allow_adjacent | cls::long_allow_next;
}

void Tool::Warn(const std::string &msg) const {
  std::cerr << name_ << ": warning: " << msg << std::endl;
}

void Tool::Error(const std::string &msg) const {
  std::cerr << name_ << ": error: " << msg << std::endl;
  std::exit(1);
}

void Tool::OpenInputFileOrDie(const std::string &filename,
                              std::ifstream &stream) {
  stream.open(filename.c_str());
  if (!stream) {
    std::ostringstream msg;
    msg << "failed to open input file: " << filename;
    Error(msg.str());
  }
}

void Tool::OpenOutputFileOrDie(const std::string &filename,
                               std::ofstream &stream) {
  stream.open(filename.c_str());
  if (!stream) {
    std::ostringstream msg;
    msg << "failed to open output file: " << filename;
    Error(msg.str());
  }
}

void Tool::OpenOutputFileOrDie(const std::string &filename,
                               Moses::OutputFileStream &stream) {
  bool ret = stream.Open(filename);
  if (!ret) {
    std::ostringstream msg;
    msg << "failed to open output file: " << filename;
    Error(msg.str());
  }
}

}  // namespace Syntax
}  // namespace MosesTraining