From 02099a01350a41a99ec400e9b29df08a01d88979 Mon Sep 17 00:00:00 2001 From: Paul Baltescu Date: Tue, 4 Jun 2013 23:17:57 +0100 Subject: Serialize data structures. --- extractor/data_array.cc | 33 ++++++--------------------------- 1 file changed, 6 insertions(+), 27 deletions(-) (limited to 'extractor/data_array.cc') diff --git a/extractor/data_array.cc b/extractor/data_array.cc index 203fe219..2e4bdafb 100644 --- a/extractor/data_array.cc +++ b/extractor/data_array.cc @@ -118,33 +118,6 @@ int DataArray::GetSentenceId(int position) const { return sentence_id[position]; } -void DataArray::WriteBinary(const fs::path& filepath) const { - std::cerr << "File: " << filepath.string() << std::endl; - WriteBinary(fopen(filepath.string().c_str(), "w")); -} - -void DataArray::WriteBinary(FILE* file) const { - int size = id2word.size(); - fwrite(&size, sizeof(int), 1, file); - for (string word: id2word) { - size = word.size(); - fwrite(&size, sizeof(int), 1, file); - fwrite(word.data(), sizeof(char), size, file); - } - - size = data.size(); - fwrite(&size, sizeof(int), 1, file); - fwrite(data.data(), sizeof(int), size, file); - - size = sentence_id.size(); - fwrite(&size, sizeof(int), 1, file); - fwrite(sentence_id.data(), sizeof(int), size, file); - - size = sentence_start.size(); - fwrite(&size, sizeof(int), 1, file); - fwrite(sentence_start.data(), sizeof(int), 1, file); -} - bool DataArray::HasWord(const string& word) const { return word2id.count(word); } @@ -158,4 +131,10 @@ string DataArray::GetWord(int word_id) const { return id2word[word_id]; } +bool DataArray::operator==(const DataArray& other) const { + return word2id == other.word2id && id2word == other.id2word && + data == other.data && sentence_start == other.sentence_start && + sentence_id == other.sentence_id; +} + } // namespace extractor -- cgit v1.2.3