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