00001
00002
00003
00004 #include <cstdlib>
00005 #include <cstring>
00006 #include <string>
00007 #include <vector>
00008
00009 #include "moses/TranslationModel/PhraseDictionaryTree.h"
00010 #include "moses/Util.h"
00011
00012 void usage();
00013
00014 typedef unsigned int uint;
00015
00016 int main(int argc, char **argv)
00017 {
00018 int nscores = 5;
00019 std::string ttable = "";
00020 bool needAlignments = false;
00021 bool reportCounts = false;
00022
00023 for(int i = 1; i < argc; i++) {
00024 if(!strcmp(argv[i], "-n")) {
00025 if(i + 1 == argc)
00026 usage();
00027 nscores = atoi(argv[++i]);
00028 } else if(!strcmp(argv[i], "-t")) {
00029 if(i + 1 == argc)
00030 usage();
00031 ttable = argv[++i];
00032 } else if(!strcmp(argv[i], "-a")) {
00033 needAlignments = true;
00034 } else if (!strcmp(argv[i], "-c")) {
00035 reportCounts = true;
00036 } else
00037 usage();
00038 }
00039
00040 if(ttable == "")
00041 usage();
00042
00043 Moses::PhraseDictionaryTree ptree;
00044 ptree.NeedAlignmentInfo(needAlignments);
00045 ptree.Read(ttable);
00046
00047 std::string line;
00048 while(getline(std::cin, line)) {
00049 std::vector<std::string> srcphrase;
00050 srcphrase = Moses::Tokenize<std::string>(line);
00051
00052 std::vector<Moses::StringTgtCand> tgtcands;
00053 std::vector<std::string> wordAlignment;
00054
00055 if(needAlignments)
00056 ptree.GetTargetCandidates(srcphrase, tgtcands, wordAlignment);
00057 else
00058 ptree.GetTargetCandidates(srcphrase, tgtcands);
00059
00060 if (reportCounts) {
00061 std::cout << line << " " << tgtcands.size() << "\n";
00062 } else {
00063 for(uint i = 0; i < tgtcands.size(); i++) {
00064 std::cout << line << " |||";
00065 for(uint j = 0; j < tgtcands[i].tokens.size(); j++)
00066 std::cout << ' ' << *tgtcands[i].tokens[j];
00067 std::cout << " |||";
00068
00069 if(needAlignments) {
00070 std::cout << " " << wordAlignment[i] << " |||";
00071 }
00072
00073 for(uint j = 0; j < tgtcands[i].scores.size(); j++)
00074 std::cout << ' ' << tgtcands[i].scores[j];
00075 std::cout << '\n';
00076 }
00077 std::cout << '\n';
00078 }
00079
00080 std::cout.flush();
00081 }
00082 }
00083
00084 void usage()
00085 {
00086 std::cerr << "Usage: queryPhraseTable [-n <nscores>] [-a] -t <ttable>\n"
00087 "-n <nscores> number of scores in phrase table (default: 5)\n"
00088 "-c only report counts of entries\n"
00089 "-a binary phrase table contains alignments\n"
00090 "-t <ttable> phrase table\n";
00091 exit(1);
00092 }