add OutputSearchGraphSLF() to API framework

This commit is contained in:
Hieu Hoang 2014-12-05 19:40:51 +00:00
parent 65c016667e
commit 6a77fd0ce3
9 changed files with 39 additions and 27 deletions

View File

@ -175,7 +175,6 @@ int main(int argc, char** argv)
else { else {
// pb // pb
task = new TranslationTask(source, *ioWrapper, task = new TranslationTask(source, *ioWrapper,
staticData.GetOutputSearchGraphSLF(),
hypergraphOutput); hypergraphOutput);
} }

View File

@ -55,6 +55,7 @@ public:
virtual void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const = 0; virtual void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const = 0;
virtual void OutputWordGraph(OutputCollector *collector) const = 0; virtual void OutputWordGraph(OutputCollector *collector) const = 0;
virtual void OutputSearchGraph(OutputCollector *collector) const = 0; virtual void OutputSearchGraph(OutputCollector *collector) const = 0;
virtual void OutputSearchGraphSLF() const = 0;
}; };

View File

@ -161,6 +161,8 @@ public:
void OutputWordGraph(OutputCollector *collector) const void OutputWordGraph(OutputCollector *collector) const
{} {}
void OutputSearchGraph(OutputCollector *collector) const; void OutputSearchGraph(OutputCollector *collector) const;
void OutputSearchGraphSLF() const
{}
}; };

View File

@ -52,7 +52,8 @@ public:
{} {}
void OutputSearchGraph(OutputCollector *collector) const void OutputSearchGraph(OutputCollector *collector) const
{} {}
void OutputSearchGraphSLF() const
{}
private: private:

View File

@ -1780,4 +1780,34 @@ void Manager::OutputSearchGraph(OutputCollector *collector) const
} }
void Manager::OutputSearchGraphSLF() const
{
const StaticData &staticData = StaticData::Instance();
long translationId = m_source.GetTranslationId();
// Output search graph in HTK standard lattice format (SLF)
bool slf = staticData.GetOutputSearchGraphSLF();
if (slf) {
stringstream fileName;
string dir;
staticData.GetParameter().SetParameter<string>(dir, "output-search-graph-slf", "");
fileName << dir << "/" << translationId << ".slf";
ofstream *file = new ofstream;
file->open(fileName.str().c_str());
if (file->is_open() && file->good()) {
ostringstream out;
FixPrecision(out,PRECISION);
OutputSearchGraphAsSLF(translationId, out);
*file << out.str();
file -> flush();
} else {
TRACE_ERR("Cannot output HTK standard lattice for line " << translationId << " because the output file is not open or not ready for writing" << endl);
}
delete file;
}
} }
} // namespace

View File

@ -198,6 +198,7 @@ public:
{} {}
void OutputWordGraph(OutputCollector *collector) const; void OutputWordGraph(OutputCollector *collector) const;
void OutputSearchGraph(OutputCollector *collector) const; void OutputSearchGraph(OutputCollector *collector) const;
void OutputSearchGraphSLF() const;
}; };

View File

@ -56,6 +56,8 @@ class Manager : public BaseManager
{} {}
void OutputSearchGraph(OutputCollector *collector) const void OutputSearchGraph(OutputCollector *collector) const
{} {}
void OutputSearchGraphSLF() const
{}
private: private:
void FindOovs(const PChart &, std::set<Word> &, std::size_t); void FindOovs(const PChart &, std::set<Word> &, std::size_t);

View File

@ -21,11 +21,9 @@ namespace Moses
{ {
TranslationTask::TranslationTask(InputType* source, Moses::IOWrapper &ioWrapper, TranslationTask::TranslationTask(InputType* source, Moses::IOWrapper &ioWrapper,
bool outputSearchGraphSLF,
boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput) boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput)
: m_source(source) : m_source(source)
, m_ioWrapper(ioWrapper) , m_ioWrapper(ioWrapper)
, m_outputSearchGraphSLF(outputSearchGraphSLF)
, m_hypergraphOutput(hypergraphOutput) , m_hypergraphOutput(hypergraphOutput)
, m_pbOrChart(1) , m_pbOrChart(1)
{} {}
@ -95,27 +93,7 @@ void TranslationTask::RunPb()
// output search graph // output search graph
manager.OutputSearchGraph(m_ioWrapper.GetSearchGraphOutputCollector()); manager.OutputSearchGraph(m_ioWrapper.GetSearchGraphOutputCollector());
// Output search graph in HTK standard lattice format (SLF) manager.OutputSearchGraphSLF();
if (m_outputSearchGraphSLF) {
stringstream fileName;
string dir;
staticData.GetParameter().SetParameter<string>(dir, "output-search-graph-slf", "");
fileName << dir << "/" << m_source->GetTranslationId() << ".slf";
ofstream *file = new ofstream;
file->open(fileName.str().c_str());
if (file->is_open() && file->good()) {
ostringstream out;
FixPrecision(out,PRECISION);
manager.OutputSearchGraphAsSLF(m_source->GetTranslationId(), out);
*file << out.str();
file -> flush();
} else {
TRACE_ERR("Cannot output HTK standard lattice for line " << m_source->GetTranslationId() << " because the output file is not open or not ready for writing" << endl);
}
delete file;
}
// Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder // Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder
if (m_hypergraphOutput.get()) { if (m_hypergraphOutput.get()) {

View File

@ -27,7 +27,6 @@ class TranslationTask : public Moses::Task
public: public:
TranslationTask(Moses::InputType* source, Moses::IOWrapper &ioWrapper, TranslationTask(Moses::InputType* source, Moses::IOWrapper &ioWrapper,
bool outputSearchGraphSLF,
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > hypergraphOutput); boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > hypergraphOutput);
TranslationTask(Moses::InputType *source, IOWrapper &ioWrapper, TranslationTask(Moses::InputType *source, IOWrapper &ioWrapper,
@ -45,7 +44,6 @@ private:
Moses::InputType* m_source; Moses::InputType* m_source;
Moses::IOWrapper &m_ioWrapper; Moses::IOWrapper &m_ioWrapper;
bool m_outputSearchGraphSLF;
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > m_hypergraphOutput; boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > m_hypergraphOutput;
boost::shared_ptr<Moses::HypergraphOutput<Moses::ChartManager> > m_hypergraphOutputChart; boost::shared_ptr<Moses::HypergraphOutput<Moses::ChartManager> > m_hypergraphOutputChart;