00001
00002
00003
00004
00005 #include "sapt_pscore_base.h"
00006 #include <boost/dynamic_bitset.hpp>
00007 #include <vector>
00008
00009 namespace sapt
00010 {
00011 template<typename Token>
00012 class
00013 PScoreUnaligned : public PhraseScorer<Token>
00014 {
00015 typedef boost::dynamic_bitset<uint64_t> bitvector;
00016 public:
00017 PScoreUnaligned(std::string const spec)
00018 {
00019 this->m_index = -1;
00020 int f = this->m_num_feats = atoi(spec.c_str());
00021 UTIL_THROW_IF2(f != 1 && f != 2,"unal parameter must be 1 or 2 at "<<HERE);
00022 this->m_feature_names.resize(f);
00023 if (f == 1)
00024 this->m_feature_names[0] = "unal";
00025 else
00026 {
00027 this->m_feature_names[0] = "unal-s";
00028 this->m_feature_names[1] = "unal-t";
00029 }
00030 }
00031
00032 bool
00033 isLogVal(int i) const { return false; }
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
00045
00046
00047 bitvector check1(pp.len1),check2(pp.len2);
00048 for (size_t i = 0; i < pp.aln.size(); )
00049 {
00050 check1.set(pp.aln[i++]);
00051 check2.set(pp.aln.at(i++));
00052 }
00053
00054 if (this->m_num_feats == 1)
00055 {
00056 (*dest)[this->m_index] = pp.len1 - check1.count();
00057 (*dest)[this->m_index] += pp.len2 - check2.count();
00058 }
00059 else
00060 {
00061 (*dest)[this->m_index] = pp.len1 - check1.count();
00062 (*dest)[this->m_index+1] = pp.len2 - check2.count();
00063 }
00064 }
00065 };
00066 }