2012-08-03 18:38:45 +04:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2012-08-11 03:03:10 +04:00
|
|
|
#ifdef WITH_THREADS
|
|
|
|
#include <boost/thread/thread.hpp>
|
|
|
|
#endif
|
|
|
|
|
2012-11-30 13:49:36 +04:00
|
|
|
#include "moses/TranslationModel/CompactPT/LexicalReorderingTableCreator.h"
|
2012-08-03 18:38:45 +04:00
|
|
|
|
2013-01-23 01:12:08 +04:00
|
|
|
#include "util/file.hh"
|
|
|
|
|
2012-08-03 18:38:45 +04:00
|
|
|
using namespace Moses;
|
|
|
|
|
|
|
|
void printHelp(char **argv)
|
|
|
|
{
|
|
|
|
std::cerr << "Usage " << argv[0] << ":\n"
|
2012-08-07 16:18:07 +04:00
|
|
|
" options: \n"
|
2012-08-03 18:38:45 +04:00
|
|
|
"\t-in string -- input table file name\n"
|
|
|
|
"\t-out string -- prefix of binary table file\n"
|
2013-01-23 00:11:02 +04:00
|
|
|
"\t-T string -- path to temporary directory (uses /tmp by default)\n"
|
2012-08-03 19:45:00 +04:00
|
|
|
#ifdef WITH_THREADS
|
2012-08-11 03:03:10 +04:00
|
|
|
"\t-threads int|all -- number of threads used for conversion\n"
|
2013-05-29 21:16:15 +04:00
|
|
|
#endif
|
2012-08-07 16:18:07 +04:00
|
|
|
"\n advanced:\n"
|
2012-08-03 18:38:45 +04:00
|
|
|
"\t-landmark int -- use landmark phrase every 2^n phrases\n"
|
|
|
|
"\t-fingerprint int -- number of bits used for phrase fingerprints\n"
|
|
|
|
"\t-join-scores -- single set of Huffman codes for score components\n"
|
|
|
|
"\t-quantize int -- maximum number of scores per score component\n"
|
2012-08-03 19:45:00 +04:00
|
|
|
"\n"
|
2012-08-07 16:18:07 +04:00
|
|
|
" For more information see: http://www.statmt.org/moses/?n=Moses.AdvancedFeatures#ntoc6\n\n"
|
|
|
|
" If you use this please cite:\n\n"
|
2012-08-04 17:39:30 +04:00
|
|
|
" @article { junczys_pbml98_2012,\n"
|
2012-08-03 19:02:47 +04:00
|
|
|
" author = { Marcin Junczys-Dowmunt },\n"
|
|
|
|
" title = { Phrasal Rank-Encoding: Exploiting Phrase Redundancy and\n"
|
|
|
|
" Translational Relations for Phrase Table Compression },\n"
|
|
|
|
" journal = { The Prague Bulletin of Mathematical Linguistics },\n"
|
|
|
|
" volume = { 98 },\n"
|
|
|
|
" year = { 2012 },\n"
|
|
|
|
" note = { Proceedings of the MT Marathon 2012, Edinburgh },\n"
|
2012-08-06 17:58:13 +04:00
|
|
|
" }\n\n"
|
|
|
|
" Acknowledgments: Part of this research was carried out at and funded by\n"
|
|
|
|
" the World Intellectual Property Organization (WIPO) in Geneva.\n\n";
|
2012-08-03 18:38:45 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-08-03 18:38:45 +04:00
|
|
|
std::string inFilePath;
|
|
|
|
std::string outFilePath("out");
|
2013-01-23 00:11:02 +04:00
|
|
|
std::string tempfilePath;
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-08-03 18:38:45 +04:00
|
|
|
size_t orderBits = 10;
|
|
|
|
size_t fingerPrintBits = 16;
|
|
|
|
bool multipleScoreTrees = true;
|
|
|
|
size_t quantize = 0;
|
|
|
|
|
|
|
|
#ifdef WITH_THREADS
|
2012-08-10 15:22:40 +04:00
|
|
|
size_t threads = 1;
|
2013-05-29 21:16:15 +04:00
|
|
|
#endif
|
2012-08-03 18:38:45 +04:00
|
|
|
|
2013-05-29 21:16:15 +04:00
|
|
|
if(1 >= argc) {
|
2012-08-03 18:38:45 +04:00
|
|
|
printHelp(argv);
|
|
|
|
return 1;
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
for(int i = 1; i < argc; ++i) {
|
2012-08-03 18:38:45 +04:00
|
|
|
std::string arg(argv[i]);
|
2013-05-29 21:16:15 +04:00
|
|
|
if("-in" == arg && i+1 < argc) {
|
2012-08-03 18:38:45 +04:00
|
|
|
++i;
|
|
|
|
inFilePath = argv[i];
|
2013-05-29 21:16:15 +04:00
|
|
|
} else if("-out" == arg && i+1 < argc) {
|
2012-08-03 18:38:45 +04:00
|
|
|
++i;
|
|
|
|
outFilePath = argv[i];
|
2013-05-29 21:16:15 +04:00
|
|
|
} else if("-T" == arg && i+1 < argc) {
|
2013-01-23 00:11:02 +04:00
|
|
|
++i;
|
|
|
|
tempfilePath = argv[i];
|
2013-01-23 01:12:08 +04:00
|
|
|
util::NormalizeTempPrefix(tempfilePath);
|
2013-05-29 21:16:15 +04:00
|
|
|
} else if("-landmark" == arg && i+1 < argc) {
|
2012-08-03 18:38:45 +04:00
|
|
|
++i;
|
|
|
|
orderBits = atoi(argv[i]);
|
2013-05-29 21:16:15 +04:00
|
|
|
} else if("-fingerprint" == arg && i+1 < argc) {
|
2012-08-03 18:38:45 +04:00
|
|
|
++i;
|
|
|
|
fingerPrintBits = atoi(argv[i]);
|
2013-05-29 21:16:15 +04:00
|
|
|
} else if("-join-scores" == arg) {
|
2012-08-03 18:38:45 +04:00
|
|
|
multipleScoreTrees = false;
|
2013-05-29 21:16:15 +04:00
|
|
|
} else if("-quantize" == arg && i+1 < argc) {
|
2012-08-03 18:38:45 +04:00
|
|
|
++i;
|
|
|
|
quantize = atoi(argv[i]);
|
2013-05-29 21:16:15 +04:00
|
|
|
} else if("-threads" == arg && i+1 < argc) {
|
2012-08-03 18:38:45 +04:00
|
|
|
#ifdef WITH_THREADS
|
|
|
|
++i;
|
2012-08-11 03:03:10 +04:00
|
|
|
if(std::string(argv[i]) == "all") {
|
|
|
|
threads = boost::thread::hardware_concurrency();
|
|
|
|
if(!threads) {
|
|
|
|
std::cerr << "Could not determine number of hardware threads, setting to 1" << std::endl;
|
|
|
|
threads = 1;
|
2013-05-29 21:16:15 +04:00
|
|
|
}
|
|
|
|
} else
|
2012-08-11 03:03:10 +04:00
|
|
|
threads = atoi(argv[i]);
|
2012-08-03 18:38:45 +04:00
|
|
|
#else
|
|
|
|
std::cerr << "Thread support not compiled in" << std::endl;
|
|
|
|
exit(1);
|
|
|
|
#endif
|
2013-05-29 21:16:15 +04:00
|
|
|
} else {
|
2012-08-03 18:38:45 +04:00
|
|
|
//somethings wrong... print help
|
|
|
|
printHelp(argv);
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
2013-05-29 21:16:15 +04:00
|
|
|
|
2012-08-03 18:38:45 +04:00
|
|
|
if(outFilePath.rfind(".minlexr") != outFilePath.size() - 8)
|
|
|
|
outFilePath += ".minlexr";
|
|
|
|
|
|
|
|
LexicalReorderingTableCreator(
|
2013-01-23 00:11:02 +04:00
|
|
|
inFilePath, outFilePath, tempfilePath,
|
2012-08-03 18:38:45 +04:00
|
|
|
orderBits, fingerPrintBits,
|
|
|
|
multipleScoreTrees, quantize
|
|
|
|
#ifdef WITH_THREADS
|
|
|
|
, threads
|
2013-05-29 21:16:15 +04:00
|
|
|
#endif
|
2012-08-03 18:38:45 +04:00
|
|
|
);
|
|
|
|
}
|