diff --git a/moses/src/Manager.cpp b/moses/src/Manager.cpp index 17176dd54..0ea951ea7 100755 --- a/moses/src/Manager.cpp +++ b/moses/src/Manager.cpp @@ -365,7 +365,7 @@ void Manager::CreatePossibleTranslations(const Phrase &phrase const FactorTypeSet &targetFactors = phraseDictionary.GetFactorsUsed(Target); // make sure new phrase isn't deallocated while we're using it - m_unknownPhrase.push_back(TargetPhrase(Target, phraseDictionary.GetId())); + m_unknownPhrase.push_back(TargetPhrase(Target, &phraseDictionary)); TargetPhrase &targetPhrase = m_unknownPhrase.back(); FactorArray &targetWord = targetPhrase.AddWord(); diff --git a/moses/src/PhraseDictionary.cpp b/moses/src/PhraseDictionary.cpp index ea3526bd0..3fb0e76b8 100755 --- a/moses/src/PhraseDictionary.cpp +++ b/moses/src/PhraseDictionary.cpp @@ -94,7 +94,7 @@ void PhraseDictionary::Load(const std::vector &input Phrase sourcePhrase(Source); sourcePhrase.CreateFromString( input, phraseVector, factorCollection); //target - TargetPhrase targetPhrase(Target, m_id); + TargetPhrase targetPhrase(Target, this); targetPhrase.CreateFromString( output, token[1], factorCollection); // component score, for n-best output diff --git a/moses/src/PhraseDictionary.h b/moses/src/PhraseDictionary.h index ca2a27c0b..7206bafd0 100755 --- a/moses/src/PhraseDictionary.h +++ b/moses/src/PhraseDictionary.h @@ -53,8 +53,8 @@ protected: public: PhraseDictionary(size_t id, size_t noScoreComponent) :m_id(id) - ,m_factorsUsed(2) ,m_noScoreComponent(noScoreComponent) + ,m_factorsUsed(2) { } ~PhraseDictionary(); diff --git a/moses/src/TargetPhrase.h b/moses/src/TargetPhrase.h index e7ff7d50f..0cf51072b 100644 --- a/moses/src/TargetPhrase.h +++ b/moses/src/TargetPhrase.h @@ -25,6 +25,8 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include "Phrase.h" #include "TransScoreComponent.h" +class PhraseDictionary; + class TargetPhrase: public Phrase { protected: @@ -34,10 +36,10 @@ protected: #endif public: - TargetPhrase(Language language, size_t idPhraseDictionary) + TargetPhrase(Language language, const PhraseDictionary *phraseDictionary) :Phrase(language) #ifdef N_BEST - ,m_scoreComponent(idPhraseDictionary) + ,m_scoreComponent(phraseDictionary) #endif { } diff --git a/moses/src/TransScoreComponent.cpp b/moses/src/TransScoreComponent.cpp new file mode 100644 index 000000000..cc41b969b --- /dev/null +++ b/moses/src/TransScoreComponent.cpp @@ -0,0 +1,33 @@ + +#include "TypeDef.h" +#include "Util.h" +#include "TransScoreComponent.h" +#include "PhraseDictionary.h" + +TransScoreComponent::TransScoreComponent(const PhraseDictionary *phraseDictionary) +{ + m_phraseDictionary = phraseDictionary; +} + +TransScoreComponent::TransScoreComponent(const TransScoreComponent ©) + :m_phraseDictionary(copy.m_phraseDictionary) +{ + for (size_t i = 0 ; i < NUM_PHRASE_SCORES ; i++) + { + m_scoreComponent[i] = copy[i]; + } +} + +void TransScoreComponent::Reset() +{ + for (size_t i = 0 ; i < NUM_PHRASE_SCORES ; i++) + { + m_scoreComponent[i] = 0; + } +} + +size_t TransScoreComponent::GetPhraseDictionaryId() const +{ + return m_phraseDictionary->GetId(); +} + diff --git a/moses/src/TransScoreComponent.h b/moses/src/TransScoreComponent.h index 8539f4747..f60bad27b 100644 --- a/moses/src/TransScoreComponent.h +++ b/moses/src/TransScoreComponent.h @@ -23,34 +23,23 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA #include -//typedef float TransScoreComponent[NUM_PHRASE_SCORES]; +class PhraseDictionary; class TransScoreComponent { protected: - size_t m_idPhraseDictionary; + const PhraseDictionary *m_phraseDictionary; float m_scoreComponent[NUM_PHRASE_SCORES]; public: TransScoreComponent() - { - } - TransScoreComponent(size_t idPhraseDictionary) - { - m_idPhraseDictionary = idPhraseDictionary; - } - TransScoreComponent(const TransScoreComponent ©) - { - m_idPhraseDictionary = copy.m_idPhraseDictionary; - for (size_t i = 0 ; i < NUM_PHRASE_SCORES ; i++) - { - m_scoreComponent[i] = copy[i]; - } + { // needed by TransScoreComponentCollection + // should try & get rid of it } + TransScoreComponent(const PhraseDictionary *phraseDictionary); + TransScoreComponent(const TransScoreComponent ©); + void Reset(); - inline size_t GetPhraseDictionaryId() const - { - return m_idPhraseDictionary; - } + size_t GetPhraseDictionaryId() const; float operator[](size_t index) const { @@ -61,13 +50,6 @@ 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 TransScoreComponent &compare) const { diff --git a/moses/src/TransScoreComponentCollection.h b/moses/src/TransScoreComponentCollection.h index 2ce4ad214..ae02787e5 100644 --- a/moses/src/TransScoreComponentCollection.h +++ b/moses/src/TransScoreComponentCollection.h @@ -47,7 +47,7 @@ public: } TransScoreComponent &Add(const PhraseDictionary &phraseDictionary) { - return Add(TransScoreComponent(phraseDictionary.GetId())); + return Add(TransScoreComponent(&phraseDictionary)); } };