Allow hypergraph output to be in plain text, gzip, or bzip2.

The output-search-graph-hypergraph flag now takes two params:

* The first param must be "none", "gzip", or "bzip2"
* The second param is the hypergraph directory,
  which must already exist
This commit is contained in:
Lane Schwartz 2013-03-21 15:19:31 -04:00
parent 22c77f7331
commit 28c980d58e
2 changed files with 19 additions and 6 deletions

View File

@ -1,4 +1,4 @@
alias deps : IOWrapper.cpp mbr.cpp LatticeMBR.cpp TranslationAnalysis.cpp ../moses//moses ;
alias deps : IOWrapper.cpp mbr.cpp LatticeMBR.cpp TranslationAnalysis.cpp ..//z ..//boost_iostreams ../moses//moses ;
exe moses : Main.cpp deps ;
exe lmbrgrid : LatticeMBRGrid.cpp deps ;

View File

@ -23,6 +23,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
* Moses main, for single-threaded and multi-threaded.
**/
#include <boost/iostreams/device/file.hpp>
#include <boost/iostreams/filter/bzip2.hpp>
#include <boost/iostreams/filter/gzip.hpp>
#include <boost/iostreams/filtering_stream.hpp>
#include <exception>
#include <fstream>
#include <sstream>
@ -167,10 +172,18 @@ public:
// Output search graph in hypergraph format for Kenneth Heafield's lazy hypergraph decoder
if (m_outputSearchGraphHypergraph) {
stringstream fileName;
fileName << staticData.GetParam("output-search-graph-hypergraph")[0] << "/" << m_lineNumber;
std::ofstream *file = new std::ofstream;
file->open(fileName.str().c_str());
if (file->is_open() && file->good()) {
fileName << staticData.GetParam("output-search-graph-hypergraph")[1] << "/" << m_lineNumber;
boost::iostreams::filtering_ostream *file = new boost::iostreams::filtering_ostream;
// file->open(fileName.str().c_str());
string compression = staticData.GetParam("output-search-graph-hypergraph")[0];
if ( compression == "gzip" || compression == "gz" ) {
file->push( boost::iostreams::gzip_compressor() );
} else if ( compression == "bzip2" || compression == "bz2" ) {
file->push( boost::iostreams::bzip2_compressor() );
}
file->push( boost::iostreams::file_sink(fileName.str(), ios_base::out) );
// if (file->is_open() && file->good()) {
if (file->is_complete() && file->good()) {
// ostringstream out;
// fix(out,PRECISION);
fix(*file,PRECISION);
@ -180,7 +193,7 @@ public:
} else {
TRACE_ERR("Cannot output hypergraph for line " << m_lineNumber << " because the output file is not open or not ready for writing" << std::endl);
}
file -> close();
file -> pop();
delete file;
}