00001
00002
00003
00004
00005
00006
00007 #include "sapt_pscore_base.h"
00008 #include <boost/dynamic_bitset.hpp>
00009
00010 namespace sapt {
00011
00012 template<typename Token>
00013 class
00014 PScoreLogCnt : public PhraseScorer<Token>
00015 {
00016 std::string m_specs;
00017 public:
00018 PScoreLogCnt(std::string const specs)
00019 {
00020 this->m_index = -1;
00021 this->m_specs = specs;
00022 if (specs.find("r1") != std::string::npos)
00023 this->m_feature_names.push_back("log-r1");
00024 if (specs.find("s1") != std::string::npos)
00025 this->m_feature_names.push_back("log-s1");
00026 if (specs.find("g1") != std::string::npos)
00027 this->m_feature_names.push_back("log-g1");
00028 if (specs.find("j") != std::string::npos)
00029 this->m_feature_names.push_back("log-j");
00030 if (specs.find("r2") != std::string::npos)
00031 this->m_feature_names.push_back("log-r2");
00032 this->m_num_feats = this->m_feature_names.size();
00033 }
00034
00035 bool
00036 isIntegerValued(int i) const { return true; }
00037
00038 void
00039 operator()(Bitext<Token> const& bt,
00040 PhrasePair<Token>& pp,
00041 std::vector<float> * dest = NULL) const
00042 {
00043 if (!dest) dest = &pp.fvals;
00044 assert(pp.raw1);
00045 assert(pp.sample1);
00046 assert(pp.good1);
00047 assert(pp.joint);
00048 assert(pp.raw2);
00049 size_t i = this->m_index;
00050 if (m_specs.find("r1") != std::string::npos)
00051 (*dest)[i++] = log(pp.raw1);
00052 if (m_specs.find("s1") != std::string::npos)
00053 (*dest)[i++] = log(pp.sample1);
00054 if (m_specs.find("g1") != std::string::npos)
00055 (*dest)[i++] = log(pp.good1);
00056 if (m_specs.find("j") != std::string::npos)
00057 (*dest)[i++] = log(pp.joint);
00058 if (m_specs.find("r2") != std::string::npos)
00059 (*dest)[i] = log(pp.raw2);
00060 }
00061 };
00062 }