blob: 3f9bc630bc6a78b2e75ac68a314389783092966e (
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
|
#include "alignment.h"
#include <fstream>
#include <sstream>
#include <string>
#include <fcntl.h>
#include <unistd.h>
#include <vector>
#include "filelib.h"
#include <boost/algorithm/string.hpp>
using namespace std;
namespace extractor {
Alignment::Alignment(const string& filename) {
ReadFile rf(filename);
istream& infile = *rf.stream();
string line;
while (getline(infile, line)) {
vector<string> items;
boost::split(items, line, boost::is_any_of(" -"));
vector<pair<int, int>> alignment;
alignment.reserve(items.size() / 2);
for (size_t i = 1; i < items.size(); i += 2) {
alignment.push_back(make_pair(stoi(items[i - 1]), stoi(items[i])));
}
alignments.push_back(alignment);
}
alignments.shrink_to_fit();
}
Alignment::Alignment() {}
Alignment::~Alignment() {}
vector<pair<int, int>> Alignment::GetLinks(int sentence_index) const {
return alignments[sentence_index];
}
bool Alignment::operator==(const Alignment& other) const {
return alignments == other.alignments;
}
} // namespace extractor
|