00001 // -*- mode: c++; indent-tabs-mode: nil; tab-width:2 -*- 00002 /*********************************************************************** 00003 Moses - factored phrase-based language decoder 00004 Copyright (C) 2006 University of Edinburgh 00005 00006 This library is free software; you can redistribute it and/or 00007 modify it under the terms of the GNU Lesser General Public 00008 License as published by the Free Software Foundation; either 00009 version 2.1 of the License, or (at your option) any later version. 00010 00011 This library is distributed in the hope that it will be useful, 00012 but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 Lesser General Public License for more details. 00015 00016 You should have received a copy of the GNU Lesser General Public 00017 License along with this library; if not, write to the Free Software 00018 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA 00019 ***********************************************************************/ 00020 00021 #ifndef moses_LanguageModelSingleFactor_h 00022 #define moses_LanguageModelSingleFactor_h 00023 00024 #include "Implementation.h" 00025 #include "moses/Phrase.h" 00026 00027 namespace Moses 00028 { 00029 00030 class FactorCollection; 00031 class Factor; 00032 00034 class LanguageModelSingleFactor : public LanguageModelImplementation 00035 { 00036 protected: 00037 typedef const void *State; 00038 00039 const Factor *m_sentenceStart, *m_sentenceEnd; 00040 00041 FactorType m_factorType; 00042 FFState *m_nullContextState; 00043 FFState *m_beginSentenceState; 00044 00045 LanguageModelSingleFactor(const std::string &line); 00046 00047 public: 00048 virtual ~LanguageModelSingleFactor(); 00049 bool IsUseable(const FactorMask &mask) const; 00050 virtual void SetParameter(const std::string& key, const std::string& value); 00051 00052 const Factor *GetSentenceStart() const { 00053 return m_sentenceStart; 00054 } 00055 const Factor *GetSentenceEnd() const { 00056 return m_sentenceEnd; 00057 } 00058 FactorType GetFactorType() const { 00059 return m_factorType; 00060 } 00061 00062 virtual const FFState *GetNullContextState() const; 00063 virtual const FFState *GetBeginSentenceState() const; 00064 virtual FFState *NewState(const FFState *from = NULL) const; 00065 00066 virtual LMResult GetValueForgotState(const std::vector<const Word*> &contextFactor, FFState &outState) const; 00067 00068 protected: 00069 virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = NULL) const = 0; 00070 public: 00071 std::string DebugContextFactor(const std::vector<const Word*> &contextFactor) const; 00072 }; 00073 00074 00075 00076 } 00077 00078 #endif