|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "DecodeStep.h" |
|
|
#include "GenerationDictionary.h" |
|
|
#include "StaticData.h" |
|
|
#include "moses/TranslationModel/PhraseDictionary.h" |
|
|
|
|
|
namespace Moses |
|
|
{ |
|
|
DecodeStep::DecodeStep(DecodeFeature *decodeFeature, |
|
|
const DecodeStep* prev, |
|
|
const std::vector<FeatureFunction*> &features) |
|
|
: m_decodeFeature(decodeFeature) |
|
|
{ |
|
|
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; |
|
|
m_newOutputFactors.resize(newOutputFactorMask.count()); |
|
|
m_conflictFactors.resize(conflictMask.count()); |
|
|
size_t j=0, k=0; |
|
|
for (size_t i = 0; i < MAX_NUM_FACTORS; i++) { |
|
|
if (newOutputFactorMask[i]) m_newOutputFactors[j++] = i; |
|
|
if (conflictMask[i]) m_conflictFactors[k++] = i; |
|
|
} |
|
|
VERBOSE(2,"DecodeStep():\n\toutputFactors=" << m_outputFactors |
|
|
<< "\n\tconflictFactors=" << conflictMask |
|
|
<< "\n\tnewOutputFactors=" << newOutputFactorMask << std::endl); |
|
|
|
|
|
|
|
|
for (size_t i = 0; i < features.size(); ++i) { |
|
|
FeatureFunction *feature = features[i]; |
|
|
if (feature->IsUseable(m_outputFactors)) { |
|
|
m_featuresToApply.push_back(feature); |
|
|
} else { |
|
|
m_featuresRemaining.push_back(feature); |
|
|
} |
|
|
} |
|
|
|
|
|
decodeFeature->SetContainer(this); |
|
|
} |
|
|
|
|
|
DecodeStep::~DecodeStep() {} |
|
|
|
|
|
|
|
|
const PhraseDictionary* DecodeStep::GetPhraseDictionaryFeature() const |
|
|
{ |
|
|
return dynamic_cast<const PhraseDictionary*>(m_decodeFeature); |
|
|
} |
|
|
|
|
|
|
|
|
const GenerationDictionary* DecodeStep::GetGenerationDictionaryFeature() const |
|
|
{ |
|
|
return dynamic_cast<const GenerationDictionary*>(m_decodeFeature); |
|
|
} |
|
|
|
|
|
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; |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|