mirror of
https://github.com/moses-smt/mosesdecoder.git
synced 2024-12-28 14:32:38 +03:00
rolled back variable number of translation component scores
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@69 1f5c12ca-751b-0410-a591-d2e778427230
This commit is contained in:
parent
04f0785810
commit
3e0e05ecde
@ -142,8 +142,8 @@ void IOCommandLine::SetNBest(const LatticePathList &nBestList, long translationI
|
||||
ScoreComponentCollection::const_iterator iterTrans;
|
||||
for (iterTrans = transScoreComponent.begin() ; iterTrans != transScoreComponent.end() ; ++iterTrans)
|
||||
{
|
||||
const ScoreComponent &transScore = *iterTrans->second;
|
||||
for (size_t i = 0 ; i < transScore.GetNoScoreComponent() ; i++)
|
||||
const ScoreComponent &transScore = iterTrans->second;
|
||||
for (size_t i = 0 ; i < NUM_PHRASE_SCORES ; i++)
|
||||
{
|
||||
m_nBestFile << transScore[i] << " ";
|
||||
}
|
||||
|
@ -386,14 +386,6 @@
|
||||
RelativePath=".\src\PhraseDictionary.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ScoreComponent.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\ScoreComponentCollection.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\Sentence.cpp"
|
||||
>
|
||||
|
@ -100,9 +100,8 @@ Hypothesis::Hypothesis(const Hypothesis &prevHypo, const TranslationOption &tran
|
||||
// add components specific to poss trans
|
||||
const ScoreComponent &possComponent = transOpt.GetScoreComponents();
|
||||
ScoreComponent &transComponent = m_transScoreComponent.GetScoreComponent(possComponent.GetPhraseDictionary());
|
||||
const size_t noScoreComponent = possComponent.GetNoScoreComponent();
|
||||
|
||||
for (size_t i = 0 ; i < noScoreComponent ; i++)
|
||||
for (size_t i = 0 ; i < NUM_PHRASE_SCORES ; i++)
|
||||
{
|
||||
transComponent[i] += possComponent[i];
|
||||
}
|
||||
|
@ -115,7 +115,7 @@ void LatticePath::CalcScore(const LatticePath ©, size_t edgeIndex, const Arc
|
||||
for (iterTrans = m_transScoreComponent.begin() ; iterTrans != m_transScoreComponent.end() ; ++iterTrans)
|
||||
{
|
||||
const PhraseDictionary *phraseDictionary = iterTrans->first;
|
||||
ScoreComponent &transScore = *iterTrans->second;
|
||||
ScoreComponent &transScore = iterTrans->second;
|
||||
const size_t noScoreComponent = phraseDictionary->GetNoScoreComponent();
|
||||
|
||||
const ScoreComponent &arcScore = arcComponent.GetScoreComponent(phraseDictionary)
|
||||
|
@ -1,74 +0,0 @@
|
||||
// $Id$
|
||||
|
||||
/***********************************************************************
|
||||
Moses - factored phrase-based language decoder
|
||||
Copyright (C) 2006 University of Edinburgh
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
***********************************************************************/
|
||||
|
||||
#include "TypeDef.h"
|
||||
#include "Util.h"
|
||||
#include "ScoreComponent.h"
|
||||
#include "PhraseDictionary.h"
|
||||
|
||||
ScoreComponent::ScoreComponent(const PhraseDictionary *phraseDictionary)
|
||||
: m_phraseDictionary(phraseDictionary)
|
||||
{
|
||||
m_scoreComponent = (float*) malloc(sizeof(float) * phraseDictionary->GetNoScoreComponent());
|
||||
}
|
||||
|
||||
ScoreComponent::ScoreComponent(const ScoreComponent ©)
|
||||
:m_phraseDictionary(copy.m_phraseDictionary)
|
||||
{
|
||||
const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent();
|
||||
m_scoreComponent = (float*) malloc(sizeof(float) * noScoreComponent);
|
||||
|
||||
for (size_t i = 0 ; i < noScoreComponent ; i++)
|
||||
{
|
||||
m_scoreComponent[i] = copy[i];
|
||||
}
|
||||
}
|
||||
|
||||
ScoreComponent::~ScoreComponent()
|
||||
{
|
||||
free(m_scoreComponent);
|
||||
}
|
||||
|
||||
void ScoreComponent::Reset()
|
||||
{
|
||||
const size_t noScoreComponent = m_phraseDictionary->GetNoScoreComponent();
|
||||
for (size_t i = 0 ; i < noScoreComponent ; i++)
|
||||
{
|
||||
m_scoreComponent[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
size_t ScoreComponent::GetNoScoreComponent() const
|
||||
{
|
||||
return m_phraseDictionary->GetNoScoreComponent();
|
||||
}
|
||||
|
||||
std::ostream& operator<<(std::ostream &out, const ScoreComponent &transScoreComponent)
|
||||
{
|
||||
const size_t noScoreComponent = transScoreComponent.GetNoScoreComponent();
|
||||
out << transScoreComponent[0];
|
||||
for (size_t i = 1 ; i < noScoreComponent ; i++)
|
||||
{
|
||||
out << "," << (float) transScoreComponent[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
@ -22,6 +22,9 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#pragma once
|
||||
|
||||
#include <iostream>
|
||||
#include "TypeDef.h"
|
||||
|
||||
//typedef float ScoreComponent[NUM_PHRASE_SCORES];
|
||||
|
||||
class PhraseDictionary;
|
||||
|
||||
@ -29,20 +32,28 @@ class ScoreComponent
|
||||
{
|
||||
protected:
|
||||
const PhraseDictionary *m_phraseDictionary;
|
||||
float *m_scoreComponent;
|
||||
|
||||
ScoreComponent(); // not implemented
|
||||
float m_scoreComponent[NUM_PHRASE_SCORES];
|
||||
public:
|
||||
ScoreComponent(const PhraseDictionary *phraseDictionary);
|
||||
ScoreComponent(const ScoreComponent ©);
|
||||
~ScoreComponent();
|
||||
void Reset();
|
||||
ScoreComponent()
|
||||
{
|
||||
}
|
||||
ScoreComponent(const PhraseDictionary *phraseDictionary)
|
||||
:m_phraseDictionary(phraseDictionary)
|
||||
{
|
||||
}
|
||||
ScoreComponent(const ScoreComponent ©)
|
||||
{
|
||||
m_phraseDictionary = copy.m_phraseDictionary;
|
||||
for (size_t i = 0 ; i < NUM_PHRASE_SCORES ; i++)
|
||||
{
|
||||
m_scoreComponent[i] = copy[i];
|
||||
}
|
||||
}
|
||||
|
||||
const PhraseDictionary *GetPhraseDictionary() const
|
||||
inline const PhraseDictionary * GetPhraseDictionary() const
|
||||
{
|
||||
return m_phraseDictionary;
|
||||
}
|
||||
size_t GetNoScoreComponent() const;
|
||||
|
||||
float operator[](size_t index) const
|
||||
{
|
||||
@ -52,6 +63,29 @@ public:
|
||||
{
|
||||
return m_scoreComponent[index];
|
||||
}
|
||||
|
||||
void Reset()
|
||||
{
|
||||
for (size_t i = 0 ; i < NUM_PHRASE_SCORES ; i++)
|
||||
{
|
||||
m_scoreComponent[i] = 0;
|
||||
}
|
||||
}
|
||||
|
||||
inline bool operator< (const ScoreComponent &compare) const
|
||||
{
|
||||
return GetPhraseDictionary() < compare.GetPhraseDictionary();
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream &out, const ScoreComponent &transScoreComponent);
|
||||
inline std::ostream& operator<<(std::ostream &out, const ScoreComponent &transScoreComponent)
|
||||
{
|
||||
out << transScoreComponent[0];
|
||||
for (size_t i = 1 ; i < NUM_PHRASE_SCORES ; i++)
|
||||
{
|
||||
out << "," << transScoreComponent[i];
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
|
@ -1,32 +0,0 @@
|
||||
// $Id$
|
||||
|
||||
/***********************************************************************
|
||||
Moses - factored phrase-based language decoder
|
||||
Copyright (C) 2006 University of Edinburgh
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation; either
|
||||
version 2.1 of the License, or (at your option) any later version.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
***********************************************************************/
|
||||
|
||||
#include "ScoreComponentCollection.h"
|
||||
|
||||
ScoreComponentCollection::ScoreComponentCollection(const ScoreComponentCollection ©)
|
||||
{
|
||||
ScoreComponentCollection::const_iterator iter;
|
||||
for (iter = copy.begin() ; iter != copy.end() ; ++iter)
|
||||
{
|
||||
const ScoreComponent *origScoreComponent = iter->second;
|
||||
Add(*origScoreComponent);
|
||||
}
|
||||
}
|
@ -25,68 +25,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
#include <map>
|
||||
#include <assert.h>
|
||||
#include "ScoreComponent.h"
|
||||
#include "PhraseDictionary.h"
|
||||
|
||||
class ScoreComponentCollection : public std::map<const PhraseDictionary *, ScoreComponent*>
|
||||
class PhraseDictionary;
|
||||
|
||||
class ScoreComponentCollection : public std::map<const PhraseDictionary *, ScoreComponent>
|
||||
{
|
||||
public:
|
||||
ScoreComponentCollection()
|
||||
ScoreComponent &GetScoreComponent(const PhraseDictionary *index)
|
||||
{
|
||||
}
|
||||
ScoreComponentCollection(const ScoreComponentCollection ©);
|
||||
|
||||
~ScoreComponentCollection()
|
||||
{ // ??? memory leak but double free
|
||||
/* TRACE_ERR(this << std::endl);
|
||||
ScoreComponentCollection::iterator iter;
|
||||
for (iter = begin() ; iter != end() ; ++iter)
|
||||
{
|
||||
TRACE_ERR(iter->second << std::endl);
|
||||
TRACE_ERR(*iter->second << std::endl);
|
||||
delete iter->second;
|
||||
}
|
||||
*/ }
|
||||
|
||||
ScoreComponent &GetScoreComponent(const PhraseDictionary *phraseDictionary)
|
||||
{
|
||||
ScoreComponentCollection::iterator iter = find(phraseDictionary);
|
||||
ScoreComponentCollection::iterator iter = find(index);
|
||||
assert(iter != end());
|
||||
return *iter->second;
|
||||
return iter->second;
|
||||
}
|
||||
|
||||
const ScoreComponent &GetScoreComponent(const PhraseDictionary *phraseDictionary) const
|
||||
{
|
||||
return const_cast<ScoreComponentCollection*>(this)->GetScoreComponent(phraseDictionary);
|
||||
}
|
||||
|
||||
ScoreComponent &Add(const ScoreComponent &transScoreComponent)
|
||||
{
|
||||
const PhraseDictionary *phraseDictionary = transScoreComponent.GetPhraseDictionary();
|
||||
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
|
||||
ScoreComponent *newScoreComponent = new ScoreComponent(transScoreComponent);
|
||||
operator[](phraseDictionary) = newScoreComponent;
|
||||
|
||||
return *newScoreComponent;
|
||||
return operator[](phraseDictionary) = transScoreComponent;
|
||||
}
|
||||
ScoreComponent &Add(const PhraseDictionary *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
|
||||
ScoreComponent *newScoreComponent = new ScoreComponent(phraseDictionary);
|
||||
operator[](phraseDictionary) = newScoreComponent;
|
||||
|
||||
return *newScoreComponent;
|
||||
return Add(ScoreComponent(phraseDictionary));
|
||||
}
|
||||
};
|
||||
|
||||
@ -95,7 +57,7 @@ inline std::ostream& operator<<(std::ostream &out, const ScoreComponentCollectio
|
||||
ScoreComponentCollection::const_iterator iter;
|
||||
for (iter = transScoreComponentColl.begin() ; iter != transScoreComponentColl.end() ; ++iter)
|
||||
{
|
||||
const ScoreComponent &transScoreComponent = *iter->second;
|
||||
const ScoreComponent &transScoreComponent = iter->second;
|
||||
out << "[" << transScoreComponent << "] ";
|
||||
}
|
||||
return out;
|
||||
|
@ -31,6 +31,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
|
||||
#define NOT_FOUND std::numeric_limits<size_t>::max()
|
||||
|
||||
const size_t NUM_PHRASE_SCORES = 5;
|
||||
const size_t DEFAULT_MAX_HYPOSTACK_SIZE = 200;
|
||||
const size_t ARRAY_SIZE_INCR = 20; //amount by which a hypostack gets resized when necessary
|
||||
const float LOWEST_SCORE = -100.0f;
|
||||
|
Loading…
Reference in New Issue
Block a user