mosesdecoder/moses/TranslationModel/ProbingPT/vocabid.cpp

33 lines
787 B
C++
Raw Normal View History

2015-01-14 14:07:42 +03:00
#include "vocabid.hh"
2014-06-11 14:47:00 +04:00
2015-01-14 14:07:42 +03:00
void add_to_map(std::map<uint64_t, std::string> *karta, StringPiece textin)
{
//Tokenize
util::TokenIter<util::SingleCharacter> it(textin, util::SingleCharacter(' '));
2014-06-11 14:47:00 +04:00
2015-01-14 14:07:42 +03:00
while(it) {
karta->insert(std::pair<uint64_t, std::string>(getHash(*it), it->as_string()));
it++;
}
2014-06-11 14:47:00 +04:00
}
2015-01-14 14:07:42 +03:00
void serialize_map(std::map<uint64_t, std::string> *karta, const char* filename)
{
std::ofstream os (filename, std::ios::binary);
boost::archive::text_oarchive oarch(os);
2014-06-11 14:47:00 +04:00
2015-01-14 14:07:42 +03:00
oarch << *karta; //Serialise map
os.close();
2014-06-11 14:47:00 +04:00
}
2015-01-14 14:07:42 +03:00
void read_map(std::map<uint64_t, std::string> *karta, const char* filename)
{
std::ifstream is (filename, std::ios::binary);
boost::archive::text_iarchive iarch(is);
2014-06-11 14:47:00 +04:00
2015-01-14 14:07:42 +03:00
iarch >> *karta;
2014-06-11 14:47:00 +04:00
2015-01-14 14:07:42 +03:00
//Close the stream after we are done.
is.close();
2014-06-11 14:47:00 +04:00
}