#include "alignment.h" #include #include #include #include #include #include #include #include namespace fs = boost::filesystem; using namespace std; namespace extractor { Alignment::Alignment(const string& filename) { ifstream infile(filename.c_str()); string line; while (getline(infile, line)) { vector items; boost::split(items, line, boost::is_any_of(" -")); vector > 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 > Alignment::GetLinks(int sentence_index) const { return alignments[sentence_index]; } void Alignment::WriteBinary(const fs::path& filepath) { FILE* file = fopen(filepath.string().c_str(), "w"); int size = alignments.size(); fwrite(&size, sizeof(int), 1, file); for (vector > alignment: alignments) { size = alignment.size(); fwrite(&size, sizeof(int), 1, file); fwrite(alignment.data(), sizeof(pair), size, file); } } } // namespace extractor