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 "DecodeStep.h"
|
|
|
|
#include "GenerationDictionary.h"
|
|
|
|
#include "StaticData.h"
|
2013-10-03 14:05:53 +04:00
|
|
|
#include "moses/TranslationModel/PhraseDictionary.h"
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2013-12-05 17:06:35 +04:00
|
|
|
DecodeStep::DecodeStep(DecodeFeature *decodeFeature,
|
2013-05-30 15:51:40 +04:00
|
|
|
const DecodeStep* prev,
|
|
|
|
const std::vector<FeatureFunction*> &features)
|
|
|
|
: m_decodeFeature(decodeFeature)
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2011-02-24 16:14:42 +03:00
|
|
|
FactorMask prevOutputFactors;
|
|
|
|
if (prev) prevOutputFactors = prev->m_outputFactors;
|
|
|
|
m_outputFactors = prevOutputFactors;
|
|
|
|
FactorMask conflictMask = (m_outputFactors & decodeFeature->GetOutputFactorMask());
|
|
|
|
m_outputFactors |= decodeFeature->GetOutputFactorMask();
|
|
|
|
FactorMask newOutputFactorMask = m_outputFactors ^ prevOutputFactors; //xor
|
2008-06-11 14:52:57 +04:00
|
|
|
m_newOutputFactors.resize(newOutputFactorMask.count());
|
2011-02-24 16:14:42 +03:00
|
|
|
m_conflictFactors.resize(conflictMask.count());
|
|
|
|
size_t j=0, k=0;
|
2008-06-11 14:52:57 +04:00
|
|
|
for (size_t i = 0; i < MAX_NUM_FACTORS; i++) {
|
|
|
|
if (newOutputFactorMask[i]) m_newOutputFactors[j++] = i;
|
2011-02-24 16:14:42 +03:00
|
|
|
if (conflictMask[i]) m_conflictFactors[k++] = i;
|
|
|
|
}
|
2008-06-11 14:52:57 +04:00
|
|
|
VERBOSE(2,"DecodeStep():\n\toutputFactors=" << m_outputFactors
|
2011-02-24 16:14:42 +03:00
|
|
|
<< "\n\tconflictFactors=" << conflictMask
|
|
|
|
<< "\n\tnewOutputFactors=" << newOutputFactorMask << std::endl);
|
2013-05-30 14:25:57 +04:00
|
|
|
|
|
|
|
// find out which feature function can be applied in this decode step
|
|
|
|
for (size_t i = 0; i < features.size(); ++i) {
|
2013-05-30 15:51:40 +04:00
|
|
|
FeatureFunction *feature = features[i];
|
|
|
|
if (feature->IsUseable(m_outputFactors)) {
|
|
|
|
m_featuresToApply.push_back(feature);
|
|
|
|
} else {
|
|
|
|
m_featuresRemaining.push_back(feature);
|
|
|
|
}
|
2013-05-30 14:25:57 +04:00
|
|
|
}
|
2013-12-05 17:06:35 +04:00
|
|
|
|
|
|
|
decodeFeature->SetContainer(this);
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
DecodeStep::~DecodeStep() {}
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
/** returns phrase feature (dictionary) for translation step */
|
2013-02-22 23:17:57 +04:00
|
|
|
const PhraseDictionary* DecodeStep::GetPhraseDictionaryFeature() const
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2013-02-22 23:17:57 +04:00
|
|
|
return dynamic_cast<const PhraseDictionary*>(m_decodeFeature);
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2010-08-10 17:12:00 +04:00
|
|
|
/** returns generation feature (dictionary) for generation step */
|
|
|
|
const GenerationDictionary* DecodeStep::GetGenerationDictionaryFeature() const
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
2010-08-10 17:12:00 +04:00
|
|
|
return dynamic_cast<const GenerationDictionary*>(m_decodeFeature);
|
2008-06-11 14:52:57 +04:00
|
|
|
}
|
|
|
|
|
2013-05-30 23:04:48 +04:00
|
|
|
void DecodeStep::RemoveFeature(const FeatureFunction *ff)
|
|
|
|
{
|
|
|
|
for (size_t i = 0; i < m_featuresToApply.size(); ++i) {
|
|
|
|
if (ff == m_featuresToApply[i]) {
|
|
|
|
m_featuresToApply.erase(m_featuresToApply.begin() + i);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-10-09 03:51:26 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
|