diff options
author | Paul Baltescu <pauldb89@gmail.com> | 2013-06-20 15:38:24 +0100 |
---|---|---|
committer | Paul Baltescu <pauldb89@gmail.com> | 2013-06-20 15:38:24 +0100 |
commit | 23e89686849d290e8b64875a0bdf77cbdb70d2df (patch) | |
tree | e014b6136b089ee7ef3b42bdafcabfecb147952c /extractor | |
parent | 3c3d79f7120e872176e013bf2d3617575d550860 (diff) |
Do not add empty entries in translation table for nonexistent word pairs.
Diffstat (limited to 'extractor')
-rw-r--r-- | extractor/translation_table.cc | 14 |
1 files changed, 12 insertions, 2 deletions
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 { |