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:
authorUlrich Germann <Ulrich.Germann@gmail.com>2015-08-07 05:01:24 +0300
committerUlrich Germann <Ulrich.Germann@gmail.com>2015-08-07 05:01:24 +0300
commitd11906abcdc43c6e5d41ff75d99b91c654a49daf (patch)
tree00b7641b1c47c25ba15913bd646ce1d678e885ce /moses/IOWrapper.cpp
parent4ad6f2a5a6fc860bd889edff23e9b05c1a38a83e (diff)
Code simplification in IOWrapper.
Diffstat (limited to 'moses/IOWrapper.cpp')
-rw-r--r--moses/IOWrapper.cpp141
1 files changed, 43 insertions, 98 deletions
diff --git a/moses/IOWrapper.cpp b/moses/IOWrapper.cpp
index b36fd0644..eabf0c8c2 100644
--- a/moses/IOWrapper.cpp
+++ b/moses/IOWrapper.cpp
@@ -79,12 +79,12 @@ namespace Moses
IOWrapper::IOWrapper()
: m_nBestStream(NULL)
- , m_outputWordGraphStream(NULL)
- , m_outputSearchGraphStream(NULL)
- , m_detailedTranslationReportingStream(NULL)
- , m_unknownsStream(NULL)
- , m_alignmentInfoStream(NULL)
- , m_latticeSamplesStream(NULL)
+ // , m_outputWordGraphStream(NULL)
+ // , m_outputSearchGraphStream(NULL)
+ // , m_detailedTranslationReportingStream(NULL)
+ // , m_unknownsStream(NULL)
+ // , m_alignmentInfoStream(NULL)
+ // , m_latticeSamplesStream(NULL)
, m_surpressSingleBestOutput(false)
, m_look_ahead(0)
, m_look_back(0)
@@ -94,6 +94,7 @@ IOWrapper::IOWrapper()
, spe_aln(NULL)
{
const StaticData &staticData = StaticData::Instance();
+ Parameter const& P = staticData.GetParameter();
// context buffering for context-sensitive decoding
m_look_ahead = staticData.options().context.look_ahead;
@@ -122,98 +123,41 @@ IOWrapper::IOWrapper()
}
if (nBestSize > 0) {
- if (nBestFilePath == "-" || nBestFilePath == "/dev/stdout") {
- m_nBestStream = &std::cout;
- m_nBestOutputCollector.reset(new Moses::OutputCollector(&std::cout));
+ m_nBestOutputCollector.reset(new Moses::OutputCollector(nBestFilePath));
+ if (m_nBestOutputCollector->OutputIsCout()) {
m_surpressSingleBestOutput = true;
- } else {
- std::ofstream *file = new std::ofstream;
- file->open(nBestFilePath.c_str());
- m_nBestStream = file;
-
- m_nBestOutputCollector.reset(new Moses::OutputCollector(file));
- //m_nBestOutputCollector->HoldOutputStream();
- }
- }
-
- // search graph output
- if (staticData.GetOutputSearchGraph()) {
- string fileName;
- if (staticData.GetOutputSearchGraphExtended()) {
- staticData.GetParameter().SetParameter<string>(fileName, "output-search-graph-extended", "");
- } else {
- staticData.GetParameter().SetParameter<string>(fileName, "output-search-graph", "");
}
- std::ofstream *file = new std::ofstream;
- m_outputSearchGraphStream = file;
- file->open(fileName.c_str());
- }
-
- if (!staticData.GetOutputUnknownsFile().empty()) {
- m_unknownsStream = new std::ofstream(staticData.GetOutputUnknownsFile().c_str());
- m_unknownsCollector.reset(new Moses::OutputCollector(m_unknownsStream));
- UTIL_THROW_IF2(!m_unknownsStream->good(),
- "File for unknowns words could not be opened: " <<
- staticData.GetOutputUnknownsFile());
- }
-
- if (!staticData.GetAlignmentOutputFile().empty()) {
- m_alignmentInfoStream = new std::ofstream(staticData.GetAlignmentOutputFile().c_str());
- m_alignmentInfoCollector.reset(new Moses::OutputCollector(m_alignmentInfoStream));
- UTIL_THROW_IF2(!m_alignmentInfoStream->good(),
- "File for alignment output could not be opened: " << staticData.GetAlignmentOutputFile());
- }
-
- if (staticData.GetOutputSearchGraph()) {
- string fileName;
- staticData.GetParameter().SetParameter<string>(fileName, "output-search-graph", "");
-
- std::ofstream *file = new std::ofstream;
- m_outputSearchGraphStream = file;
- file->open(fileName.c_str());
- m_searchGraphOutputCollector.reset(new Moses::OutputCollector(m_outputSearchGraphStream));
- }
-
- // detailed translation reporting
- if (staticData.IsDetailedTranslationReportingEnabled()) {
- const std::string &path = staticData.GetDetailedTranslationReportingFilePath();
- m_detailedTranslationReportingStream = new std::ofstream(path.c_str());
- m_detailedTranslationCollector.reset(new Moses::OutputCollector(m_detailedTranslationReportingStream));
- }
-
- if (staticData.IsDetailedTreeFragmentsTranslationReportingEnabled()) {
- const std::string &path = staticData.GetDetailedTreeFragmentsTranslationReportingFilePath();
- m_detailedTreeFragmentsTranslationReportingStream = new std::ofstream(path.c_str());
- m_detailTreeFragmentsOutputCollector.reset(new Moses::OutputCollector(m_detailedTreeFragmentsTranslationReportingStream));
- }
-
- // wordgraph output
- if (staticData.GetOutputWordGraph()) {
- string fileName;
- staticData.GetParameter().SetParameter<string>(fileName, "output-word-graph", "");
-
- std::ofstream *file = new std::ofstream;
- m_outputWordGraphStream = file;
- file->open(fileName.c_str());
- m_wordGraphCollector.reset(new OutputCollector(m_outputWordGraphStream));
}
+ std::string path;
+ P.SetParameter<std::string>(path, "output-search-graph-extended", "");
+ if (!path.size()) P.SetParameter<std::string>(path, "output-search-graph", "");
+ if (path.size()) m_searchGraphOutputCollector.reset(new OutputCollector(path));
+
+ P.SetParameter<std::string>(path, "output-unknowns", "");
+ if (path.size()) m_unknownsCollector.reset(new OutputCollector(path));
+
+ P.SetParameter<std::string>(path, "alignment-output-file", "");
+ if (path.size()) m_alignmentInfoCollector.reset(new OutputCollector(path));
+
+ P.SetParameter<string>(path, "translation-details", "");
+ if (path.size()) m_detailedTranslationCollector.reset(new OutputCollector(path));
+
+ P.SetParameter<string>(path, "tree-translation-details", "");
+ if (path.size()) m_detailTreeFragmentsOutputCollector.reset(new OutputCollector(path));
+
+ P.SetParameter<string>(path, "output-word-graph", "");
+ if (path.size()) m_wordGraphCollector.reset(new OutputCollector(path));
+
size_t latticeSamplesSize = staticData.GetLatticeSamplesSize();
string latticeSamplesFile = staticData.GetLatticeSamplesFilePath();
if (latticeSamplesSize) {
- if (latticeSamplesFile == "-" || latticeSamplesFile == "/dev/stdout") {
- m_latticeSamplesCollector.reset(new OutputCollector());
+ m_latticeSamplesCollector.reset(new OutputCollector(latticeSamplesFile));
+ if (m_latticeSamplesCollector->OutputIsCout()) {
m_surpressSingleBestOutput = true;
- } else {
- m_latticeSamplesStream = new ofstream(latticeSamplesFile.c_str());
- if (!m_latticeSamplesStream->good()) {
- TRACE_ERR("ERROR: Failed to open " << latticeSamplesFile << " for lattice samples" << endl);
- exit(1);
- }
- m_latticeSamplesCollector.reset(new OutputCollector(m_latticeSamplesStream));
}
}
-
+
if (!m_surpressSingleBestOutput) {
m_singleBestOutputCollector.reset(new Moses::OutputCollector(&std::cout));
}
@@ -236,6 +180,7 @@ IOWrapper::IOWrapper()
<< "' for hypergraph output!");
fmt += string("%d.") + extension;
+ // input streams for simulated post-editing
if (staticData.GetParameter().GetParam("spe-src")) {
spe_src = new ifstream(staticData.GetParameter().GetParam("spe-src")->at(0).c_str());
spe_trg = new ifstream(staticData.GetParameter().GetParam("spe-trg")->at(0).c_str());
@@ -247,17 +192,17 @@ IOWrapper::~IOWrapper()
{
if (m_inputFile != NULL)
delete m_inputFile;
- if (m_nBestStream != NULL && !m_surpressSingleBestOutput) {
+ // if (m_nBestStream != NULL && !m_surpressSingleBestOutput) {
// outputting n-best to file, rather than stdout. need to close file and delete obj
- delete m_nBestStream;
- }
-
- delete m_detailedTranslationReportingStream;
- delete m_alignmentInfoStream;
- delete m_unknownsStream;
- delete m_outputSearchGraphStream;
- delete m_outputWordGraphStream;
- delete m_latticeSamplesStream;
+ // delete m_nBestStream;
+ // }
+
+ // delete m_detailedTranslationReportingStream;
+ // delete m_alignmentInfoStream;
+ // delete m_unknownsStream;
+ // delete m_outputSearchGraphStream;
+ // delete m_outputWordGraphStream;
+ // delete m_latticeSamplesStream;
}
// InputType*