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 "Phrase.h"
#include "LatticeEdge.h"
#include "TransScoreComponent.h"
#include "ScoreComponent.h"
class Arc : public LatticeEdge
{
@ -34,7 +34,7 @@ public:
Arc(const Arc &arc); // not implemented
Arc( const float score[NUM_SCORES]
, const TransScoreComponentCollection &transScoreComponent
, const ScoreComponentCollection &transScoreComponent
, const ScoreColl &lmScoreComponent
, const ScoreColl &generationScoreColl
, const Phrase &phrase

View File

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

View File

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

View File

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

View File

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

View File

@ -35,7 +35,7 @@ LatticePath::LatticePath(const Hypothesis *hypo)
}
#ifdef N_BEST
m_lmScoreComponent = hypo->GetLMScoreComponent();
m_transScoreComponent = hypo->GetTransScoreComponent();
m_transScoreComponent = hypo->GetScoreComponent();
m_generationScoreComponent = hypo->GetGenerationScoreComponent();
#endif
@ -104,23 +104,23 @@ void LatticePath::CalcScore(const LatticePath &copy, size_t edgeIndex, const Arc
}
// phrase trans
m_transScoreComponent = copy.GetTransScoreComponent();
m_transScoreComponent = copy.GetScoreComponent();
const TransScoreComponentCollection
&arcComponent = arc->GetTransScoreComponent()
,&copyComponent = copy.m_path[edgeIndex]->GetTransScoreComponent()
,&totalComponent= copy.GetTransScoreComponent();
const ScoreComponentCollection
&arcComponent = arc->GetScoreComponent()
,&copyComponent = copy.m_path[edgeIndex]->GetScoreComponent()
,&totalComponent= copy.GetScoreComponent();
TransScoreComponentCollection::iterator iterTrans;
ScoreComponentCollection::iterator iterTrans;
for (iterTrans = m_transScoreComponent.begin() ; iterTrans != m_transScoreComponent.end() ; ++iterTrans)
{
const PhraseDictionary *phraseDictionary = iterTrans->first;
TransScoreComponent &transScore = *iterTrans->second;
ScoreComponent &transScore = *iterTrans->second;
const size_t noScoreComponent = phraseDictionary->GetNoScoreComponent();
const TransScoreComponent &arcScore = arcComponent.GetTransScoreComponent(phraseDictionary)
,&copyScore = copyComponent.GetTransScoreComponent(phraseDictionary)
,&totalScore = totalComponent.GetTransScoreComponent(phraseDictionary);
const ScoreComponent &arcScore = arcComponent.GetScoreComponent(phraseDictionary)
,&copyScore = copyComponent.GetScoreComponent(phraseDictionary)
,&totalScore = totalComponent.GetScoreComponent(phraseDictionary);
for (size_t i = 0 ; i < noScoreComponent ; 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 "Hypothesis.h"
#include "TypeDef.h"
#include "TransScoreComponent.h"
#include "ScoreComponent.h"
#include "ScoreColl.h"
class Arc;
@ -42,7 +42,7 @@ protected:
size_t m_prevEdgeChanged;
float m_score[NUM_SCORES];
TransScoreComponentCollection m_transScoreComponent;
ScoreComponentCollection m_transScoreComponent;
ScoreColl m_generationScoreComponent
, m_lmScoreComponent;
@ -86,7 +86,7 @@ public:
{
return m_lmScoreComponent.GetValue(index);
}
inline const TransScoreComponentCollection &GetTransScoreComponent() const
inline const ScoreComponentCollection &GetScoreComponent() const
{
return m_transScoreComponent;
}
@ -116,7 +116,7 @@ inline std::ostream& operator<<(std::ostream& out, const LatticePath& path)
}
out << "]";
#ifdef N_BEST
out << " " << path.GetTransScoreComponent();
out << " " << path.GetScoreComponent();
out << " " << path.GetGenerationScoreComponent();
#endif

View File

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

View File

@ -25,17 +25,17 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
class PhraseDictionary;
class TransScoreComponent
class ScoreComponent
{
protected:
const PhraseDictionary *m_phraseDictionary;
float *m_scoreComponent;
TransScoreComponent(); // not implemented
ScoreComponent(); // not implemented
public:
TransScoreComponent(const PhraseDictionary *phraseDictionary);
TransScoreComponent(const TransScoreComponent &copy);
~TransScoreComponent();
ScoreComponent(const PhraseDictionary *phraseDictionary);
ScoreComponent(const ScoreComponent &copy);
~ScoreComponent();
void Reset();
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 <map>
#include <assert.h>
#include "TransScoreComponent.h"
#include "ScoreComponent.h"
#include "PhraseDictionary.h"
class TransScoreComponentCollection : public std::map<const PhraseDictionary *, TransScoreComponent*>
class ScoreComponentCollection : public std::map<const PhraseDictionary *, ScoreComponent*>
{
public:
TransScoreComponent &GetTransScoreComponent(const PhraseDictionary *phraseDictionary)
ScoreComponent &GetScoreComponent(const PhraseDictionary *phraseDictionary)
{
TransScoreComponentCollection::iterator iter = find(phraseDictionary);
ScoreComponentCollection::iterator iter = find(phraseDictionary);
assert(iter != end());
return *iter->second;
}
~TransScoreComponentCollection()
~ScoreComponentCollection()
{ // ??? memory leak but double free
/* TransScoreComponentCollection::iterator iter;
/* ScoreComponentCollection::iterator iter;
for (iter = begin() ; iter != end() ; ++iter)
{
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();
TransScoreComponentCollection::iterator iter = find(phraseDictionary);
ScoreComponentCollection::iterator iter = find(phraseDictionary);
if (iter != end())
{ // already have scores for this phrase table. delete it 1st
delete iter->second;
erase(iter);
}
// add new into same place
TransScoreComponent *newTransScoreComponent = new TransScoreComponent(transScoreComponent);
operator[](phraseDictionary) = newTransScoreComponent;
ScoreComponent *newScoreComponent = new ScoreComponent(transScoreComponent);
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)
{
const PhraseDictionary *phraseDictionary = iter->first;
const TransScoreComponent &transScoreComponent = *iter->second;
const ScoreComponent &transScoreComponent = *iter->second;
out << "[" << phraseDictionary->GetId() << "=" << transScoreComponent << "] ";
}
return out;

View File

@ -23,7 +23,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include <vector>
#include "Phrase.h"
#include "TransScoreComponent.h"
#include "ScoreComponent.h"
class PhraseDictionary;
@ -32,7 +32,7 @@ class TargetPhrase: public Phrase
protected:
float m_score;
#ifdef N_BEST
TransScoreComponent m_scoreComponent;
ScoreComponent m_scoreComponent;
#endif
public:
@ -52,7 +52,7 @@ public:
void SetWeight(const std::vector<float> &weightT);
#ifdef N_BEST
inline const TransScoreComponent &GetScoreComponents() const
inline const ScoreComponent &GetScoreComponents() const
{
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 "Util.h"
#include "TransScoreComponent.h"
#include "ScoreComponent.h"
#include "PhraseDictionary.h"
TransScoreComponent::TransScoreComponent(const PhraseDictionary *phraseDictionary)
ScoreComponent::ScoreComponent(const PhraseDictionary *phraseDictionary)
: m_phraseDictionary(phraseDictionary)
{
m_scoreComponent = (float*) malloc(sizeof(float) * phraseDictionary->GetNoScoreComponent());
}
TransScoreComponent::TransScoreComponent(const TransScoreComponent &copy)
ScoreComponent::ScoreComponent(const ScoreComponent &copy)
:m_phraseDictionary(copy.m_phraseDictionary)
{
const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent();
@ -42,12 +42,12 @@ TransScoreComponent::TransScoreComponent(const TransScoreComponent &copy)
}
}
TransScoreComponent::~TransScoreComponent()
ScoreComponent::~ScoreComponent()
{
free(m_scoreComponent);
}
void TransScoreComponent::Reset()
void ScoreComponent::Reset()
{
const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent();
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();
}
std::ostream& operator<<(std::ostream &out, const TransScoreComponent &transScoreComponent)
std::ostream& operator<<(std::ostream &out, const ScoreComponent &transScoreComponent)
{
const size_t noScoreComponent = transScoreComponent.GetNoScoreComponent();
out << transScoreComponent[0];