mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-08 20:46:59 +03:00
EmptyHypothesisState()
This commit is contained in:
parent
63f13edec3
commit
656b484442
@ -56,9 +56,9 @@ Moses::FFState* Distortion::BlankState(const Manager &mgr, const PhraseImpl &inp
|
|||||||
return new (pool.Allocate<DistortionState_traditional>()) DistortionState_traditional();
|
return new (pool.Allocate<DistortionState_traditional>()) DistortionState_traditional();
|
||||||
}
|
}
|
||||||
|
|
||||||
Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
|
void Distortion::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const
|
||||||
{
|
{
|
||||||
MemPool &pool = mgr.GetPool();
|
DistortionState_traditional &stateCast = static_cast<DistortionState_traditional&>(state);
|
||||||
|
|
||||||
// fake previous translated phrase start and end
|
// fake previous translated phrase start and end
|
||||||
size_t start = NOT_FOUND;
|
size_t start = NOT_FOUND;
|
||||||
@ -70,10 +70,9 @@ Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const Phras
|
|||||||
end = input.m_frontSpanCoveredLength -1;
|
end = input.m_frontSpanCoveredLength -1;
|
||||||
}
|
}
|
||||||
*/
|
*/
|
||||||
return new (pool.Allocate<DistortionState_traditional>()) DistortionState_traditional(
|
|
||||||
Moses::Range(start, end),
|
|
||||||
NOT_FOUND);
|
|
||||||
|
|
||||||
|
stateCast.range = Moses::Range(start, end);
|
||||||
|
stateCast.first_gap = NOT_FOUND;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -19,7 +19,7 @@ public:
|
|||||||
virtual ~Distortion();
|
virtual ~Distortion();
|
||||||
|
|
||||||
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
||||||
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
EvaluateInIsolation(const System &system,
|
EvaluateInIsolation(const System &system,
|
||||||
|
@ -10,23 +10,20 @@
|
|||||||
|
|
||||||
class SkeletonState : public Moses::FFState
|
class SkeletonState : public Moses::FFState
|
||||||
{
|
{
|
||||||
int m_targetLen;
|
|
||||||
public:
|
public:
|
||||||
|
int targetLen;
|
||||||
|
|
||||||
SkeletonState()
|
SkeletonState()
|
||||||
{
|
{
|
||||||
// uninitialised
|
// uninitialised
|
||||||
}
|
}
|
||||||
|
|
||||||
SkeletonState(int targetLen)
|
|
||||||
:m_targetLen(targetLen) {
|
|
||||||
}
|
|
||||||
|
|
||||||
virtual size_t hash() const {
|
virtual size_t hash() const {
|
||||||
return (size_t) m_targetLen;
|
return (size_t) targetLen;
|
||||||
}
|
}
|
||||||
virtual bool operator==(const Moses::FFState& o) const {
|
virtual bool operator==(const Moses::FFState& o) const {
|
||||||
const SkeletonState& other = static_cast<const SkeletonState&>(o);
|
const SkeletonState& other = static_cast<const SkeletonState&>(o);
|
||||||
return m_targetLen == other.m_targetLen;
|
return targetLen == other.targetLen;
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -48,10 +45,10 @@ Moses::FFState* SkeletonStatefulFF::BlankState(const Manager &mgr, const PhraseI
|
|||||||
return new (pool.Allocate<SkeletonState>()) SkeletonState();
|
return new (pool.Allocate<SkeletonState>()) SkeletonState();
|
||||||
}
|
}
|
||||||
|
|
||||||
Moses::FFState* SkeletonStatefulFF::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
|
void SkeletonStatefulFF::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const
|
||||||
{
|
{
|
||||||
MemPool &pool = mgr.GetPool();
|
SkeletonState &stateCast = static_cast<SkeletonState&>(state);
|
||||||
return new (pool.Allocate<SkeletonState>()) SkeletonState(0);
|
stateCast.targetLen = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -17,7 +17,7 @@ public:
|
|||||||
virtual ~SkeletonStatefulFF();
|
virtual ~SkeletonStatefulFF();
|
||||||
|
|
||||||
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
||||||
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
EvaluateInIsolation(const System &system,
|
EvaluateInIsolation(const System &system,
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const = 0;
|
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const = 0;
|
||||||
|
|
||||||
//! return the state associated with the empty hypothesis for a given sentence
|
//! return the state associated with the empty hypothesis for a given sentence
|
||||||
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const = 0;
|
virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const = 0;
|
||||||
|
|
||||||
virtual Moses::FFState* EvaluateWhenApplied(const Manager &mgr,
|
virtual Moses::FFState* EvaluateWhenApplied(const Manager &mgr,
|
||||||
const Hypothesis &hypo,
|
const Hypothesis &hypo,
|
||||||
|
@ -107,12 +107,10 @@ Moses::FFState* KENLM::BlankState(const Manager &mgr, const PhraseImpl &input) c
|
|||||||
}
|
}
|
||||||
|
|
||||||
//! return the state associated with the empty hypothesis for a given sentence
|
//! return the state associated with the empty hypothesis for a given sentence
|
||||||
Moses::FFState* KENLM::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
|
void KENLM::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const
|
||||||
{
|
{
|
||||||
MemPool &pool = mgr.GetPool();
|
KenLMState &stateCast = static_cast<KenLMState&>(state);
|
||||||
KenLMState *ret = new (pool.Allocate<KenLMState>()) KenLMState();
|
stateCast.state = m_ngram->BeginSentenceState();
|
||||||
ret->state = m_ngram->BeginSentenceState();
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -26,7 +26,7 @@ public:
|
|||||||
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
||||||
|
|
||||||
//! return the state associated with the empty hypothesis for a given sentence
|
//! return the state associated with the empty hypothesis for a given sentence
|
||||||
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
EvaluateInIsolation(const System &system,
|
EvaluateInIsolation(const System &system,
|
||||||
|
@ -25,14 +25,6 @@ struct LMState : public Moses::PointerState
|
|||||||
// uninitialised
|
// uninitialised
|
||||||
}
|
}
|
||||||
|
|
||||||
LMState(MemPool &pool, const Moses::Factor *eos)
|
|
||||||
:PointerState(NULL)
|
|
||||||
{
|
|
||||||
numWords = 1;
|
|
||||||
lastWords = (const Moses::Factor**) pool.Allocate(sizeof(const Moses::Factor*));
|
|
||||||
lastWords[0] = eos;
|
|
||||||
}
|
|
||||||
|
|
||||||
LMState(MemPool &pool, void *lms, const std::vector<const Moses::Factor*> &context)
|
LMState(MemPool &pool, void *lms, const std::vector<const Moses::Factor*> &context)
|
||||||
:PointerState(lms)
|
:PointerState(lms)
|
||||||
{
|
{
|
||||||
@ -43,6 +35,14 @@ struct LMState : public Moses::PointerState
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Init(MemPool &pool, const Moses::Factor *factor)
|
||||||
|
{
|
||||||
|
lmstate = NULL;
|
||||||
|
numWords = 1;
|
||||||
|
lastWords = (const Moses::Factor**) pool.Allocate(sizeof(const Moses::Factor*));
|
||||||
|
lastWords[0] = factor;
|
||||||
|
}
|
||||||
|
|
||||||
size_t numWords;
|
size_t numWords;
|
||||||
const Moses::Factor** lastWords;
|
const Moses::Factor** lastWords;
|
||||||
};
|
};
|
||||||
@ -129,10 +129,12 @@ Moses::FFState* LanguageModel::BlankState(const Manager &mgr, const PhraseImpl &
|
|||||||
return new (pool.Allocate<LMState>()) LMState();
|
return new (pool.Allocate<LMState>()) LMState();
|
||||||
}
|
}
|
||||||
|
|
||||||
Moses::FFState* LanguageModel::EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const
|
void LanguageModel::EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const
|
||||||
{
|
{
|
||||||
|
LMState &stateCast = static_cast<LMState&>(state);
|
||||||
|
|
||||||
MemPool &pool = mgr.GetPool();
|
MemPool &pool = mgr.GetPool();
|
||||||
return new (pool.Allocate<LMState>()) LMState(pool, m_bos);
|
stateCast.Init(pool, m_bos);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -51,7 +51,7 @@ public:
|
|||||||
virtual void SetParameter(const std::string& key, const std::string& value);
|
virtual void SetParameter(const std::string& key, const std::string& value);
|
||||||
|
|
||||||
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
||||||
virtual Moses::FFState* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
|
virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const;
|
||||||
|
|
||||||
virtual void
|
virtual void
|
||||||
EvaluateInIsolation(const System &system,
|
EvaluateInIsolation(const System &system,
|
||||||
|
@ -135,8 +135,8 @@ void Hypothesis::EmptyHypothesisState(const PhraseImpl &input)
|
|||||||
const std::vector<const StatefulFeatureFunction*> &sfffs = m_mgr.GetSystem().featureFunctions.GetStatefulFeatureFunctions();
|
const std::vector<const StatefulFeatureFunction*> &sfffs = m_mgr.GetSystem().featureFunctions.GetStatefulFeatureFunctions();
|
||||||
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) {
|
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) {
|
||||||
size_t statefulInd = sfff->GetStatefulInd();
|
size_t statefulInd = sfff->GetStatefulInd();
|
||||||
Moses::FFState *state = sfff->EmptyHypothesisState(m_mgr, input);
|
Moses::FFState *state = m_ffStates[statefulInd];
|
||||||
m_ffStates[statefulInd] = state;
|
sfff->EmptyHypothesisState(*state, m_mgr, input);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user