mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
merge TranslationTask and IOWrapper. Move m_nBestOutputCollector into IOWrapper
This commit is contained in:
parent
8d0f74c6e4
commit
8611dc8cdf
@ -138,7 +138,6 @@ int main(int argc, char** argv)
|
||||
// initialize output streams
|
||||
// note: we can't just write to STDOUT or files
|
||||
// because multithreading may return sentences in shuffled order
|
||||
auto_ptr<OutputCollector> nbestCollector; // for n-best lists
|
||||
auto_ptr<OutputCollector> latticeSamplesCollector; //for lattice samples
|
||||
auto_ptr<ofstream> nbestOut;
|
||||
auto_ptr<ofstream> latticeSamplesOut;
|
||||
@ -148,7 +147,6 @@ int main(int argc, char** argv)
|
||||
if (nbestSize) {
|
||||
if (nbestFile == "-" || nbestFile == "/dev/stdout") {
|
||||
// nbest to stdout, no 1-best
|
||||
nbestCollector.reset(new OutputCollector());
|
||||
output1best = false;
|
||||
} else {
|
||||
// nbest to file, 1-best to stdout
|
||||
@ -157,7 +155,6 @@ int main(int argc, char** argv)
|
||||
TRACE_ERR("ERROR: Failed to open " << nbestFile << " for nbest lists" << endl);
|
||||
exit(1);
|
||||
}
|
||||
nbestCollector.reset(new OutputCollector(nbestOut.get()));
|
||||
}
|
||||
}
|
||||
size_t latticeSamplesSize = staticData.GetLatticeSamplesSize();
|
||||
@ -230,7 +227,6 @@ int main(int argc, char** argv)
|
||||
// set up task of translating one sentence
|
||||
TranslationTask* task =
|
||||
new TranslationTask(lineCount,source, *ioWrapper,
|
||||
nbestCollector.get(),
|
||||
latticeSamplesCollector.get(),
|
||||
wordGraphCollector.get(),
|
||||
searchGraphCollector.get(),
|
||||
|
@ -135,6 +135,11 @@ public:
|
||||
Moses::OutputCollector *GetSingleBestOutputCollector() {
|
||||
return m_singleBestOutputCollector;
|
||||
}
|
||||
|
||||
Moses::OutputCollector *GetNBestOutputCollector() {
|
||||
return m_nBestOutputCollector;
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
IOWrapper *GetIOWrapper(const Moses::StaticData &staticData);
|
||||
|
@ -16,7 +16,6 @@ namespace MosesCmd
|
||||
{
|
||||
|
||||
TranslationTask::TranslationTask(size_t lineNumber, InputType* source, MosesCmd::IOWrapper &ioWrapper,
|
||||
OutputCollector* nbestCollector,
|
||||
OutputCollector* latticeSamplesCollector,
|
||||
OutputCollector* wordGraphCollector, OutputCollector* searchGraphCollector,
|
||||
OutputCollector* detailedTranslationCollector,
|
||||
@ -26,7 +25,6 @@ TranslationTask::TranslationTask(size_t lineNumber, InputType* source, MosesCmd:
|
||||
boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput) :
|
||||
m_source(source), m_lineNumber(lineNumber),
|
||||
m_ioWrapper(ioWrapper),
|
||||
m_nbestCollector(nbestCollector),
|
||||
m_latticeSamplesCollector(latticeSamplesCollector),
|
||||
m_wordGraphCollector(wordGraphCollector), m_searchGraphCollector(searchGraphCollector),
|
||||
m_detailedTranslationCollector(detailedTranslationCollector),
|
||||
@ -196,14 +194,14 @@ void TranslationTask::Run() {
|
||||
|
||||
// lattice MBR
|
||||
if (staticData.UseLatticeMBR()) {
|
||||
if (m_nbestCollector) {
|
||||
if (m_ioWrapper.GetNBestOutputCollector()) {
|
||||
//lattice mbr nbest
|
||||
vector<LatticeMBRSolution> solutions;
|
||||
size_t n = min(nBestSize, staticData.GetNBestSize());
|
||||
getLatticeMBRNBest(manager,nBestList,solutions,n);
|
||||
ostringstream out;
|
||||
OutputLatticeMBRNBest(out, solutions,m_lineNumber);
|
||||
m_nbestCollector->Write(m_lineNumber, out.str());
|
||||
m_ioWrapper.GetNBestOutputCollector()->Write(m_lineNumber, out.str());
|
||||
} else {
|
||||
//Lattice MBR decoding
|
||||
vector<Word> mbrBestHypo = doLatticeMBR(manager,nBestList);
|
||||
@ -250,13 +248,13 @@ void TranslationTask::Run() {
|
||||
additionalReportingTime.start();
|
||||
|
||||
// output n-best list
|
||||
if (m_nbestCollector && !staticData.UseLatticeMBR()) {
|
||||
if (m_ioWrapper.GetNBestOutputCollector() && !staticData.UseLatticeMBR()) {
|
||||
TrellisPathList nBestList;
|
||||
ostringstream out;
|
||||
manager.CalcNBest(staticData.GetNBestSize(), nBestList,staticData.GetDistinctNBest());
|
||||
OutputNBest(out, nBestList, staticData.GetOutputFactorOrder(), m_lineNumber,
|
||||
staticData.GetReportSegmentation());
|
||||
m_nbestCollector->Write(m_lineNumber, out.str());
|
||||
m_ioWrapper.GetNBestOutputCollector()->Write(m_lineNumber, out.str());
|
||||
}
|
||||
|
||||
//lattice samples
|
||||
|
@ -27,7 +27,6 @@ class TranslationTask : public Moses::Task
|
||||
public:
|
||||
|
||||
TranslationTask(size_t lineNumber, Moses::InputType* source, MosesCmd::IOWrapper &ioWrapper,
|
||||
Moses::OutputCollector* nbestCollector,
|
||||
Moses::OutputCollector* latticeSamplesCollector,
|
||||
Moses::OutputCollector* wordGraphCollector, Moses::OutputCollector* searchGraphCollector,
|
||||
Moses::OutputCollector* detailedTranslationCollector,
|
||||
@ -48,7 +47,6 @@ private:
|
||||
size_t m_lineNumber;
|
||||
MosesCmd::IOWrapper &m_ioWrapper;
|
||||
|
||||
Moses::OutputCollector* m_nbestCollector;
|
||||
Moses::OutputCollector* m_latticeSamplesCollector;
|
||||
Moses::OutputCollector* m_wordGraphCollector;
|
||||
Moses::OutputCollector* m_searchGraphCollector;
|
||||
|
Loading…
Reference in New Issue
Block a user