mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2025-01-06 19:49:41 +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();
|
||||
}
|
||||
|
||||
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
|
||||
size_t start = NOT_FOUND;
|
||||
@ -70,10 +70,9 @@ Moses::FFState* Distortion::EmptyHypothesisState(const Manager &mgr, const Phras
|
||||
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
|
||||
|
@ -19,7 +19,7 @@ public:
|
||||
virtual ~Distortion();
|
||||
|
||||
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
|
||||
EvaluateInIsolation(const System &system,
|
||||
|
@ -10,23 +10,20 @@
|
||||
|
||||
class SkeletonState : public Moses::FFState
|
||||
{
|
||||
int m_targetLen;
|
||||
public:
|
||||
int targetLen;
|
||||
|
||||
SkeletonState()
|
||||
{
|
||||
// uninitialised
|
||||
}
|
||||
|
||||
SkeletonState(int targetLen)
|
||||
:m_targetLen(targetLen) {
|
||||
}
|
||||
|
||||
virtual size_t hash() const {
|
||||
return (size_t) m_targetLen;
|
||||
return (size_t) targetLen;
|
||||
}
|
||||
virtual bool operator==(const Moses::FFState& o) const {
|
||||
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();
|
||||
}
|
||||
|
||||
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();
|
||||
return new (pool.Allocate<SkeletonState>()) SkeletonState(0);
|
||||
SkeletonState &stateCast = static_cast<SkeletonState&>(state);
|
||||
stateCast.targetLen = 0;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -17,7 +17,7 @@ public:
|
||||
virtual ~SkeletonStatefulFF();
|
||||
|
||||
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
|
||||
EvaluateInIsolation(const System &system,
|
||||
|
@ -28,7 +28,7 @@ public:
|
||||
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const = 0;
|
||||
|
||||
//! 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,
|
||||
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
|
||||
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 *ret = new (pool.Allocate<KenLMState>()) KenLMState();
|
||||
ret->state = m_ngram->BeginSentenceState();
|
||||
return ret;
|
||||
KenLMState &stateCast = static_cast<KenLMState&>(state);
|
||||
stateCast.state = m_ngram->BeginSentenceState();
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -26,7 +26,7 @@ public:
|
||||
virtual Moses::FFState* BlankState(const Manager &mgr, const PhraseImpl &input) const;
|
||||
|
||||
//! 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
|
||||
EvaluateInIsolation(const System &system,
|
||||
|
@ -25,14 +25,6 @@ struct LMState : public Moses::PointerState
|
||||
// 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)
|
||||
: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;
|
||||
const Moses::Factor** lastWords;
|
||||
};
|
||||
@ -129,10 +129,12 @@ Moses::FFState* LanguageModel::BlankState(const Manager &mgr, const PhraseImpl &
|
||||
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();
|
||||
return new (pool.Allocate<LMState>()) LMState(pool, m_bos);
|
||||
stateCast.Init(pool, m_bos);
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -51,7 +51,7 @@ public:
|
||||
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* EmptyHypothesisState(const Manager &mgr, const PhraseImpl &input) const;
|
||||
virtual void EmptyHypothesisState(Moses::FFState &state, const Manager &mgr, const PhraseImpl &input) const;
|
||||
|
||||
virtual void
|
||||
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();
|
||||
BOOST_FOREACH(const StatefulFeatureFunction *sfff, sfffs) {
|
||||
size_t statefulInd = sfff->GetStatefulInd();
|
||||
Moses::FFState *state = sfff->EmptyHypothesisState(m_mgr, input);
|
||||
m_ffStates[statefulInd] = state;
|
||||
Moses::FFState *state = m_ffStates[statefulInd];
|
||||
sfff->EmptyHypothesisState(*state, m_mgr, input);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user