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 <limits> 00023 #include <iostream> 00024 #include <sstream> 00025 00026 #include "SingleFactor.h" 00027 #include "PointerState.h" 00028 #include "moses/FF/FFState.h" 00029 #include "moses/TypeDef.h" 00030 #include "moses/Util.h" 00031 #include "moses/FactorCollection.h" 00032 #include "moses/Phrase.h" 00033 #include "moses/StaticData.h" 00034 #include "moses/FactorTypeSet.h" 00035 00036 using namespace std; 00037 00038 namespace Moses 00039 { 00040 00041 LanguageModelSingleFactor::LanguageModelSingleFactor(const std::string &line) 00042 :LanguageModelImplementation(line) 00043 ,m_factorType(0) 00044 { 00045 m_nullContextState = new PointerState(NULL); 00046 m_beginSentenceState = new PointerState(NULL); 00047 } 00048 00049 LanguageModelSingleFactor::~LanguageModelSingleFactor() 00050 { 00051 delete m_nullContextState; 00052 delete m_beginSentenceState; 00053 } 00054 00055 const FFState *LanguageModelSingleFactor::GetNullContextState() const 00056 { 00057 return m_nullContextState; 00058 } 00059 00060 const FFState *LanguageModelSingleFactor::GetBeginSentenceState() const 00061 { 00062 return m_beginSentenceState; 00063 } 00064 00065 FFState *LanguageModelSingleFactor::NewState(const FFState *from) const 00066 { 00067 return new PointerState(from ? static_cast<const PointerState*>(from)->lmstate : NULL); 00068 } 00069 00070 LMResult LanguageModelSingleFactor::GetValueForgotState(const std::vector<const Word*> &contextFactor, FFState &outState) const 00071 { 00072 return GetValue(contextFactor, &static_cast<PointerState&>(outState).lmstate); 00073 } 00074 00075 bool LanguageModelSingleFactor::IsUseable(const FactorMask &mask) const 00076 { 00077 bool ret = mask[m_factorType]; 00078 return ret; 00079 } 00080 00081 void LanguageModelSingleFactor::SetParameter(const std::string& key, const std::string& value) 00082 { 00083 if (key == "factor") { 00084 m_factorType = Scan<FactorType>(value); 00085 } else { 00086 LanguageModelImplementation::SetParameter(key, value); 00087 } 00088 } 00089 00090 std::string LanguageModelSingleFactor::DebugContextFactor(const std::vector<const Word*> &contextFactor) const 00091 { 00092 std::string ret; 00093 for (size_t i = 0; i < contextFactor.size(); ++i) { 00094 const Word &word = *contextFactor[i]; 00095 ret += word.ToString(); 00096 } 00097 00098 return ret; 00099 } 00100 00101 } 00102 00103 00104 00105