#ifndef _TRANSLATION_TABLE_ #define _TRANSLATION_TABLE_ #include #include #include #include #include #include #include #include using namespace std; namespace fs = boost::filesystem; namespace extractor { typedef boost::hash> PairHash; class Alignment; class DataArray; /** * Bilexical table with conditional probabilities. */ class TranslationTable { public: // Constructs a translation table from source data, target data and the // corresponding alignment. TranslationTable( shared_ptr source_data_array, shared_ptr target_data_array, shared_ptr alignment); // Creates empty translation table. TranslationTable(); virtual ~TranslationTable(); // Returns p(e | f). virtual double GetTargetGivenSourceScore(const string& source_word, const string& target_word); // Returns p(f | e). virtual double GetSourceGivenTargetScore(const string& source_word, const string& target_word); bool operator==(const TranslationTable& other) const; private: // Increment links count for the given (f, e) word pair. void IncrementLinksCount( unordered_map& source_links_count, unordered_map& target_links_count, unordered_map, int, PairHash>& links_count, int source_word_id, int target_word_id) const; friend class boost::serialization::access; template void save(Archive& ar, unsigned int) const { ar << *source_data_array << *target_data_array; int num_entries = translation_probabilities.size(); ar << num_entries; for (auto entry: translation_probabilities) { ar << entry; } } template void load(Archive& ar, unsigned int) { source_data_array = make_shared(); ar >> *source_data_array; target_data_array = make_shared(); ar >> *target_data_array; int num_entries; ar >> num_entries; for (size_t i = 0; i < num_entries; ++i) { pair, pair> entry; ar >> entry; translation_probabilities.insert(entry); } } BOOST_SERIALIZATION_SPLIT_MEMBER(); shared_ptr source_data_array; shared_ptr target_data_array; unordered_map, pair, PairHash> translation_probabilities; }; } // namespace extractor #endif