|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include <string> |
|
#include <vector> |
|
|
|
#include "TypeDef.h" |
|
#include "PhraseDictionaryTreeAdaptor.h" |
|
#include "Phrase.h" |
|
#include "TargetPhraseCollection.h" |
|
#include "LMList.h" |
|
#include "ScoreComponentCollection.h" |
|
|
|
using namespace std; |
|
using namespace Moses; |
|
|
|
|
|
string trim(string str) |
|
{ |
|
string::iterator it; |
|
|
|
while ((str.length()>0)&&((*(it=str.begin()))==' ')) { |
|
str.erase(it); |
|
} |
|
|
|
while ((str.length()>0)&&((*(it=(str.end()-1)))==' ')) { |
|
str.erase(it); |
|
} |
|
|
|
for(unsigned i=0; i<str.length(); i++) { |
|
if ((str[i]==' ') && ((i+1)<str.length()) && (str[i+1]==' ')) { |
|
str=str.erase(i,1); |
|
i--; |
|
} |
|
} |
|
|
|
return str; |
|
} |
|
|
|
|
|
int main (int argc, char *argv[]) |
|
{ |
|
vector<FactorType> input, output; |
|
vector<float> weight; |
|
int numScoreComponent=5; |
|
int numInputScores=0; |
|
int tableLimit=0; |
|
int weightWP=0; |
|
LMList lmList; |
|
|
|
input.push_back(0); |
|
output.push_back(0); |
|
|
|
weight.push_back(0); |
|
weight.push_back(0); |
|
weight.push_back(0); |
|
weight.push_back(0); |
|
weight.push_back(0); |
|
|
|
if (argc<3) { |
|
cerr<<"Error: Wrong number of parameters."<<endl; |
|
cerr<<"Sintax: "<<argv[0]<<" /path/to/phrase/table source phrase"<<endl; |
|
exit(EXIT_FAILURE); |
|
} |
|
|
|
string filePath=argv[1]; |
|
|
|
string source_str=""; |
|
for(unsigned i=2; i<argc; i++) { |
|
if (source_str.length()>0) source_str+=" "; |
|
source_str+=argv[i]; |
|
} |
|
|
|
cerr<<"numScoreComponent: "<<numScoreComponent<<endl; |
|
cerr<<"numInputScores: "<<numInputScores<<endl; |
|
|
|
PhraseDictionaryTreeAdaptor *pd=new PhraseDictionaryTreeAdaptor(numScoreComponent, numInputScores); |
|
|
|
cerr<<"Table limit: "<<tableLimit<<endl; |
|
cerr<<"WeightWordPenalty: "<<weightWP<<endl; |
|
cerr<<"Source phrase: ___"<<source_str<<"___"<<endl; |
|
|
|
if (!pd->Load(input, output, filePath, weight, tableLimit, lmList, weightWP)) { |
|
delete pd; |
|
return false; |
|
} |
|
|
|
cerr<<"-------------------------------------------------"<<endl; |
|
FactorDirection direction; |
|
Phrase phrase(direction); |
|
|
|
phrase.CreateFromString(input, source_str, "|"); |
|
TargetPhraseCollection *tpc = (TargetPhraseCollection*) pd->GetTargetPhraseCollection(phrase); |
|
|
|
if (tpc == NULL) |
|
cerr<<"Not found."<<endl; |
|
else { |
|
TargetPhraseCollection::iterator iterTargetPhrase; |
|
for (iterTargetPhrase = tpc->begin(); iterTargetPhrase != tpc->end(); ++iterTargetPhrase) { |
|
|
|
|
|
stringstream strs; |
|
strs<<static_cast<const Phrase&>(*(*iterTargetPhrase)); |
|
cerr<<source_str<<" => ___"<<trim(strs.str())<<"___ "; |
|
ScoreComponentCollection scc = (*iterTargetPhrase)->GetScoreBreakdown(); |
|
cerr<<"Scores: "; |
|
for(unsigned i=0; i<scc.size(); i++) { |
|
cerr<<scc[i]<<" "; |
|
} |
|
cerr<<endl; |
|
} |
|
} |
|
cerr<<"-------------------------------------------------"<<endl; |
|
} |
|
|