00001 // $Id: LanguageModel.cpp 4348 2011-10-13 12:33:05Z heafield $ 00002 00003 /*********************************************************************** 00004 Moses - statistical machine translation system 00005 Copyright (C) 2006-2011 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 "LanguageModel.h" 00023 #include "TypeDef.h" 00024 #include "Util.h" 00025 #include "Manager.h" 00026 #include "ChartManager.h" 00027 #include "FactorCollection.h" 00028 #include "Phrase.h" 00029 #include "StaticData.h" 00030 00031 using namespace std; 00032 00033 namespace Moses { 00034 00035 LanguageModel::LanguageModel() { 00036 m_enableOOVFeature = StaticData::Instance().GetLMEnableOOVFeature(); 00037 } 00038 00039 void LanguageModel::Init(ScoreIndexManager &scoreIndexManager) { 00040 scoreIndexManager.AddScoreProducer(this); 00041 } 00042 00043 LanguageModel::~LanguageModel() {} 00044 00045 // don't inline virtual funcs... 00046 size_t LanguageModel::GetNumScoreComponents() const { 00047 if (m_enableOOVFeature) { 00048 return 2; 00049 } else { 00050 return 1; 00051 } 00052 } 00053 00054 float LanguageModel::GetWeight() const { 00055 size_t lmIndex = StaticData::Instance().GetScoreIndexManager(). 00056 GetBeginIndex(GetScoreBookkeepingID()); 00057 return StaticData::Instance().GetAllWeights()[lmIndex]; 00058 } 00059 00060 float LanguageModel::GetOOVWeight() const { 00061 if (!m_enableOOVFeature) return 0; 00062 size_t lmIndex = StaticData::Instance().GetScoreIndexManager(). 00063 GetBeginIndex(GetScoreBookkeepingID()); 00064 return StaticData::Instance().GetAllWeights()[lmIndex+1]; 00065 } 00066 00067 } // namespace Moses
1.5.9