2011-03-22 17:33:16 +03:00
|
|
|
#include "AlignmentInfo.h"
|
|
|
|
#include "PhrasePairFeature.h"
|
|
|
|
#include "TargetPhrase.h"
|
|
|
|
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
namespace Moses {
|
|
|
|
|
|
|
|
|
|
|
|
PhrasePairFeature::PhrasePairFeature
|
|
|
|
(FactorType sourceFactorId, FactorType targetFactorId) :
|
2011-11-09 01:22:34 +04:00
|
|
|
StatelessFeatureFunction("pp", ScoreProducer::unlimited),
|
2011-03-22 17:33:16 +03:00
|
|
|
m_sourceFactorId(sourceFactorId),
|
2012-03-15 16:16:54 +04:00
|
|
|
m_targetFactorId(targetFactorId),
|
|
|
|
m_sparseProducerWeight(1) {
|
2012-03-06 00:55:26 +04:00
|
|
|
std::cerr << "Creating phrase pair feature.. " << endl;
|
|
|
|
}
|
2011-03-22 17:33:16 +03:00
|
|
|
|
2011-09-20 14:23:38 +04:00
|
|
|
string PhrasePairFeature::GetScoreProducerWeightShortName(unsigned) const
|
2011-03-22 17:33:16 +03:00
|
|
|
{
|
|
|
|
return "pp";
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t PhrasePairFeature::GetNumInputScores() const
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2012-03-04 02:20:04 +04:00
|
|
|
void PhrasePairFeature::Evaluate(const TargetPhrase& target, ScoreComponentCollection* accumulator) const {
|
|
|
|
const Phrase& source = target.GetSourcePhrase();
|
|
|
|
/* const AlignmentInfo& align = cur_hypo.GetAlignmentInfo();
|
|
|
|
for (AlignmentInfo::const_iterator i = align.begin(); i != align.end(); ++i) {
|
2011-03-23 23:42:34 +03:00
|
|
|
const Factor* sourceFactor = source.GetWord(i->first).GetFactor(m_sourceFactorId);
|
2011-03-22 17:33:16 +03:00
|
|
|
const Factor* targetFactor = cur_hypo.GetWord(i->second).GetFactor(m_targetFactorId);
|
|
|
|
ostringstream namestr;
|
|
|
|
namestr << sourceFactor->GetString();
|
|
|
|
namestr << ":";
|
|
|
|
namestr << targetFactor->GetString();
|
|
|
|
accumulator->PlusEquals(this,namestr.str(),1);
|
2012-03-04 02:20:04 +04:00
|
|
|
}*/
|
|
|
|
ostringstream namestr;
|
|
|
|
namestr << source.GetWord(0).GetFactor(m_sourceFactorId)->GetString();
|
|
|
|
for (size_t i = 1; i < source.GetSize(); ++i) {
|
|
|
|
const Factor* sourceFactor = source.GetWord(i).GetFactor(m_sourceFactorId);
|
|
|
|
namestr << ",";
|
|
|
|
namestr << sourceFactor->GetString();
|
|
|
|
}
|
|
|
|
namestr << "~";
|
|
|
|
namestr << target.GetWord(0).GetFactor(m_targetFactorId)->GetString();
|
|
|
|
for (size_t i = 1; i < target.GetSize(); ++i) {
|
|
|
|
const Factor* targetFactor = target.GetWord(i).GetFactor(m_targetFactorId);
|
|
|
|
namestr << ",";
|
|
|
|
namestr << targetFactor->GetString();
|
|
|
|
}
|
|
|
|
accumulator->PlusEquals(this,namestr.str(),1);
|
2011-03-22 17:33:16 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
bool PhrasePairFeature::ComputeValueInTranslationOption() const {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
}
|