00001 // -*- c++ -*- 00002 // Phrase scorer that rewards the number of phrase pair occurrences in a bitext 00003 // with the asymptotic function x/(j+x) where x > 0 is a function 00004 // parameter that determines the steepness of the rewards curve 00005 // written by Ulrich Germann 00006 00007 #include "sapt_pscore_base.h" 00008 #include <boost/dynamic_bitset.hpp> 00009 00010 namespace sapt { 00011 00012 // rareness penalty: x/(n+x) 00013 template<typename Token> 00014 class 00015 PScoreRareness : public SingleRealValuedParameterPhraseScorerFamily<Token> 00016 { 00017 public: 00018 PScoreRareness(std::string const spec) 00019 { 00020 this->m_tag = "rare"; 00021 this->init(spec); 00022 } 00023 00024 bool 00025 isLogVal(int i) const { return false; } 00026 00027 void 00028 operator()(Bitext<Token> const& bt, 00029 PhrasePair<Token>& pp, 00030 std::vector<float> * dest = NULL) const 00031 { 00032 if (!dest) dest = &pp.fvals; 00033 size_t i = this->m_index; 00034 BOOST_FOREACH(float const x, this->m_x) 00035 (*dest).at(i++) = x/(x + pp.joint); 00036 } 00037 }; 00038 } // namespace sapt