00001 // $Id$ 00002 00003 /*********************************************************************** 00004 Moses - factored phrase-based language decoder 00005 Copyright (C) 2006 University of Edinburgh 00006 00007 This library is free software; you can redistribute it and/or 00008 modify it under the terms of the GNU Lesser General Public 00009 License as published by the Free Software Foundation; either 00010 version 2.1 of the License, or (at your option) any later version. 00011 00012 This library is distributed in the hope that it will be useful, 00013 but WITHOUT ANY WARRANTY; without even the implied warranty of 00014 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00015 Lesser General Public License for more details. 00016 00017 You should have received a copy of the GNU Lesser General Public 00018 License along with this library; if not, write to the Free Software 00019 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00020 ***********************************************************************/ 00021 00022 #include "DecodeStep.h" 00023 #include "GenerationDictionary.h" 00024 #include "StaticData.h" 00025 #include "moses/TranslationModel/PhraseDictionary.h" 00026 00027 namespace Moses 00028 { 00029 DecodeStep::DecodeStep(DecodeFeature *decodeFeature, 00030 const DecodeStep* prev, 00031 const std::vector<FeatureFunction*> &features) 00032 : m_decodeFeature(decodeFeature) 00033 { 00034 FactorMask prevOutputFactors; 00035 if (prev) prevOutputFactors = prev->m_outputFactors; 00036 m_outputFactors = prevOutputFactors; 00037 FactorMask conflictMask = (m_outputFactors & decodeFeature->GetOutputFactorMask()); 00038 m_outputFactors |= decodeFeature->GetOutputFactorMask(); 00039 FactorMask newOutputFactorMask = m_outputFactors ^ prevOutputFactors; //xor 00040 m_newOutputFactors.resize(newOutputFactorMask.count()); 00041 m_conflictFactors.resize(conflictMask.count()); 00042 size_t j=0, k=0; 00043 for (size_t i = 0; i < MAX_NUM_FACTORS; i++) { 00044 if (newOutputFactorMask[i]) m_newOutputFactors[j++] = i; 00045 if (conflictMask[i]) m_conflictFactors[k++] = i; 00046 } 00047 VERBOSE(2,"DecodeStep():\n\toutputFactors=" << m_outputFactors 00048 << "\n\tconflictFactors=" << conflictMask 00049 << "\n\tnewOutputFactors=" << newOutputFactorMask << std::endl); 00050 00051 // find out which feature function can be applied in this decode step 00052 for (size_t i = 0; i < features.size(); ++i) { 00053 FeatureFunction *feature = features[i]; 00054 if (feature->IsUseable(m_outputFactors)) { 00055 m_featuresToApply.push_back(feature); 00056 } else { 00057 m_featuresRemaining.push_back(feature); 00058 } 00059 } 00060 00061 decodeFeature->SetContainer(this); 00062 } 00063 00064 DecodeStep::~DecodeStep() {} 00065 00067 const PhraseDictionary* DecodeStep::GetPhraseDictionaryFeature() const 00068 { 00069 return dynamic_cast<const PhraseDictionary*>(m_decodeFeature); 00070 } 00071 00073 const GenerationDictionary* DecodeStep::GetGenerationDictionaryFeature() const 00074 { 00075 return dynamic_cast<const GenerationDictionary*>(m_decodeFeature); 00076 } 00077 00078 void DecodeStep::RemoveFeature(const FeatureFunction *ff) 00079 { 00080 for (size_t i = 0; i < m_featuresToApply.size(); ++i) { 00081 if (ff == m_featuresToApply[i]) { 00082 m_featuresToApply.erase(m_featuresToApply.begin() + i); 00083 return; 00084 } 00085 } 00086 } 00087 00088 } 00089 00090