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 | 5794c0109902cf19a52cc8f1799353270ed9d85d (patch) | |
tree | b32b113529eac6ed35458bb2675850343a16432d /extractor | |
parent | 4987b08e432f594d76f136a9b9de78192ec3eea2 (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 { |