1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
/*
* Copyright (C) 2009 Felipe Sánchez-Martínez
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of the
* License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
* 02111-1307, USA.
*/
#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;
//Delete white spaces from the end and the begining of the string
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) {
//cerr<<(*(*iterTargetPhrase))<<endl;
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;
}
|