mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-26 05:14:36 +03:00
add OutputSearchGraphSLF() to API framework
This commit is contained in:
parent
65c016667e
commit
6a77fd0ce3
@ -175,7 +175,6 @@ int main(int argc, char** argv)
|
||||
else {
|
||||
// pb
|
||||
task = new TranslationTask(source, *ioWrapper,
|
||||
staticData.GetOutputSearchGraphSLF(),
|
||||
hypergraphOutput);
|
||||
}
|
||||
|
||||
|
@ -55,6 +55,7 @@ public:
|
||||
virtual void OutputDetailedTreeFragmentsTranslationReport(OutputCollector *collector) const = 0;
|
||||
virtual void OutputWordGraph(OutputCollector *collector) const = 0;
|
||||
virtual void OutputSearchGraph(OutputCollector *collector) const = 0;
|
||||
virtual void OutputSearchGraphSLF() const = 0;
|
||||
|
||||
|
||||
};
|
||||
|
@ -161,6 +161,8 @@ public:
|
||||
void OutputWordGraph(OutputCollector *collector) const
|
||||
{}
|
||||
void OutputSearchGraph(OutputCollector *collector) const;
|
||||
void OutputSearchGraphSLF() const
|
||||
{}
|
||||
|
||||
};
|
||||
|
||||
|
@ -52,7 +52,8 @@ public:
|
||||
{}
|
||||
void OutputSearchGraph(OutputCollector *collector) const
|
||||
{}
|
||||
|
||||
void OutputSearchGraphSLF() const
|
||||
{}
|
||||
|
||||
|
||||
private:
|
||||
|
@ -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
|
||||
|
@ -198,6 +198,7 @@ public:
|
||||
{}
|
||||
void OutputWordGraph(OutputCollector *collector) const;
|
||||
void OutputSearchGraph(OutputCollector *collector) const;
|
||||
void OutputSearchGraphSLF() const;
|
||||
|
||||
};
|
||||
|
||||
|
@ -56,6 +56,8 @@ class Manager : public BaseManager
|
||||
{}
|
||||
void OutputSearchGraph(OutputCollector *collector) const
|
||||
{}
|
||||
void OutputSearchGraphSLF() const
|
||||
{}
|
||||
|
||||
private:
|
||||
void FindOovs(const PChart &, std::set<Word> &, std::size_t);
|
||||
|
@ -21,11 +21,9 @@ namespace Moses
|
||||
{
|
||||
|
||||
TranslationTask::TranslationTask(InputType* source, Moses::IOWrapper &ioWrapper,
|
||||
bool outputSearchGraphSLF,
|
||||
boost::shared_ptr<HypergraphOutput<Manager> > hypergraphOutput)
|
||||
: m_source(source)
|
||||
, m_ioWrapper(ioWrapper)
|
||||
, m_outputSearchGraphSLF(outputSearchGraphSLF)
|
||||
, m_hypergraphOutput(hypergraphOutput)
|
||||
, m_pbOrChart(1)
|
||||
{}
|
||||
@ -95,27 +93,7 @@ void TranslationTask::RunPb()
|
||||
// output search graph
|
||||
manager.OutputSearchGraph(m_ioWrapper.GetSearchGraphOutputCollector());
|
||||
|
||||
// Output search graph in HTK standard lattice format (SLF)
|
||||
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;
|
||||
}
|
||||
manager.OutputSearchGraphSLF();
|
||||
|
||||
// Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder
|
||||
if (m_hypergraphOutput.get()) {
|
||||
|
@ -27,7 +27,6 @@ class TranslationTask : public Moses::Task
|
||||
public:
|
||||
|
||||
TranslationTask(Moses::InputType* source, Moses::IOWrapper &ioWrapper,
|
||||
bool outputSearchGraphSLF,
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > hypergraphOutput);
|
||||
|
||||
TranslationTask(Moses::InputType *source, IOWrapper &ioWrapper,
|
||||
@ -45,7 +44,6 @@ private:
|
||||
Moses::InputType* m_source;
|
||||
Moses::IOWrapper &m_ioWrapper;
|
||||
|
||||
bool m_outputSearchGraphSLF;
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::Manager> > m_hypergraphOutput;
|
||||
boost::shared_ptr<Moses::HypergraphOutput<Moses::ChartManager> > m_hypergraphOutputChart;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user