diff options
author | Hieu Hoang <hieuhoang@gmail.com> | 2016-09-28 15:02:22 +0300 |
---|---|---|
committer | Hieu Hoang <hieuhoang@gmail.com> | 2016-09-28 15:02:22 +0300 |
commit | 6d276661e009bcf8a1e70e21b01564dc8b7c758e (patch) | |
tree | 3e3c462855c3d1a9a563f73209025e0cbbff140e | |
parent | aeecda9a8e5611f2900c4fd58ea7d93876c32700 (diff) |
refactor state info to work with moses2
-rw-r--r-- | contrib/moses2/FF/OSM/OpSequenceModel.cpp | 39 | ||||
-rw-r--r-- | contrib/moses2/FF/OSM/osmHyp.cpp | 15 | ||||
-rw-r--r-- | contrib/moses2/FF/OSM/osmHyp.h | 8 |
3 files changed, 19 insertions, 43 deletions
diff --git a/contrib/moses2/FF/OSM/OpSequenceModel.cpp b/contrib/moses2/FF/OSM/OpSequenceModel.cpp index 71818bb5a..572065813 100644 --- a/contrib/moses2/FF/OSM/OpSequenceModel.cpp +++ b/contrib/moses2/FF/OSM/OpSequenceModel.cpp @@ -13,34 +13,6 @@ using namespace std; namespace Moses2 { -class OSMState: public FFState -{ -public: - int targetLen; - - OSMState() - { - // uninitialised - } - - virtual size_t hash() const - { - return (size_t) targetLen; - } - virtual bool operator==(const FFState& o) const - { - const OSMState& other = static_cast<const OSMState&>(o); - return targetLen == other.targetLen; - } - - virtual std::string ToString() const - { - stringstream sb; - sb << targetLen; - return sb.str(); - } - -}; //////////////////////////////////////////////////////////////////////////////////////// @@ -67,15 +39,17 @@ void OpSequenceModel::Load(System &system) FFState* OpSequenceModel::BlankState(MemPool &pool, const System &sys) const { - return new (pool.Allocate<OSMState>()) OSMState(); + return new (pool.Allocate<osmState>()) osmState(); } void OpSequenceModel::EmptyHypothesisState(FFState &state, const ManagerBase &mgr, const InputType &input, const Hypothesis &hypo) const { - OSMState &stateCast = static_cast<OSMState&>(state); - stateCast.targetLen = 0; + lm::ngram::State startState = OSM->BeginSentenceState(); + + osmState &stateCast = static_cast<osmState&>(state); + stateCast.setState(startState); } void OpSequenceModel::EvaluateInIsolation(MemPool &pool, @@ -217,7 +191,8 @@ void OpSequenceModel::EvaluateWhenApplied(const ManagerBase &mgr, scores.PlusEquals(mgr.system, *this, scoresVec); - //return obj.saveState(); + osmState &stateCast = static_cast<osmState&>(state); + obj.saveState(stateCast); } void OpSequenceModel::EvaluateWhenApplied(const SCFG::Manager &mgr, diff --git a/contrib/moses2/FF/OSM/osmHyp.cpp b/contrib/moses2/FF/OSM/osmHyp.cpp index b78d33ea6..ede841a80 100644 --- a/contrib/moses2/FF/OSM/osmHyp.cpp +++ b/contrib/moses2/FF/OSM/osmHyp.cpp @@ -6,12 +6,11 @@ using namespace lm::ngram; namespace Moses2 { -osmState::osmState(const State & val) - :j(0) - ,E(0) +void osmState::setState(const lm::ngram::State & val) { + j = 0; + E = 0; lmState = val; - } void osmState::saveState(int jVal, int eVal, map <int , string> & gapVal) @@ -81,12 +80,10 @@ void osmHypothesis :: setState(const FFState* prev_state) } } -osmState * osmHypothesis :: saveState() +void osmHypothesis :: saveState(osmState &state) { - - osmState * statePtr = new osmState(lmState); - statePtr->saveState(j,E,gap); - return statePtr; + state.setState(lmState); + state.saveState(j,E,gap); } int osmHypothesis :: isTranslationOperation(int x) diff --git a/contrib/moses2/FF/OSM/osmHyp.h b/contrib/moses2/FF/OSM/osmHyp.h index a30c84837..c2893d366 100644 --- a/contrib/moses2/FF/OSM/osmHyp.h +++ b/contrib/moses2/FF/OSM/osmHyp.h @@ -14,7 +14,11 @@ namespace Moses2 class osmState : public FFState { public: - osmState(const lm::ngram::State & val); + osmState() + {} + + void setState(const lm::ngram::State & val); + virtual size_t hash() const; virtual bool operator==(const FFState& other) const; @@ -92,7 +96,7 @@ public: currE = val2; } void setState(const FFState* prev_state); - osmState * saveState(); + void saveState(osmState &state); void print(); void populateScores(std::vector <float> & scores , const int numFeatures); void setState(const lm::ngram::State & val) { |