00001
00002
00003
00004
00005 #include "moses/TranslationModel/UG/mm/ug_bitext.h"
00006 #include "sapt_pscore_base.h"
00007 #include <boost/dynamic_bitset.hpp>
00008
00009 namespace sapt
00010 {
00011 template<typename Token>
00012 class
00013 PScoreLex1 : public PhraseScorer<Token>
00014 {
00015 float m_alpha;
00016 std::string m_lexfile;
00017 public:
00018 sapt::LexicalPhraseScorer2<Token> scorer;
00019
00020 PScoreLex1(std::string const& alphaspec, std::string const& lexfile)
00021 {
00022 this->m_index = -1;
00023 this->m_num_feats = 2;
00024 this->m_feature_names.reserve(2);
00025 this->m_feature_names.push_back("lexfwd");
00026 this->m_feature_names.push_back("lexbwd");
00027 m_alpha = atof(alphaspec.c_str());
00028 m_lexfile = lexfile;
00029 }
00030
00031 void
00032 load()
00033 {
00034 scorer.open(m_lexfile);
00035 }
00036
00037 void
00038 operator()(Bitext<Token> const& bt,
00039 PhrasePair<Token>& pp,
00040 std::vector<float> * dest = NULL) const
00041 {
00042 if (!dest) dest = &pp.fvals;
00043
00044
00045
00046 #if 0
00047 cout << len1 << " " << len2 << endl;
00048 Token const* t1 = bt.T1->sntStart(sid1);
00049 for (size_t i = off1; i < off1 + len1; ++i)
00050 cout << (*bt.V1)[t1[i].id()] << " ";
00051 cout << __FILE__ << ":" << __LINE__ << endl;
00052
00053 Token const* t2 = bt.T2->sntStart(sid2);
00054 for (size_t i = off2; i < off2 + len2; ++i)
00055 cout << (*bt.V2)[t2[i].id()] << " ";
00056 cout << __FILE__ << ":" << __LINE__ << endl;
00057
00058 BOOST_FOREACH (int a, pp.aln)
00059 cout << a << " " ;
00060 cout << __FILE__ << ":" << __LINE__ << "\n" << endl;
00061
00062 scorer.score(bt.T1->sntStart(sid1)+off1,0,len1,
00063 bt.T2->sntStart(sid2)+off2,0,len2,
00064 pp.aln, m_alpha,
00065 (*dest)[this->m_index],
00066 (*dest)[this->m_index+1]);
00067 #endif
00068 scorer.score(pp.start1,0, pp.len1,
00069 pp.start2,0, pp.len2, pp.aln, m_alpha,
00070 (*dest)[this->m_index],
00071 (*dest)[this->m_index+1]);
00072 }
00073 };
00074 }
00075