summaryrefslogtreecommitdiff
path: root/extractor/translation_table.cc
diff options
context:
space:
mode:
authorPatrick Simianer <p@simianer.de>2013-06-24 14:40:07 +0200
committerPatrick Simianer <p@simianer.de>2013-06-24 14:40:07 +0200
commite547ab5f765c72ad326b1d3a79f26bb221364d7d (patch)
treee205609de0adce98bdf4ec4e799cd776cebe8b72 /extractor/translation_table.cc
parentbecb1347773ebaae8cab2669afe4bad048cda992 (diff)
parent5794c0109902cf19a52cc8f1799353270ed9d85d (diff)
Merge remote-tracking branch 'upstream/master'
Diffstat (limited to 'extractor/translation_table.cc')
-rw-r--r--extractor/translation_table.cc27
1 files changed, 16 insertions, 11 deletions
diff --git a/extractor/translation_table.cc b/extractor/translation_table.cc
index adb59cb5..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,18 +114,18 @@ 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;
}
-void TranslationTable::WriteBinary(const fs::path& filepath) const {
- FILE* file = fopen(filepath.string().c_str(), "w");
-
- int size = translation_probabilities.size();
- fwrite(&size, sizeof(int), 1, file);
- for (auto entry: translation_probabilities) {
- fwrite(&entry.first, sizeof(entry.first), 1, file);
- fwrite(&entry.second, sizeof(entry.second), 1, file);
- }
+bool TranslationTable::operator==(const TranslationTable& other) const {
+ return *source_data_array == *other.source_data_array &&
+ *target_data_array == *other.target_data_array &&
+ translation_probabilities == other.translation_probabilities;
}
} // namespace extractor