2007-03-15 15:43:27 +03:00
|
|
|
#include <iostream>
|
|
|
|
#include <string>
|
|
|
|
|
2012-11-14 18:18:53 +04:00
|
|
|
#include "moses/Phrase.h"
|
|
|
|
#include "moses/FactorCollection.h"
|
|
|
|
#include "moses/Timer.h"
|
|
|
|
#include "moses/InputFileStream.h"
|
2013-08-30 20:45:56 +04:00
|
|
|
#include "moses/FF/LexicalReordering/LexicalReorderingTable.h"
|
2007-03-15 15:43:27 +03:00
|
|
|
|
2008-10-09 04:20:39 +04:00
|
|
|
using namespace Moses;
|
|
|
|
|
2007-03-15 15:43:27 +03:00
|
|
|
Timer timer;
|
|
|
|
|
2011-02-24 16:57:11 +03:00
|
|
|
void printHelp()
|
|
|
|
{
|
2007-03-15 15:43:27 +03:00
|
|
|
std::cerr << "Usage:\n"
|
2011-02-24 16:57:11 +03:00
|
|
|
"options: \n"
|
|
|
|
"\t-table file -- input table file name\n"
|
|
|
|
"\t-f string -- f query phrase\n"
|
|
|
|
"\t-e string -- e query phrase\n"
|
|
|
|
"\t-c string -- context query phrase\n"
|
|
|
|
"\n";
|
2007-03-15 15:43:27 +03:00
|
|
|
}
|
|
|
|
|
2011-02-24 16:57:11 +03:00
|
|
|
std::ostream& operator<<(std::ostream& o, Scores s)
|
|
|
|
{
|
2012-05-10 16:48:51 +04:00
|
|
|
for(size_t i = 0; i < s.size(); ++i) {
|
2011-02-24 16:57:11 +03:00
|
|
|
o << s[i] << " ";
|
2007-03-15 15:43:27 +03:00
|
|
|
}
|
|
|
|
//o << std::endln;
|
|
|
|
return o;
|
|
|
|
};
|
|
|
|
|
2011-02-24 16:57:11 +03:00
|
|
|
int main(int argc, char** argv)
|
|
|
|
{
|
2007-03-15 15:43:27 +03:00
|
|
|
std::cerr << "queryLexicalTable v0.2 by Konrad Rawlik\n";
|
|
|
|
std::string inFilePath;
|
|
|
|
std::string outFilePath("out");
|
|
|
|
bool cache = false;
|
|
|
|
std::string query_e, query_f, query_c;
|
|
|
|
bool use_context = false;
|
|
|
|
bool use_e = false;
|
2011-02-24 16:57:11 +03:00
|
|
|
if(1 >= argc) {
|
|
|
|
printHelp();
|
|
|
|
return 1;
|
2007-03-15 15:43:27 +03:00
|
|
|
}
|
2011-02-24 16:57:11 +03:00
|
|
|
for(int i = 1; i < argc; ++i) {
|
2007-03-15 15:43:27 +03:00
|
|
|
std::string arg(argv[i]);
|
2011-02-24 16:57:11 +03:00
|
|
|
if("-table" == arg && i+1 < argc) {
|
|
|
|
//std::cerr << "Table is " << argv[i];
|
2007-03-15 15:43:27 +03:00
|
|
|
++i;
|
|
|
|
inFilePath = argv[i];
|
2011-02-24 16:57:11 +03:00
|
|
|
} else if("-f" == arg && i+1 < argc) {
|
|
|
|
++i;
|
|
|
|
//std::cerr << "F is " << argv[i];
|
|
|
|
query_f = argv[i];
|
|
|
|
} else if("-e" == arg && i+1 < argc) {
|
|
|
|
++i;
|
|
|
|
query_e = argv[i];
|
|
|
|
use_e = true;
|
|
|
|
} else if("-c" == arg) {
|
|
|
|
if(i+1 < argc && '-' != argv[i+1][0]) {
|
|
|
|
++i;
|
|
|
|
query_c = argv[i];
|
|
|
|
use_context = true;
|
|
|
|
} else {
|
|
|
|
use_context = false;
|
|
|
|
}
|
|
|
|
} else if("-cache" == arg) {
|
|
|
|
++i;
|
|
|
|
cache = true;
|
2007-03-15 15:43:27 +03:00
|
|
|
} else {
|
|
|
|
//somethings wrong... print help
|
2011-02-24 16:57:11 +03:00
|
|
|
printHelp();
|
2007-03-15 15:43:27 +03:00
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
FactorList f_mask;
|
|
|
|
FactorList e_mask;
|
|
|
|
FactorList c_mask;
|
|
|
|
f_mask.push_back(0);
|
2011-02-24 16:57:11 +03:00
|
|
|
if(use_e) {
|
|
|
|
e_mask.push_back(0);
|
2007-03-15 15:43:27 +03:00
|
|
|
}
|
2011-02-24 16:57:11 +03:00
|
|
|
if(use_context) {
|
|
|
|
c_mask.push_back(0);
|
2007-03-15 15:43:27 +03:00
|
|
|
}
|
2011-11-21 14:49:26 +04:00
|
|
|
Phrase e( 0),f(0),c(0);
|
2014-05-31 17:33:31 +04:00
|
|
|
// e.CreateFromString(Output, e_mask, query_e, "|", NULL);
|
|
|
|
// f.CreateFromString(Input, f_mask, query_f, "|", NULL);
|
|
|
|
// c.CreateFromString(Input, c_mask, query_c,"|", NULL);
|
|
|
|
// Phrase.CreateFromString() calls Word.CreateFromSting(), which gets
|
|
|
|
// the factor delimiter from StaticData, so it should not be hardcoded
|
|
|
|
// here. [UG], thus:
|
|
|
|
e.CreateFromString(Output, e_mask, query_e, NULL);
|
|
|
|
f.CreateFromString(Input, f_mask, query_f, NULL);
|
|
|
|
c.CreateFromString(Input, c_mask, query_c, NULL);
|
2007-03-15 15:43:27 +03:00
|
|
|
LexicalReorderingTable* table;
|
2011-02-24 16:57:11 +03:00
|
|
|
if(FileExists(inFilePath+".binlexr.idx")) {
|
|
|
|
std::cerr << "Loading binary table...\n";
|
|
|
|
table = new LexicalReorderingTableTree(inFilePath, f_mask, e_mask, c_mask);
|
2007-03-15 15:43:27 +03:00
|
|
|
} else {
|
2011-02-24 16:57:11 +03:00
|
|
|
std::cerr << "Loading ordinary table...\n";
|
|
|
|
table = new LexicalReorderingTableMemory(inFilePath, f_mask, e_mask, c_mask);
|
2007-03-15 15:43:27 +03:00
|
|
|
}
|
|
|
|
//table->DbgDump(&std::cerr);
|
2011-02-24 16:57:11 +03:00
|
|
|
if(cache) {
|
|
|
|
std::cerr << "Caching for f\n";
|
|
|
|
table->InitializeForInputPhrase(f);
|
2007-03-15 15:43:27 +03:00
|
|
|
}
|
|
|
|
std::cerr << "Querying: f='" << f.GetStringRep(f_mask) << "' e='" << e.GetStringRep(e_mask) << "' c='" << c.GetStringRep(c_mask) << "'\n";
|
|
|
|
std::cerr << table->GetScore(f,e,c) << "\n";
|
|
|
|
//table->DbgDump(&std::cerr);
|
|
|
|
delete table;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|