diff options
author | Paul Baltescu <pauldb89@gmail.com> | 2013-02-01 16:11:10 +0000 |
---|---|---|
committer | Paul Baltescu <pauldb89@gmail.com> | 2013-02-01 16:11:10 +0000 |
commit | 252fb164c208ec8f3005f8a652eb3b48c0644e3d (patch) | |
tree | 7199cb668e77ef89c7bcccb37d70554e3b52c2a5 /extractor/features/max_lex_source_given_target.cc | |
parent | 4ab84a0be28fdb6c0c421fe5ba5e09cfa298f2d1 (diff) |
Second working commit.
Diffstat (limited to 'extractor/features/max_lex_source_given_target.cc')
-rw-r--r-- | extractor/features/max_lex_source_given_target.cc | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/extractor/features/max_lex_source_given_target.cc b/extractor/features/max_lex_source_given_target.cc new file mode 100644 index 00000000..c4792d49 --- /dev/null +++ b/extractor/features/max_lex_source_given_target.cc @@ -0,0 +1,30 @@ +#include "max_lex_source_given_target.h" + +#include <cmath> + +#include "../translation_table.h" + +MaxLexSourceGivenTarget::MaxLexSourceGivenTarget( + shared_ptr<TranslationTable> table) : + table(table) {} + +double MaxLexSourceGivenTarget::Score(const FeatureContext& context) const { + vector<string> source_words = context.source_phrase.GetWords(); + // TODO(pauldb): Add NULL to target_words, after fixing translation table. + vector<string> target_words = context.target_phrase.GetWords(); + + double score = 0; + for (string source_word: source_words) { + double max_score = 0; + for (string target_word: target_words) { + max_score = max(max_score, + table->GetSourceGivenTargetScore(source_word, target_word)); + } + score += max_score > 0 ? -log10(max_score) : MAX_SCORE; + } + return score; +} + +string MaxLexSourceGivenTarget::GetName() const { + return "MaxLexFGivenE"; +} |