2008-06-11 14:52:57 +04:00
|
|
|
// $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 "DecodeStepTranslation.h"
|
|
|
|
#include "TranslationOption.h"
|
|
|
|
#include "TranslationOptionCollection.h"
|
|
|
|
#include "PartialTranslOptColl.h"
|
|
|
|
#include "FactorCollection.h"
|
|
|
|
|
2013-04-26 17:27:44 +04:00
|
|
|
using namespace std;
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2013-02-22 23:17:57 +04:00
|
|
|
DecodeStepTranslation::DecodeStepTranslation(const PhraseDictionary* pdf, const DecodeStep* prev)
|
2011-02-24 16:14:42 +03:00
|
|
|
: DecodeStep(pdf, prev)
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-05-11 17:13:26 +04:00
|
|
|
void DecodeStepTranslation::Process(const TranslationOption &inputPartialTranslOpt
|
2011-02-24 16:14:42 +03:00
|
|
|
, const DecodeStep &decodeStep
|
|
|
|
, PartialTranslOptColl &outputPartialTranslOptColl
|
|
|
|
, TranslationOptionCollection *toc
|
|
|
|
, bool adhereTableLimit) const
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
if (inputPartialTranslOpt.GetTargetPhrase().GetSize() == 0) {
|
|
|
|
// word deletion
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2013-05-11 17:13:26 +04:00
|
|
|
outputPartialTranslOptColl.Add(new TranslationOption(inputPartialTranslOpt));
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
return;
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
// normal trans step
|
|
|
|
const WordsRange &sourceWordsRange = inputPartialTranslOpt.GetSourceWordsRange();
|
|
|
|
const PhraseDictionary* phraseDictionary =
|
2013-02-22 23:17:57 +04:00
|
|
|
decodeStep.GetPhraseDictionaryFeature();
|
2013-05-08 14:28:31 +04:00
|
|
|
const TargetPhrase &inPhrase = inputPartialTranslOpt.GetTargetPhrase();
|
|
|
|
const size_t currSize = inPhrase.GetSize();
|
2011-02-24 16:14:42 +03:00
|
|
|
const size_t tableLimit = phraseDictionary->GetTableLimit();
|
|
|
|
|
|
|
|
const TargetPhraseCollection *phraseColl=
|
|
|
|
phraseDictionary->GetTargetPhraseCollection(toc->GetSource(),sourceWordsRange);
|
|
|
|
|
|
|
|
if (phraseColl != NULL) {
|
|
|
|
TargetPhraseCollection::const_iterator iterTargetPhrase, iterEnd;
|
|
|
|
iterEnd = (!adhereTableLimit || tableLimit == 0 || phraseColl->GetSize() < tableLimit) ? phraseColl->end() : phraseColl->begin() + tableLimit;
|
|
|
|
|
|
|
|
for (iterTargetPhrase = phraseColl->begin(); iterTargetPhrase != iterEnd; ++iterTargetPhrase) {
|
|
|
|
const TargetPhrase& targetPhrase = **iterTargetPhrase;
|
2013-05-08 14:28:31 +04:00
|
|
|
const ScoreComponentCollection &transScores = targetPhrase.GetScoreBreakdown();
|
2011-02-24 16:14:42 +03:00
|
|
|
// skip if the
|
|
|
|
if (targetPhrase.GetSize() != currSize) continue;
|
|
|
|
|
2013-05-08 14:28:31 +04:00
|
|
|
TargetPhrase outPhrase(inPhrase);
|
|
|
|
|
|
|
|
if (IsFilteringStep()) {
|
|
|
|
if (!inputPartialTranslOpt.IsCompatible(targetPhrase, m_conflictFactors))
|
|
|
|
continue;
|
2011-02-24 16:14:42 +03:00
|
|
|
}
|
2013-05-08 14:28:31 +04:00
|
|
|
|
2013-05-13 16:19:25 +04:00
|
|
|
outPhrase.GetScoreBreakdown().PlusEquals(transScores);
|
2013-05-08 14:28:31 +04:00
|
|
|
outPhrase.Evaluate(); // need to do this as all non-transcores would be screwed up
|
|
|
|
|
|
|
|
outPhrase.MergeFactors(targetPhrase, m_newOutputFactors);
|
|
|
|
|
|
|
|
TranslationOption *newTransOpt = new TranslationOption(sourceWordsRange, outPhrase);
|
|
|
|
assert(newTransOpt != NULL);
|
|
|
|
|
2013-05-11 17:13:26 +04:00
|
|
|
outputPartialTranslOptColl.Add(newTransOpt );
|
2013-05-08 14:28:31 +04:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
2011-02-24 16:14:42 +03:00
|
|
|
} else if (sourceWordsRange.GetNumWordsCovered() == 1) {
|
|
|
|
// unknown handler
|
|
|
|
//toc->ProcessUnknownWord(sourceWordsRange.GetStartPos(), factorCollection);
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-11 17:13:26 +04:00
|
|
|
void DecodeStepTranslation::ProcessInitialTranslation(
|
|
|
|
const InputType &source
|
2011-02-24 16:14:42 +03:00
|
|
|
,PartialTranslOptColl &outputPartialTranslOptColl
|
|
|
|
, size_t startPos, size_t endPos, bool adhereTableLimit) const
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2013-02-22 23:17:57 +04:00
|
|
|
const PhraseDictionary* phraseDictionary = GetPhraseDictionaryFeature();
|
2011-02-24 16:14:42 +03:00
|
|
|
const size_t tableLimit = phraseDictionary->GetTableLimit();
|
|
|
|
|
|
|
|
const WordsRange wordsRange(startPos, endPos);
|
|
|
|
const TargetPhraseCollection *phraseColl = phraseDictionary->GetTargetPhraseCollection(source,wordsRange);
|
|
|
|
|
|
|
|
if (phraseColl != NULL) {
|
|
|
|
IFVERBOSE(3) {
|
|
|
|
if(StaticData::Instance().GetInputType() == SentenceInput)
|
|
|
|
TRACE_ERR("[" << source.GetSubString(wordsRange) << "; " << startPos << "-" << endPos << "]\n");
|
|
|
|
else
|
|
|
|
TRACE_ERR("[" << startPos << "-" << endPos << "]" << std::endl);
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetPhraseCollection::const_iterator iterTargetPhrase, iterEnd;
|
|
|
|
iterEnd = (!adhereTableLimit || tableLimit == 0 || phraseColl->GetSize() < tableLimit) ? phraseColl->end() : phraseColl->begin() + tableLimit;
|
|
|
|
|
|
|
|
for (iterTargetPhrase = phraseColl->begin() ; iterTargetPhrase != iterEnd ; ++iterTargetPhrase) {
|
|
|
|
const TargetPhrase &targetPhrase = **iterTargetPhrase;
|
2013-05-08 14:28:31 +04:00
|
|
|
TranslationOption *transOpt = new TranslationOption(wordsRange, targetPhrase);
|
2013-04-26 17:27:44 +04:00
|
|
|
|
2013-05-11 17:13:26 +04:00
|
|
|
outputPartialTranslOptColl.Add (transOpt);
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
VERBOSE(3,"\t" << targetPhrase << "\n");
|
|
|
|
}
|
|
|
|
VERBOSE(3,std::endl);
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
|