variable number of translation component scores

git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@22 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
hieuhoang1972 2006-07-09 01:49:43 +00:00
parent 09e46ab211
commit 287cf55d8a
12 changed files with 68 additions and 68 deletions

View File

@ -24,7 +24,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <vector> #include <vector>
#include "Phrase.h" #include "Phrase.h"
#include "LatticeEdge.h" #include "LatticeEdge.h"
#include "TransScoreComponent.h" #include "ScoreComponent.h"
class Arc : public LatticeEdge class Arc : public LatticeEdge
{ {
@ -34,7 +34,7 @@ public:
Arc(const Arc &arc); // not implemented Arc(const Arc &arc); // not implemented
Arc( const float score[NUM_SCORES] Arc( const float score[NUM_SCORES]
, const TransScoreComponentCollection &transScoreComponent , const ScoreComponentCollection &transScoreComponent
, const ScoreColl &lmScoreComponent , const ScoreColl &lmScoreComponent
, const ScoreColl &generationScoreColl , const ScoreColl &generationScoreColl
, const Phrase &phrase , const Phrase &phrase

View File

@ -53,7 +53,7 @@ Hypothesis::Hypothesis(const Hypothesis &copy)
SetScore(copy.GetScore()); SetScore(copy.GetScore());
#ifdef N_BEST #ifdef N_BEST
m_lmScoreComponent = copy.GetLMScoreComponent(); m_lmScoreComponent = copy.GetLMScoreComponent();
m_transScoreComponent = copy.GetTransScoreComponent(); m_transScoreComponent = copy.GetScoreComponent();
m_generationScoreComponent = copy.GetGenerationScoreComponent(); m_generationScoreComponent = copy.GetGenerationScoreComponent();
#endif #endif
@ -94,12 +94,12 @@ Hypothesis::Hypothesis(const Hypothesis &prevHypo, const PossibleTranslation &po
} }
// translation score // translation score
const TransScoreComponentCollection &prevComponent= prevHypo.GetTransScoreComponent(); const ScoreComponentCollection &prevComponent= prevHypo.GetScoreComponent();
m_transScoreComponent = prevComponent; m_transScoreComponent = prevComponent;
// add components specific to poss trans // add components specific to poss trans
const TransScoreComponent &possComponent = possTrans.GetScoreComponents(); const ScoreComponent &possComponent = possTrans.GetScoreComponents();
TransScoreComponent &transComponent = m_transScoreComponent.GetTransScoreComponent(possComponent.GetPhraseDictionary()); ScoreComponent &transComponent = m_transScoreComponent.GetScoreComponent(possComponent.GetPhraseDictionary());
const size_t noScoreComponent = possComponent.GetNoScoreComponent(); const size_t noScoreComponent = possComponent.GetNoScoreComponent();
for (size_t i = 0 ; i < noScoreComponent ; i++) for (size_t i = 0 ; i < noScoreComponent ; i++)
@ -151,7 +151,7 @@ Hypothesis *Hypothesis::MergeNext(const PossibleTranslation &possTrans) const
} }
#ifdef N_BEST #ifdef N_BEST
const TransScoreComponent &possTransComponent = possTrans.GetScoreComponents(); const ScoreComponent &possTransComponent = possTrans.GetScoreComponents();
clone->m_transScoreComponent.Add(possTransComponent); clone->m_transScoreComponent.Add(possTransComponent);
#endif #endif
@ -439,7 +439,7 @@ ostream& operator<<(ostream& out, const Hypothesis& hypothesis)
} }
out << "]"; out << "]";
#ifdef N_BEST #ifdef N_BEST
out << " " << hypothesis.GetTransScoreComponent(); out << " " << hypothesis.GetScoreComponent();
out << " " << hypothesis.GetGenerationScoreComponent(); out << " " << hypothesis.GetGenerationScoreComponent();
#endif #endif
return out; return out;

View File

@ -32,7 +32,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "LanguageModel.h" #include "LanguageModel.h"
#include "Arc.h" #include "Arc.h"
#include "LatticeEdge.h" #include "LatticeEdge.h"
#include "TransScoreComponentCollection.h" #include "ScoreComponentCollection.h"
class SquareMatrix; class SquareMatrix;
class PossibleTranslation; class PossibleTranslation;
@ -150,7 +150,7 @@ public:
inline void AddArc(Hypothesis &loserHypo) inline void AddArc(Hypothesis &loserHypo)
{ {
Arc *arc = new Arc(loserHypo.m_score Arc *arc = new Arc(loserHypo.m_score
, loserHypo.GetTransScoreComponent() , loserHypo.GetScoreComponent()
, loserHypo.GetLMScoreComponent() , loserHypo.GetLMScoreComponent()
, loserHypo.GetGenerationScoreComponent() , loserHypo.GetGenerationScoreComponent()
, loserHypo.GetPhrase() , loserHypo.GetPhrase()

View File

@ -53,7 +53,7 @@ void LatticeEdge::ResizeComponentScore(const LMList &allLM, const list < DecodeS
{ {
case Translate: case Translate:
{ {
TransScoreComponent &transScoreComponent = m_transScoreComponent.Add(&step.GetPhraseDictionary()); ScoreComponent &transScoreComponent = m_transScoreComponent.Add(&step.GetPhraseDictionary());
transScoreComponent.Reset(); transScoreComponent.Reset();
break; break;
} }

View File

@ -25,8 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <list> #include <list>
#include "TypeDef.h" #include "TypeDef.h"
#include "Phrase.h" #include "Phrase.h"
#include "TransScoreComponent.h" #include "ScoreComponent.h"
#include "TransScoreComponentCollection.h" #include "ScoreComponentCollection.h"
#include "ScoreColl.h" #include "ScoreColl.h"
#include "DecodeStep.h" #include "DecodeStep.h"
@ -44,7 +44,7 @@ protected:
Phrase m_phrase; Phrase m_phrase;
#ifdef N_BEST #ifdef N_BEST
TransScoreComponentCollection m_transScoreComponent; ScoreComponentCollection m_transScoreComponent;
ScoreColl m_generationScoreComponent ScoreColl m_generationScoreComponent
,m_lmScoreComponent; ,m_lmScoreComponent;
#endif #endif
@ -52,7 +52,7 @@ protected:
public: public:
LatticeEdge(const LatticeEdge &edge); // not implemented LatticeEdge(const LatticeEdge &edge); // not implemented
LatticeEdge(const float score[NUM_SCORES] LatticeEdge(const float score[NUM_SCORES]
, const TransScoreComponentCollection &transScoreComponent , const ScoreComponentCollection &transScoreComponent
, const ScoreColl &lmScoreComponent , const ScoreColl &lmScoreComponent
, const ScoreColl &generationScoreComponent , const ScoreColl &generationScoreComponent
, const Phrase &phrase , const Phrase &phrase
@ -109,7 +109,7 @@ public:
#ifdef N_BEST #ifdef N_BEST
virtual const std::list<Arc*> &GetArcList() const = 0; virtual const std::list<Arc*> &GetArcList() const = 0;
inline const TransScoreComponentCollection &GetTransScoreComponent() const inline const ScoreComponentCollection &GetScoreComponent() const
{ {
return m_transScoreComponent; return m_transScoreComponent;
} }

View File

@ -35,7 +35,7 @@ LatticePath::LatticePath(const Hypothesis *hypo)
} }
#ifdef N_BEST #ifdef N_BEST
m_lmScoreComponent = hypo->GetLMScoreComponent(); m_lmScoreComponent = hypo->GetLMScoreComponent();
m_transScoreComponent = hypo->GetTransScoreComponent(); m_transScoreComponent = hypo->GetScoreComponent();
m_generationScoreComponent = hypo->GetGenerationScoreComponent(); m_generationScoreComponent = hypo->GetGenerationScoreComponent();
#endif #endif
@ -104,23 +104,23 @@ void LatticePath::CalcScore(const LatticePath &copy, size_t edgeIndex, const Arc
} }
// phrase trans // phrase trans
m_transScoreComponent = copy.GetTransScoreComponent(); m_transScoreComponent = copy.GetScoreComponent();
const TransScoreComponentCollection const ScoreComponentCollection
&arcComponent = arc->GetTransScoreComponent() &arcComponent = arc->GetScoreComponent()
,&copyComponent = copy.m_path[edgeIndex]->GetTransScoreComponent() ,&copyComponent = copy.m_path[edgeIndex]->GetScoreComponent()
,&totalComponent= copy.GetTransScoreComponent(); ,&totalComponent= copy.GetScoreComponent();
TransScoreComponentCollection::iterator iterTrans; ScoreComponentCollection::iterator iterTrans;
for (iterTrans = m_transScoreComponent.begin() ; iterTrans != m_transScoreComponent.end() ; ++iterTrans) for (iterTrans = m_transScoreComponent.begin() ; iterTrans != m_transScoreComponent.end() ; ++iterTrans)
{ {
const PhraseDictionary *phraseDictionary = iterTrans->first; const PhraseDictionary *phraseDictionary = iterTrans->first;
TransScoreComponent &transScore = *iterTrans->second; ScoreComponent &transScore = *iterTrans->second;
const size_t noScoreComponent = phraseDictionary->GetNoScoreComponent(); const size_t noScoreComponent = phraseDictionary->GetNoScoreComponent();
const TransScoreComponent &arcScore = arcComponent.GetTransScoreComponent(phraseDictionary) const ScoreComponent &arcScore = arcComponent.GetScoreComponent(phraseDictionary)
,&copyScore = copyComponent.GetTransScoreComponent(phraseDictionary) ,&copyScore = copyComponent.GetScoreComponent(phraseDictionary)
,&totalScore = totalComponent.GetTransScoreComponent(phraseDictionary); ,&totalScore = totalComponent.GetScoreComponent(phraseDictionary);
for (size_t i = 0 ; i < noScoreComponent ; i++) for (size_t i = 0 ; i < noScoreComponent ; i++)
{ {
float adj = arcScore[i] - copyScore[i]; float adj = arcScore[i] - copyScore[i];

View File

@ -27,7 +27,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "LatticeEdge.h" #include "LatticeEdge.h"
#include "Hypothesis.h" #include "Hypothesis.h"
#include "TypeDef.h" #include "TypeDef.h"
#include "TransScoreComponent.h" #include "ScoreComponent.h"
#include "ScoreColl.h" #include "ScoreColl.h"
class Arc; class Arc;
@ -42,7 +42,7 @@ protected:
size_t m_prevEdgeChanged; size_t m_prevEdgeChanged;
float m_score[NUM_SCORES]; float m_score[NUM_SCORES];
TransScoreComponentCollection m_transScoreComponent; ScoreComponentCollection m_transScoreComponent;
ScoreColl m_generationScoreComponent ScoreColl m_generationScoreComponent
, m_lmScoreComponent; , m_lmScoreComponent;
@ -86,7 +86,7 @@ public:
{ {
return m_lmScoreComponent.GetValue(index); return m_lmScoreComponent.GetValue(index);
} }
inline const TransScoreComponentCollection &GetTransScoreComponent() const inline const ScoreComponentCollection &GetScoreComponent() const
{ {
return m_transScoreComponent; return m_transScoreComponent;
} }
@ -116,7 +116,7 @@ inline std::ostream& operator<<(std::ostream& out, const LatticePath& path)
} }
out << "]"; out << "]";
#ifdef N_BEST #ifdef N_BEST
out << " " << path.GetTransScoreComponent(); out << " " << path.GetScoreComponent();
out << " " << path.GetGenerationScoreComponent(); out << " " << path.GetGenerationScoreComponent();
#endif #endif

View File

@ -26,7 +26,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "Hypothesis.h" #include "Hypothesis.h"
#include "Util.h" #include "Util.h"
#include "TypeDef.h" #include "TypeDef.h"
#include "TransScoreComponent.h" #include "ScoreComponent.h"
class PossibleTranslation class PossibleTranslation
{ {
@ -37,7 +37,7 @@ protected:
WordsRange m_wordsRange; WordsRange m_wordsRange;
float m_transScore, m_futureScore, m_ngramScore; float m_transScore, m_futureScore, m_ngramScore;
#ifdef N_BEST #ifdef N_BEST
TransScoreComponent m_transScoreComponent; ScoreComponent m_transScoreComponent;
std::list< std::pair<size_t, float> > m_lmScoreComponent; std::list< std::pair<size_t, float> > m_lmScoreComponent;
std::list< std::pair<size_t, float> > m_trigramComponent; std::list< std::pair<size_t, float> > m_trigramComponent;
#endif #endif
@ -89,7 +89,7 @@ public:
} }
#ifdef N_BEST #ifdef N_BEST
inline const TransScoreComponent &GetScoreComponents() const inline const ScoreComponent &GetScoreComponents() const
{ {
return m_transScoreComponent; return m_transScoreComponent;
} }

View File

@ -25,17 +25,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class PhraseDictionary; class PhraseDictionary;
class TransScoreComponent class ScoreComponent
{ {
protected: protected:
const PhraseDictionary *m_phraseDictionary; const PhraseDictionary *m_phraseDictionary;
float *m_scoreComponent; float *m_scoreComponent;
TransScoreComponent(); // not implemented ScoreComponent(); // not implemented
public: public:
TransScoreComponent(const PhraseDictionary *phraseDictionary); ScoreComponent(const PhraseDictionary *phraseDictionary);
TransScoreComponent(const TransScoreComponent &copy); ScoreComponent(const ScoreComponent &copy);
~TransScoreComponent(); ~ScoreComponent();
void Reset(); void Reset();
const PhraseDictionary *GetPhraseDictionary() const const PhraseDictionary *GetPhraseDictionary() const
@ -54,4 +54,4 @@ public:
} }
}; };
std::ostream& operator<<(std::ostream &out, const TransScoreComponent &transScoreComponent); std::ostream& operator<<(std::ostream &out, const ScoreComponent &transScoreComponent);

View File

@ -24,22 +24,22 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <iostream> #include <iostream>
#include <map> #include <map>
#include <assert.h> #include <assert.h>
#include "TransScoreComponent.h" #include "ScoreComponent.h"
#include "PhraseDictionary.h" #include "PhraseDictionary.h"
class TransScoreComponentCollection : public std::map<const PhraseDictionary *, TransScoreComponent*> class ScoreComponentCollection : public std::map<const PhraseDictionary *, ScoreComponent*>
{ {
public: public:
TransScoreComponent &GetTransScoreComponent(const PhraseDictionary *phraseDictionary) ScoreComponent &GetScoreComponent(const PhraseDictionary *phraseDictionary)
{ {
TransScoreComponentCollection::iterator iter = find(phraseDictionary); ScoreComponentCollection::iterator iter = find(phraseDictionary);
assert(iter != end()); assert(iter != end());
return *iter->second; return *iter->second;
} }
~TransScoreComponentCollection() ~ScoreComponentCollection()
{ // ??? memory leak but double free { // ??? memory leak but double free
/* TransScoreComponentCollection::iterator iter; /* ScoreComponentCollection::iterator iter;
for (iter = begin() ; iter != end() ; ++iter) for (iter = begin() ; iter != end() ; ++iter)
{ {
delete iter->second; delete iter->second;
@ -47,39 +47,39 @@ public:
*/ */
} }
const TransScoreComponent &GetTransScoreComponent(const PhraseDictionary *phraseDictionary) const const ScoreComponent &GetScoreComponent(const PhraseDictionary *phraseDictionary) const
{ {
return const_cast<TransScoreComponentCollection*>(this)->GetTransScoreComponent(phraseDictionary); return const_cast<ScoreComponentCollection*>(this)->GetScoreComponent(phraseDictionary);
} }
TransScoreComponent &Add(const TransScoreComponent &transScoreComponent) ScoreComponent &Add(const ScoreComponent &transScoreComponent)
{ {
const PhraseDictionary *phraseDictionary = transScoreComponent.GetPhraseDictionary(); const PhraseDictionary *phraseDictionary = transScoreComponent.GetPhraseDictionary();
TransScoreComponentCollection::iterator iter = find(phraseDictionary); ScoreComponentCollection::iterator iter = find(phraseDictionary);
if (iter != end()) if (iter != end())
{ // already have scores for this phrase table. delete it 1st { // already have scores for this phrase table. delete it 1st
delete iter->second; delete iter->second;
erase(iter); erase(iter);
} }
// add new into same place // add new into same place
TransScoreComponent *newTransScoreComponent = new TransScoreComponent(transScoreComponent); ScoreComponent *newScoreComponent = new ScoreComponent(transScoreComponent);
operator[](phraseDictionary) = newTransScoreComponent; operator[](phraseDictionary) = newScoreComponent;
return *newTransScoreComponent; return *newScoreComponent;
} }
TransScoreComponent &Add(const PhraseDictionary *phraseDictionary) ScoreComponent &Add(const PhraseDictionary *phraseDictionary)
{ {
return Add(TransScoreComponent(phraseDictionary)); return Add(ScoreComponent(phraseDictionary));
} }
}; };
inline std::ostream& operator<<(std::ostream &out, const TransScoreComponentCollection &transScoreComponentColl) inline std::ostream& operator<<(std::ostream &out, const ScoreComponentCollection &transScoreComponentColl)
{ {
TransScoreComponentCollection::const_iterator iter; ScoreComponentCollection::const_iterator iter;
for (iter = transScoreComponentColl.begin() ; iter != transScoreComponentColl.end() ; ++iter) for (iter = transScoreComponentColl.begin() ; iter != transScoreComponentColl.end() ; ++iter)
{ {
const PhraseDictionary *phraseDictionary = iter->first; const PhraseDictionary *phraseDictionary = iter->first;
const TransScoreComponent &transScoreComponent = *iter->second; const ScoreComponent &transScoreComponent = *iter->second;
out << "[" << phraseDictionary->GetId() << "=" << transScoreComponent << "] "; out << "[" << phraseDictionary->GetId() << "=" << transScoreComponent << "] ";
} }
return out; return out;

View File

@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <vector> #include <vector>
#include "Phrase.h" #include "Phrase.h"
#include "TransScoreComponent.h" #include "ScoreComponent.h"
class PhraseDictionary; class PhraseDictionary;
@ -32,7 +32,7 @@ class TargetPhrase: public Phrase
protected: protected:
float m_score; float m_score;
#ifdef N_BEST #ifdef N_BEST
TransScoreComponent m_scoreComponent; ScoreComponent m_scoreComponent;
#endif #endif
public: public:
@ -52,7 +52,7 @@ public:
void SetWeight(const std::vector<float> &weightT); void SetWeight(const std::vector<float> &weightT);
#ifdef N_BEST #ifdef N_BEST
inline const TransScoreComponent &GetScoreComponents() const inline const ScoreComponent &GetScoreComponents() const
{ {
return m_scoreComponent; return m_scoreComponent;
} }

View File

@ -21,16 +21,16 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "TypeDef.h" #include "TypeDef.h"
#include "Util.h" #include "Util.h"
#include "TransScoreComponent.h" #include "ScoreComponent.h"
#include "PhraseDictionary.h" #include "PhraseDictionary.h"
TransScoreComponent::TransScoreComponent(const PhraseDictionary *phraseDictionary) ScoreComponent::ScoreComponent(const PhraseDictionary *phraseDictionary)
: m_phraseDictionary(phraseDictionary) : m_phraseDictionary(phraseDictionary)
{ {
m_scoreComponent = (float*) malloc(sizeof(float) * phraseDictionary->GetNoScoreComponent()); m_scoreComponent = (float*) malloc(sizeof(float) * phraseDictionary->GetNoScoreComponent());
} }
TransScoreComponent::TransScoreComponent(const TransScoreComponent &copy) ScoreComponent::ScoreComponent(const ScoreComponent &copy)
:m_phraseDictionary(copy.m_phraseDictionary) :m_phraseDictionary(copy.m_phraseDictionary)
{ {
const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent(); const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent();
@ -42,12 +42,12 @@ TransScoreComponent::TransScoreComponent(const TransScoreComponent &copy)
} }
} }
TransScoreComponent::~TransScoreComponent() ScoreComponent::~ScoreComponent()
{ {
free(m_scoreComponent); free(m_scoreComponent);
} }
void TransScoreComponent::Reset() void ScoreComponent::Reset()
{ {
const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent(); const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent();
for (size_t i = 0 ; i < noScoreComponent ; i++) for (size_t i = 0 ; i < noScoreComponent ; i++)
@ -56,12 +56,12 @@ void TransScoreComponent::Reset()
} }
} }
size_t TransScoreComponent::GetNoScoreComponent() const size_t ScoreComponent::GetNoScoreComponent() const
{ {
return m_phraseDictionary->GetNoScoreComponent(); return m_phraseDictionary->GetNoScoreComponent();
} }
std::ostream& operator<<(std::ostream &out, const TransScoreComponent &transScoreComponent) std::ostream& operator<<(std::ostream &out, const ScoreComponent &transScoreComponent)
{ {
const size_t noScoreComponent = transScoreComponent.GetNoScoreComponent(); const size_t noScoreComponent = transScoreComponent.GetNoScoreComponent();
out << transScoreComponent[0]; out << transScoreComponent[0];