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
129
130
131
132
133
134
135
136
137
|
/***********************************************************************
Moses - factored phrase-based language decoder
Copyright (C) 2009 University of Edinburgh
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
This library 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
Lesser General Public License for more details.
You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
***********************************************************************/
#include <string.h>
#include <fstream>
#include <vector>
#include <string>
#include <iostream>
#include <cstdlib>
#include "InputFileStream.h"
#include "OutputFileStream.h"
#include "SafeGetline.h"
#define LINE_MAX_LENGTH 10000
using namespace std;
char line[LINE_MAX_LENGTH];
vector< string > splitLine()
{
vector< string > item;
int start=0;
int i=0;
for(; line[i] != '\0'; i++) {
if (line[i] == ' ' &&
line[i+1] == '|' &&
line[i+2] == '|' &&
line[i+3] == '|' &&
line[i+4] == ' ') {
if (start > i) start = i; // empty item
item.push_back( string( line+start, i-start ) );
start = i+5;
i += 3;
}
}
item.push_back( string( line+start, i-start ) );
return item;
}
bool getLine( istream &fileP, vector< string > &item )
{
if (fileP.eof())
return false;
SAFE_GETLINE((fileP), line, LINE_MAX_LENGTH, '\n', __FILE__);
if (fileP.eof())
return false;
item = splitLine();
return true;
}
int main(int argc, char* argv[])
{
cerr << "Starting..." << endl;
char* &fileNameDirect = argv[1];
Moses::InputFileStream fileDirect(fileNameDirect);
//fileDirect.open(fileNameDirect);
if (fileDirect.fail()) {
cerr << "ERROR: could not open extract file " << fileNameDirect << endl;
exit(1);
}
istream &fileDirectP = fileDirect;
char* &fileNameConsolidated = argv[2];
ostream *fileConsolidated;
if (strcmp(fileNameConsolidated, "-") == 0) {
fileConsolidated = &cout;
} else {
Moses::OutputFileStream *outputFile = new Moses::OutputFileStream();
bool success = outputFile->Open(fileNameConsolidated);
if (!success) {
cerr << "ERROR: could not open file phrase table file "
<< fileNameConsolidated << endl;
exit(1);
}
fileConsolidated = outputFile;
}
int i=0;
while(true) {
i++;
if (i%1000 == 0) cerr << "." << flush;
if (i%10000 == 0) cerr << ":" << flush;
if (i%100000 == 0) cerr << "!" << flush;
vector< string > itemDirect;
if (! getLine(fileDirectP, itemDirect ))
break;
(*fileConsolidated) << itemDirect[0] << " ||| " << itemDirect[1] << " ||| ";
// output alignment and probabilities
(*fileConsolidated) << itemDirect[2] // prob direct
<< " 2.718" // phrase count feature
<< " ||| " << itemDirect[3]; // alignment
// counts
(*fileConsolidated) << "||| 0 " << itemDirect[4]; // indirect
(*fileConsolidated) << endl;
}
fileConsolidated->flush();
if (fileConsolidated != &cout) {
delete fileConsolidated;
}
cerr << "Finished" << endl;
}
|