File size: 2,937 Bytes
158b61b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
/*
* Hypothesis.h
*
* Created on: 24 Oct 2015
* Author: hieu
*/
#pragma once
#include <iostream>
#include <cstddef>
#include "../FF/FFState.h"
#include "../legacy/Bitmap.h"
#include "../legacy/Range.h"
#include "../Scores.h"
#include "../Phrase.h"
#include "../TargetPhrase.h"
#include "../InputPathBase.h"
#include "../HypothesisBase.h"
namespace Moses2
{
class Manager;
class InputType;
class StatefulFeatureFunction;
class TargetPhraseImpl;
class Hypothesis: public HypothesisBase
{
Hypothesis(MemPool &pool, const System &system);
public:
static Hypothesis *Create(MemPool &pool, Manager &mgr);
virtual ~Hypothesis();
// initial, empty hypo
void Init(Manager &mgr, const InputPathBase &path, const TargetPhraseImpl &tp,
const Bitmap &bitmap);
void Init(Manager &mgr, const Hypothesis &prevHypo, const InputPathBase &path,
const TargetPhraseImpl &tp, const Bitmap &bitmap, SCORE estimatedScore);
size_t hash() const;
bool operator==(const Hypothesis &other) const;
inline const Bitmap &GetBitmap() const {
return *m_sourceCompleted;
}
inline const InputPathBase &GetInputPath() const {
return *m_path;
}
inline const Range &GetCurrTargetWordsRange() const {
return m_currTargetWordsRange;
}
SCORE GetFutureScore() const {
return GetScores().GetTotalScore() + m_estimatedScore;
}
const TargetPhrase<Moses2::Word> &GetTargetPhrase() const {
return *m_targetPhrase;
}
std::string Debug(const System &system) const;
virtual void OutputToStream(std::ostream &out) const;
void EmptyHypothesisState(const InputType &input);
void EvaluateWhenApplied();
void EvaluateWhenApplied(const StatefulFeatureFunction &sfff);
const Hypothesis* GetPrevHypo() const {
return m_prevHypo;
}
/** curr - pos is relative from CURRENT hypothesis's starting index
* (ie, start of sentence would be some negative number, which is
* not allowed- USE WITH CAUTION) */
inline const Word &GetCurrWord(size_t pos) const {
return GetTargetPhrase()[pos];
}
/** recursive - pos is relative from start of sentence */
const Word &GetWord(size_t pos) const;
void Swap(Hypothesis &other);
protected:
const TargetPhrase<Moses2::Word> *m_targetPhrase;
const Bitmap *m_sourceCompleted;
const InputPathBase *m_path;
const Hypothesis *m_prevHypo;
SCORE m_estimatedScore;
Range m_currTargetWordsRange;
};
////////////////////////////////////////////////////////////////////////////////////
class HypothesisTargetPhraseOrderer
{
public:
bool operator()(const Hypothesis* a, const Hypothesis* b) const {
PhraseOrdererLexical<Moses2::Word> phraseCmp;
bool ret = phraseCmp(a->GetTargetPhrase(), b->GetTargetPhrase());
/*
std::cerr << (const Phrase&) a->GetTargetPhrase() << " ||| "
<< (const Phrase&) b->GetTargetPhrase() << " ||| "
<< ret << std::endl;
*/
return ret;
}
};
}
|