summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPaul Baltescu <pauldb89@gmail.com>2013-06-20 15:38:24 +0100
committerPaul Baltescu <pauldb89@gmail.com>2013-06-20 15:38:24 +0100
commit23e89686849d290e8b64875a0bdf77cbdb70d2df (patch)
treee014b6136b089ee7ef3b42bdafcabfecb147952c
parent3c3d79f7120e872176e013bf2d3617575d550860 (diff)
Do not add empty entries in translation table for nonexistent word pairs.
-rw-r--r--extractor/translation_table.cc14
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 {