2016-04-26 13:40:57 +03:00
|
|
|
/*
|
|
|
|
* TargetPhrase.h
|
|
|
|
*
|
|
|
|
* Created on: 26 Apr 2016
|
|
|
|
* Author: hieu
|
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
2016-06-20 16:59:31 +03:00
|
|
|
#include <sstream>
|
2016-04-27 10:53:51 +03:00
|
|
|
#include "PhraseImplTemplate.h"
|
2016-04-26 16:47:31 +03:00
|
|
|
#include "System.h"
|
|
|
|
#include "Scores.h"
|
2016-04-26 13:40:57 +03:00
|
|
|
|
|
|
|
namespace Moses2
|
|
|
|
{
|
|
|
|
|
2016-04-26 22:53:53 +03:00
|
|
|
template<typename WORD>
|
2016-04-27 10:53:51 +03:00
|
|
|
class TargetPhrase: public PhraseImplTemplate<WORD>
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
const PhraseTable &pt;
|
|
|
|
mutable void **ffData;
|
|
|
|
SCORE *scoreProperties;
|
|
|
|
|
2016-04-27 10:53:51 +03:00
|
|
|
TargetPhrase(MemPool &pool, const PhraseTable &pt, const System &system, size_t size)
|
|
|
|
: PhraseImplTemplate<WORD>(pool, size)
|
|
|
|
, pt(pt)
|
2016-04-26 16:47:31 +03:00
|
|
|
, scoreProperties(NULL)
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
2016-04-26 16:47:31 +03:00
|
|
|
m_scores = new (pool.Allocate<Scores>()) Scores(system, pool,
|
|
|
|
system.featureFunctions.GetNumScores());
|
2016-04-26 13:40:57 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 16:47:31 +03:00
|
|
|
Scores &GetScores()
|
|
|
|
{ return *m_scores; }
|
|
|
|
|
2016-04-26 13:40:57 +03:00
|
|
|
const Scores &GetScores() const
|
2016-04-26 16:47:31 +03:00
|
|
|
{ return *m_scores; }
|
2016-04-26 13:40:57 +03:00
|
|
|
|
2016-07-15 18:35:38 +03:00
|
|
|
virtual SCORE GetScoreForPruning() const = 0;
|
|
|
|
|
2016-04-26 16:47:31 +03:00
|
|
|
SCORE *GetScoresProperty(int propertyInd) const
|
|
|
|
{ return scoreProperties ? scoreProperties + propertyInd : NULL; }
|
2016-04-26 13:40:57 +03:00
|
|
|
|
2016-08-26 13:04:22 +03:00
|
|
|
void OutputToStream(const Hypothesis &hypo, std::ostream &out) const
|
|
|
|
{
|
|
|
|
size_t size = PhraseImplTemplate<WORD>::GetSize();
|
|
|
|
if (size) {
|
|
|
|
(*this)[0].OutputToStream(out);
|
|
|
|
for (size_t i = 1; i < size; ++i) {
|
|
|
|
const WORD &word = (*this)[i];
|
|
|
|
out << " BOO:";
|
|
|
|
word.OutputToStream(out);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-06-20 16:59:31 +03:00
|
|
|
virtual std::string Debug(const System &system) const
|
2016-06-11 00:03:11 +03:00
|
|
|
{
|
2016-06-20 16:59:31 +03:00
|
|
|
std::stringstream out;
|
|
|
|
out << Phrase<WORD>::Debug(system);
|
|
|
|
out << " SCORES:" << GetScores().Debug(system);
|
2016-06-18 00:54:32 +03:00
|
|
|
|
2016-06-20 16:59:31 +03:00
|
|
|
return out.str();
|
2016-06-11 00:03:11 +03:00
|
|
|
}
|
|
|
|
|
2016-04-26 13:40:57 +03:00
|
|
|
protected:
|
|
|
|
Scores *m_scores;
|
|
|
|
};
|
|
|
|
|
2016-04-26 16:47:31 +03:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
2016-06-13 15:59:26 +03:00
|
|
|
template<typename TP>
|
2016-07-15 18:35:38 +03:00
|
|
|
struct CompareScoreForPruning
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
2016-06-13 15:59:26 +03:00
|
|
|
bool operator()(const TP *a, const TP *b) const
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
2016-07-15 18:35:38 +03:00
|
|
|
return a->GetScoreForPruning() > b->GetScoreForPruning();
|
2016-04-26 13:40:57 +03:00
|
|
|
}
|
|
|
|
|
2016-06-13 15:59:26 +03:00
|
|
|
bool operator()(const TP &a, const TP &b) const
|
2016-04-26 13:40:57 +03:00
|
|
|
{
|
2016-07-15 18:35:38 +03:00
|
|
|
return a.GetScoreForPruning() > b.GetScoreForPruning();
|
2016-04-26 13:40:57 +03:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
} /* namespace Moses2a */
|
|
|
|
|