mosesdecoder/contrib/moses2/TargetPhrase.h

109 lines
2.4 KiB
C
Raw Normal View History

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-08-26 13:50:12 +03:00
#include "AlignmentInfoCollection.h"
2016-04-26 13:40:57 +03:00
namespace Moses2
{
2016-08-26 13:50:12 +03:00
class AlignmentInfo;
2016-04-26 13:40:57 +03:00
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:
2016-08-26 13:50:12 +03:00
typedef PhraseImplTemplate<WORD> Parent;
2016-04-26 13:40:57 +03:00
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-08-26 13:50:12 +03:00
, m_alignTerm(&AlignmentInfoCollection::Instance().GetEmptyAlignmentInfo())
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:50:12 +03:00
const AlignmentInfo &GetAlignTerm() const {
return *m_alignTerm;
}
void SetAlignTerm(const AlignmentInfo &alignInfo) {
m_alignTerm = &alignInfo;
}
2016-08-26 13:59:46 +03:00
// ALNREP = alignment representation,
// see AlignmentInfo constructors for supported representations
template<typename ALNREP>
void
SetAlignTerm(const ALNREP &coll) {
m_alignTerm = AlignmentInfoCollection::Instance().Add(coll);
}
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-08-26 13:50:12 +03:00
const AlignmentInfo *m_alignTerm;
2016-04-26 13:40:57 +03:00
};
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 */