diff options
author | hieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-01 08:20:48 +0400 |
---|---|---|
committer | hieuhoang1972 <hieuhoang1972@1f5c12ca-751b-0410-a591-d2e778427230> | 2006-08-01 08:20:48 +0400 |
commit | 5d517ded747e8904570755bbefb32b9561795b26 (patch) | |
tree | 0d040b7ff59defe8000f6367e294745f45800c2e | |
parent | c4a6905fa98b4ba2cf67f171091e7bb47ab316ff (diff) |
rollback
git-svn-id: https://mosesdecoder.svn.sourceforge.net/svnroot/mosesdecoder/trunk@442 1f5c12ca-751b-0410-a591-d2e778427230
-rwxr-xr-x | moses/src/Hypothesis.cpp | 2 | ||||
-rwxr-xr-x | moses/src/TranslationOption.cpp | 28 | ||||
-rwxr-xr-x | moses/src/TranslationOption.h | 31 | ||||
-rw-r--r-- | moses/src/TranslationOptionCollection.cpp | 17 |
4 files changed, 41 insertions, 37 deletions
diff --git a/moses/src/Hypothesis.cpp b/moses/src/Hypothesis.cpp index 1bbb228f1..98e5e546c 100755 --- a/moses/src/Hypothesis.cpp +++ b/moses/src/Hypothesis.cpp @@ -68,7 +68,7 @@ Hypothesis::Hypothesis(const Hypothesis &prevHypo, const TranslationOption &tran , m_sourceInput (prevHypo.m_sourceInput) , m_currSourceWordsRange (transOpt.GetSourceWordsRange()) , m_currTargetWordsRange ( prevHypo.m_currTargetWordsRange.GetEndPos() + 1 - ,prevHypo.m_currTargetWordsRange.GetEndPos() + transOpt.GetTargetPhrase().GetSize()) + ,prevHypo.m_currTargetWordsRange.GetEndPos() + transOpt.GetPhrase().GetSize()) , m_totalScore(0.0f) , m_futureScore(0.0f) , m_wordDeleted(false) diff --git a/moses/src/TranslationOption.cpp b/moses/src/TranslationOption.cpp index 688271a67..7cc409401 100755 --- a/moses/src/TranslationOption.cpp +++ b/moses/src/TranslationOption.cpp @@ -28,30 +28,30 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA using namespace std; -TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetPhrase *targetPhrase) +TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetPhrase &targetPhrase) : m_phrase(targetPhrase) ,m_sourceWordsRange (wordsRange) { // used by initial translation step // set score m_scoreGen = 0; - m_scoreTrans = targetPhrase->GetTranslationScore(); - m_scoreBreakdown.PlusEquals(targetPhrase->GetScoreBreakdown()); + m_scoreTrans = targetPhrase.GetTranslationScore(); + m_scoreBreakdown.PlusEquals(targetPhrase.GetScoreBreakdown()); } -TranslationOption::TranslationOption(const TranslationOption ©, const TargetPhrase *targetPhrase) +TranslationOption::TranslationOption(const TranslationOption ©, const TargetPhrase &targetPhrase) : m_phrase(targetPhrase) ,m_sourceWordsRange (copy.m_sourceWordsRange) ,m_scoreBreakdown(copy.m_scoreBreakdown) { // used in creating the next translation step m_scoreGen = copy.GetGenerationScore(); - m_scoreTrans = copy.GetTranslationScore() + targetPhrase->GetTranslationScore(); + m_scoreTrans = copy.GetTranslationScore() + targetPhrase.GetTranslationScore(); - m_scoreBreakdown.PlusEquals(targetPhrase->GetScoreBreakdown()); + m_scoreBreakdown.PlusEquals(targetPhrase.GetScoreBreakdown()); } TranslationOption::TranslationOption(const TranslationOption © - , const Phrase *inputPhrase + , const Phrase &inputPhrase , const GenerationDictionary *generationDictionary , float generationScore , float weight) @@ -66,7 +66,7 @@ TranslationOption::TranslationOption(const TranslationOption © m_scoreBreakdown.PlusEquals(generationDictionary, generationScore); } -TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetPhrase *targetPhrase, int /*whatever*/) +TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetPhrase &targetPhrase, int /*whatever*/) : m_phrase(targetPhrase) ,m_sourceWordsRange (wordsRange) ,m_scoreTrans(0) @@ -78,10 +78,10 @@ TranslationOption::TranslationOption(const WordsRange &wordsRange, const TargetP TranslationOption *TranslationOption::MergeTranslation(const TargetPhrase &targetPhrase) const { - if (m_phrase->IsCompatible(targetPhrase)) + if (m_phrase.IsCompatible(targetPhrase)) { - TargetPhrase *mergePhrase = new TargetPhrase(targetPhrase); - mergePhrase->MergeFactors(*m_phrase); + TargetPhrase mergePhrase(targetPhrase); + mergePhrase.MergeFactors(m_phrase); TranslationOption *newTransOpt = new TranslationOption(*this, mergePhrase); return newTransOpt; } @@ -96,10 +96,10 @@ TranslationOption *TranslationOption::MergeGeneration(const Phrase &inputPhrase , float generationScore , float weight) const { - if (m_phrase->IsCompatible(inputPhrase)) + if (m_phrase.IsCompatible(inputPhrase)) { - Phrase *mergePhrase = new Phrase(inputPhrase); - mergePhrase->MergeFactors(*m_phrase); + Phrase mergePhrase(inputPhrase); + mergePhrase.MergeFactors(m_phrase); TranslationOption *newTransOpt = new TranslationOption(*this, mergePhrase, generationDictionary, generationScore, weight); return newTransOpt; } diff --git a/moses/src/TranslationOption.h b/moses/src/TranslationOption.h index ed8163d11..9b347c910 100755 --- a/moses/src/TranslationOption.h +++ b/moses/src/TranslationOption.h @@ -44,7 +44,7 @@ class TranslationOption protected: - const Phrase *m_phrase; + const Phrase m_phrase; const WordsRange m_sourceWordsRange; float m_scoreTrans, m_scoreGen, m_futureScore, m_ngramScore; @@ -55,34 +55,27 @@ protected: ScoreComponentCollection2 m_scoreBreakdown; public: - TranslationOption(const WordsRange &wordsRange, const TargetPhrase *targetPhrase); + TranslationOption(const WordsRange &wordsRange, const TargetPhrase &targetPhrase); // used by initial translation step - TranslationOption(const TranslationOption ©, const TargetPhrase *targetPhrase); + TranslationOption(const TranslationOption ©, const TargetPhrase &targetPhrase); // used by MergeTranslation TranslationOption(const TranslationOption © - , const Phrase *inputPhrase + , const Phrase &inputPhrase , const GenerationDictionary *generationDictionary , float generationScore , float weight); - // used in creating the next generation step - TranslationOption(const WordsRange &wordsRange, const TargetPhrase *targetPhrase, int /*whatever*/); + TranslationOption(const WordsRange &wordsRange, const TargetPhrase &targetPhrase, int /*whatever*/); // used to create trans opt from unknown word - ~TranslationOption() - { - delete m_phrase; - } + TranslationOption *MergeTranslation(const TargetPhrase &targetPhrase) const; TranslationOption *MergeGeneration(const Phrase &inputPhrase , const GenerationDictionary *generationDictionary , float generationScore , float weight) const; - /*** - * return target phrase - */ inline const Phrase &GetTargetPhrase() const { - return *m_phrase; + return m_phrase; } inline const WordsRange &GetSourceWordsRange() const { @@ -141,12 +134,20 @@ public: { return m_scoreTrans + m_scoreGen + m_futureScore; } + /*** + * return target phrase + */ + inline const Phrase& GetPhrase() const + { + return m_phrase; + } + /*** * returns true if the source phrase translates into nothing */ inline bool IsDeletionOption() const { - return m_phrase->GetSize() == 0; + return m_phrase.GetSize() == 0; } void CalcScore(const LMList &allLM, float weightWordPenalty); diff --git a/moses/src/TranslationOptionCollection.cpp b/moses/src/TranslationOptionCollection.cpp index 9bc68b2fa..979634555 100644 --- a/moses/src/TranslationOptionCollection.cpp +++ b/moses/src/TranslationOptionCollection.cpp @@ -479,12 +479,11 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const FactorArray &sourc } TranslationOption *transOpt; - TargetPhrase *targetPhrase; if (!dropUnknown || isDigit) { // add to dictionary - targetPhrase = new TargetPhrase(Output); - FactorArray &targetWord = targetPhrase->AddWord(); + TargetPhrase targetPhraseOrig(Output); + FactorArray &targetWord = targetPhraseOrig.AddWord(); for (unsigned int currFactor = 0 ; currFactor < NUM_FACTORS ; currFactor++) { @@ -497,13 +496,17 @@ void TranslationOptionCollection::ProcessOneUnknownWord(const FactorArray &sourc targetWord[factorType] = factorCollection.AddFactor(Output, factorType, sourceFactor->GetString()); } - targetPhrase->SetScore(weightWordPenalty); + targetPhraseOrig.SetScore(weightWordPenalty); + + pair< set<TargetPhrase>::iterator, bool> inserted = m_unknownTargetPhrase.insert(targetPhraseOrig); + const TargetPhrase &targetPhrase = *inserted.first; + transOpt = new TranslationOption(WordsRange(sourcePos, sourcePos), targetPhrase, 0); } else { // drop source word. create blank trans opt - targetPhrase = new TargetPhrase(Output); + const TargetPhrase targetPhrase(Output); + transOpt = new TranslationOption(WordsRange(sourcePos, sourcePos), targetPhrase, 0); } - transOpt = new TranslationOption(WordsRange(sourcePos, sourcePos), targetPhrase, 0); transOpt->CalcScore(*m_allLM, weightWordPenalty); Add(transOpt); @@ -551,7 +554,7 @@ void TranslationOptionCollection::ProcessInitialTranslation( TargetPhraseCollection::const_iterator iterTargetPhrase; for (iterTargetPhrase = phraseColl->begin() ; iterTargetPhrase != phraseColl->end() ; ++iterTargetPhrase) { - const TargetPhrase *targetPhrase = new TargetPhrase(*iterTargetPhrase); + const TargetPhrase &targetPhrase = *iterTargetPhrase; outputPartialTranslOptColl.push_back ( new TranslationOption(wordsRange, targetPhrase) ); if (verboseLevel >= 3) |