blob: 0ceb21abd6fed59e863be79d2efcae0fd1685131 (
plain)
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
|
/*
* nbest: tool to process moses n-best lists
*
* File: Hypo.cpp
* basic functions to process one hypothesis
*
* Created by Holger Schwenk, University of Le Mans, 05/16/2008
*
*/
#include "Hypo.h"
#include <iostream>
//const char* NBEST_DELIM = "|||";
Hypo::Hypo()
{
//cerr << "Hypo: constructor called" << endl;
}
Hypo::~Hypo()
{
//cerr << "Hypo: destructor called" << endl;
}
void Hypo::Write(ofstream &outf)
{
outf << id << NBEST_DELIM2 << trg << NBEST_DELIM2;
for (vector<float>::iterator i = f.begin(); i != f.end(); i++)
outf << (*i) << " ";
outf << NBEST_DELIM << " " << s << endl;
}
float Hypo::CalcGlobal(Weights &w)
{
//cerr << " HYP: calc global" << endl;
int sz=w.val.size();
if (sz<f.size()) {
cerr << " - NOTE: padding weight vector with " << f.size()-sz << " zeros" << endl;
w.val.resize(f.size());
}
s=0;
for (int i=0; i<f.size(); i++) {
//cerr << "i=" << i << ", " << w.val[i] << ", " << f[i] << endl;
s+=w.val[i]*f[i];
}
//cerr << "s=" << s << endl;
return s;
}
// this is actually a "greater than" since we want to sort in descending order
bool Hypo::operator< (const Hypo &h2) const
{
return (this->s > h2.s);
}
|