00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include <string>
00020 #include <vector>
00021
00022 #include "TypeDef.h"
00023 #include "PhraseDictionaryTreeAdaptor.h"
00024 #include "Phrase.h"
00025 #include "TargetPhraseCollection.h"
00026 #include "LMList.h"
00027 #include "ScoreComponentCollection.h"
00028
00029 using namespace std;
00030 using namespace Moses;
00031
00032
00033 string trim(string str)
00034 {
00035 string::iterator it;
00036
00037 while ((str.length()>0)&&((*(it=str.begin()))==' ')) {
00038 str.erase(it);
00039 }
00040
00041 while ((str.length()>0)&&((*(it=(str.end()-1)))==' ')) {
00042 str.erase(it);
00043 }
00044
00045 for(unsigned i=0; i<str.length(); i++) {
00046 if ((str[i]==' ') && ((i+1)<str.length()) && (str[i+1]==' ')) {
00047 str=str.erase(i,1);
00048 i--;
00049 }
00050 }
00051
00052 return str;
00053 }
00054
00055
00056 int main (int argc, char *argv[])
00057 {
00058 vector<FactorType> input, output;
00059 vector<float> weight;
00060 int numScoreComponent=5;
00061 int numInputScores=0;
00062 int tableLimit=0;
00063 int weightWP=0;
00064 LMList lmList;
00065
00066 input.push_back(0);
00067 output.push_back(0);
00068
00069 weight.push_back(0);
00070 weight.push_back(0);
00071 weight.push_back(0);
00072 weight.push_back(0);
00073 weight.push_back(0);
00074
00075 if (argc<3) {
00076 cerr<<"Error: Wrong number of parameters."<<endl;
00077 cerr<<"Sintax: "<<argv[0]<<" /path/to/phrase/table source phrase"<<endl;
00078 exit(EXIT_FAILURE);
00079 }
00080
00081 string filePath=argv[1];
00082
00083 string source_str="";
00084 for(unsigned i=2; i<argc; i++) {
00085 if (source_str.length()>0) source_str+=" ";
00086 source_str+=argv[i];
00087 }
00088
00089 cerr<<"numScoreComponent: "<<numScoreComponent<<endl;
00090 cerr<<"numInputScores: "<<numInputScores<<endl;
00091
00092 PhraseDictionaryTreeAdaptor *pd=new PhraseDictionaryTreeAdaptor(numScoreComponent, numInputScores);
00093
00094 cerr<<"Table limit: "<<tableLimit<<endl;
00095 cerr<<"WeightWordPenalty: "<<weightWP<<endl;
00096 cerr<<"Source phrase: ___"<<source_str<<"___"<<endl;
00097
00098 if (!pd->Load(input, output, filePath, weight, tableLimit, lmList, weightWP)) {
00099 delete pd;
00100 return false;
00101 }
00102
00103 cerr<<"-------------------------------------------------"<<endl;
00104 FactorDirection direction;
00105 Phrase phrase(direction);
00106
00107 phrase.CreateFromString(input, source_str, "|");
00108 TargetPhraseCollection *tpc = (TargetPhraseCollection*) pd->GetTargetPhraseCollection(phrase);
00109
00110 if (tpc == NULL)
00111 cerr<<"Not found."<<endl;
00112 else {
00113 TargetPhraseCollection::iterator iterTargetPhrase;
00114 for (iterTargetPhrase = tpc->begin(); iterTargetPhrase != tpc->end(); ++iterTargetPhrase) {
00115
00116
00117 stringstream strs;
00118 strs<<static_cast<const Phrase&>(*(*iterTargetPhrase));
00119 cerr<<source_str<<" => ___"<<trim(strs.str())<<"___ ";
00120 ScoreComponentCollection scc = (*iterTargetPhrase)->GetScoreBreakdown();
00121 cerr<<"Scores: ";
00122 for(unsigned i=0; i<scc.size(); i++) {
00123 cerr<<scc[i]<<" ";
00124 }
00125 cerr<<endl;
00126 }
00127 }
00128 cerr<<"-------------------------------------------------"<<endl;
00129 }