00001 #include <iostream>
00002 #include <string>
00003
00004 #include "moses/Phrase.h"
00005 #include "moses/FactorCollection.h"
00006 #include "moses/Timer.h"
00007 #include "moses/InputFileStream.h"
00008 #include "moses/FF/LexicalReordering/LexicalReorderingTable.h"
00009 #include "moses/parameters/OOVHandlingOptions.h"
00010
00011 using namespace Moses;
00012
00013 Timer timer;
00014
00015 void printHelp()
00016 {
00017 std::cerr << "Usage:\n"
00018 "options: \n"
00019 "\t-table file -- input table file name\n"
00020 "\t-f string -- f query phrase\n"
00021 "\t-e string -- e query phrase\n"
00022 "\t-c string -- context query phrase\n"
00023 "\n";
00024 }
00025
00026 std::ostream& operator<<(std::ostream& o, Scores s)
00027 {
00028 for(size_t i = 0; i < s.size(); ++i) {
00029 o << s[i] << " ";
00030 }
00031
00032 return o;
00033 };
00034
00035 int main(int argc, char** argv)
00036 {
00037 std::cerr << "queryLexicalTable v0.2 by Konrad Rawlik\n";
00038 std::string inFilePath;
00039 std::string outFilePath("out");
00040 bool cache = false;
00041 std::string query_e, query_f, query_c;
00042 bool use_context = false;
00043 bool use_e = false;
00044 if(1 >= argc) {
00045 printHelp();
00046 return 1;
00047 }
00048 for(int i = 1; i < argc; ++i) {
00049 std::string arg(argv[i]);
00050 if("-table" == arg && i+1 < argc) {
00051
00052 ++i;
00053 inFilePath = argv[i];
00054 } else if("-f" == arg && i+1 < argc) {
00055 ++i;
00056
00057 query_f = argv[i];
00058 } else if("-e" == arg && i+1 < argc) {
00059 ++i;
00060 query_e = argv[i];
00061 use_e = true;
00062 } else if("-c" == arg) {
00063 if(i+1 < argc && '-' != argv[i+1][0]) {
00064 ++i;
00065 query_c = argv[i];
00066 use_context = true;
00067 } else {
00068 use_context = false;
00069 }
00070 } else if("-cache" == arg) {
00071 ++i;
00072 cache = true;
00073 } else {
00074
00075 printHelp();
00076 return 1;
00077 }
00078 }
00079
00080 FactorList f_mask;
00081 FactorList e_mask;
00082 FactorList c_mask;
00083 f_mask.push_back(0);
00084 if(use_e) {
00085 e_mask.push_back(0);
00086 }
00087 if(use_context) {
00088 c_mask.push_back(0);
00089 }
00090 Phrase e( 0),f(0),c(0);
00091
00092
00093
00094
00095
00096
00097 e.CreateFromString(Output, e_mask, query_e, NULL);
00098 f.CreateFromString(Input, f_mask, query_f, NULL);
00099 c.CreateFromString(Input, c_mask, query_c, NULL);
00100 LexicalReorderingTable* table;
00101 if(FileExists(inFilePath+".binlexr.idx")) {
00102 std::cerr << "Loading binary table...\n";
00103 table = new LexicalReorderingTableTree(inFilePath, f_mask, e_mask, c_mask);
00104 } else {
00105 std::cerr << "Loading ordinary table...\n";
00106 table = new LexicalReorderingTableMemory(inFilePath, f_mask, e_mask, c_mask);
00107 }
00108
00109 if(cache) {
00110 std::cerr << "Caching for f\n";
00111 table->InitializeForInputPhrase(f);
00112 }
00113
00114 std::cerr << "Querying: "
00115 << "f='" << f.GetStringRep(f_mask) <<"' "
00116 << "e='" << e.GetStringRep(e_mask) << "' "
00117 << "c='" << c.GetStringRep(c_mask) << "'\n";
00118 std::cerr << table->GetScore(f,e,c) << "\n";
00119
00120 delete table;
00121 return 0;
00122 }
00123
00124