-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscorers.cpp
More file actions
64 lines (44 loc) · 1.5 KB
/
scorers.cpp
File metadata and controls
64 lines (44 loc) · 1.5 KB
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
// Copyright 2012 Florian Petran
#include"scorers.h"
#include<cmath>
#include<vector>
#include"bi-sim.h"
using std::vector;
namespace Align {
ScoringMethods::ScoringMethods() {
// register all scoring methods here
this->push_back(new LengthScorer);
this->push_back(new IndexdiffScorer);
this->push_back(new BisimScorer);
}
ScoringMethods::~ScoringMethods() {
for (vector<Scorer*>::iterator sc = this->begin();
sc != this->end(); ++sc)
delete *sc;
}
Scorer::Scorer() : _max(0.0) {}
float LengthScorer::operator()(const Sequence& seq) {
_max = (_max > seq.length()) ? _max : seq.length();
return seq.length();
}
float IndexdiffScorer::operator()(const Sequence& seq) {
float result = 0.0;
float s_len = seq.first_pair().source().get_text().length();
float t_len = seq.first_pair().target().get_text().length();
for (auto pair = seq.cbegin(); pair != seq.cend(); ++pair)
result += fabs((pair->slot() / s_len)
- (pair->target_slot() / t_len));
result = 1 - (result / seq.length());
_max = (_max > result) ? _max : result;
return result;
}
float BisimScorer::operator()(const Sequence& seq) {
float result = 0.0;
for (auto pair = seq.cbegin(); pair != seq.cend(); ++pair)
result +=
bi_sim::bi_sim(pair->source().get_str(),
pair->target().get_str()) / seq.length();
_max = (_max > result) ? _max : result;
return result;
}
} // namespace Align