From 23e89686849d290e8b64875a0bdf77cbdb70d2df Mon Sep 17 00:00:00 2001 From: Paul Baltescu Date: Thu, 20 Jun 2013 15:38:24 +0100 Subject: Do not add empty entries in translation table for nonexistent word pairs. --- extractor/translation_table.cc | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'extractor') diff --git a/extractor/translation_table.cc b/extractor/translation_table.cc index 03e41d9a..1b1ba112 100644 --- a/extractor/translation_table.cc +++ b/extractor/translation_table.cc @@ -97,7 +97,12 @@ double TranslationTable::GetTargetGivenSourceScore( int source_id = source_data_array->GetWordId(source_word); int target_id = target_data_array->GetWordId(target_word); - return translation_probabilities[make_pair(source_id, target_id)].first; + auto entry = make_pair(source_id, target_id); + auto it = translation_probabilities.find(entry); + if (it == translation_probabilities.end()) { + return 0; + } + return it->second.first; } double TranslationTable::GetSourceGivenTargetScore( @@ -109,7 +114,12 @@ double TranslationTable::GetSourceGivenTargetScore( int source_id = source_data_array->GetWordId(source_word); int target_id = target_data_array->GetWordId(target_word); - return translation_probabilities[make_pair(source_id, target_id)].second; + auto entry = make_pair(source_id, target_id); + auto it = translation_probabilities.find(entry); + if (it == translation_probabilities.end()) { + return 0; + } + return it->second.second; } bool TranslationTable::operator==(const TranslationTable& other) const { -- cgit v1.2.3