2015-10-25 22:28:48 +03:00
|
|
|
// $Id$
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
/***********************************************************************
|
|
|
|
Moses - factored phrase-based language decoder
|
|
|
|
Copyright (C) 2006 University of Edinburgh
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU Lesser General Public
|
|
|
|
License as published by the Free Software Foundation; either
|
|
|
|
version 2.1 of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
This library is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
Lesser General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU Lesser General Public
|
|
|
|
License along with this library; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
***********************************************************************/
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#ifndef moses_LanguageModelIRST_h
|
|
|
|
#define moses_LanguageModelIRST_h
|
2008-06-11 14:52:57 +04:00
|
|
|
|
|
|
|
#include <string>
|
|
|
|
#include <vector>
|
2015-01-05 00:47:46 +03:00
|
|
|
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "moses/Factor.h"
|
2015-01-05 00:47:46 +03:00
|
|
|
#include "moses/LM/SingleFactor.h"
|
|
|
|
#include "moses/Hypothesis.h"
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "moses/TypeDef.h"
|
2015-01-05 00:47:46 +03:00
|
|
|
|
2012-11-12 23:56:18 +04:00
|
|
|
#include "moses/Util.h"
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2014-05-17 23:20:51 +04:00
|
|
|
//this is required because:
|
|
|
|
//- IRSTLM package uses the namespace irstlm
|
|
|
|
//- the compilation of "IRST.cpp" requires "using namespace irstlm", which is defined in any file of the IRSTLM package
|
|
|
|
// but conflicts with these foward declaration of class lmContainer
|
|
|
|
//- for files in moses/LM the IRSTLM include directory is set
|
|
|
|
// but not for the rest of files
|
|
|
|
#ifdef LM_IRST
|
2011-10-03 20:02:02 +04:00
|
|
|
class lmContainer; // irst lm container for any lm type
|
2008-06-11 14:52:57 +04:00
|
|
|
class ngram;
|
2011-02-04 10:42:56 +03:00
|
|
|
class dictionary;
|
2014-05-17 23:20:51 +04:00
|
|
|
#endif
|
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2008-10-10 22:31:07 +04:00
|
|
|
namespace Moses
|
|
|
|
{
|
2015-01-05 00:47:46 +03:00
|
|
|
|
|
|
|
//class LanguageModel;
|
|
|
|
class FFState;
|
2008-10-10 22:31:07 +04:00
|
|
|
class Phrase;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
/** Implementation of single factor LM using IRST's code.
|
2012-06-29 02:29:46 +04:00
|
|
|
* This is available from the same sourceforge repository
|
|
|
|
*/
|
2013-02-21 02:09:00 +04:00
|
|
|
class LanguageModelIRST : public LanguageModelSingleFactor
|
2008-06-11 14:52:57 +04:00
|
|
|
{
|
|
|
|
protected:
|
2011-02-24 16:14:42 +03:00
|
|
|
mutable std::vector<int> m_lmIdLookup;
|
2011-10-03 20:02:02 +04:00
|
|
|
lmContainer* m_lmtb;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
2011-09-28 22:21:55 +04:00
|
|
|
int m_unknownId; //code of OOV
|
|
|
|
int m_empty; //code of an empty position
|
2011-02-24 16:14:42 +03:00
|
|
|
int m_lmtb_sentenceStart; //lmtb symbols to initialize ngram with
|
|
|
|
int m_lmtb_sentenceEnd; //lmt symbol to initialize ngram with
|
|
|
|
int m_lmtb_dub; //dictionary upperboud
|
2015-01-05 00:47:46 +03:00
|
|
|
int m_lmtb_size; //max ngram stored in the table
|
|
|
|
|
2015-10-25 22:28:48 +03:00
|
|
|
dictionary* d;
|
2011-02-24 16:14:42 +03:00
|
|
|
|
|
|
|
std::string m_mapFilePath;
|
|
|
|
|
|
|
|
void CreateFactors(FactorCollection &factorCollection);
|
2015-01-05 00:47:46 +03:00
|
|
|
|
|
|
|
int GetLmID( const Word &word ) const;
|
2011-02-24 16:14:42 +03:00
|
|
|
int GetLmID( const std::string &str ) const;
|
|
|
|
int GetLmID( const Factor *factor ) const;
|
|
|
|
|
2011-02-04 10:42:56 +03:00
|
|
|
|
2008-06-11 14:52:57 +04:00
|
|
|
public:
|
2013-01-17 21:15:10 +04:00
|
|
|
LanguageModelIRST(const std::string &line);
|
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
~LanguageModelIRST();
|
2015-01-05 00:47:46 +03:00
|
|
|
|
|
|
|
void SetParameter(const std::string& key, const std::string& value);
|
|
|
|
|
2015-01-26 17:51:08 +03:00
|
|
|
bool IsUseable(const FactorMask &mask) const;
|
|
|
|
|
2015-12-10 06:17:36 +03:00
|
|
|
void Load(AllOptions::ptr const& opts);
|
2015-01-26 17:51:08 +03:00
|
|
|
const FFState *EmptyHypothesisState(const InputType &/*input*/) const;
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-03-08 02:21:09 +03:00
|
|
|
virtual LMResult GetValue(const std::vector<const Word*> &contextFactor, State* finalState = NULL) const;
|
2015-02-19 15:27:23 +03:00
|
|
|
|
2015-01-05 00:47:46 +03:00
|
|
|
|
2015-10-24 03:39:03 +03:00
|
|
|
virtual void CalcScore(const Phrase &phrase, float &fullScore, float &ngramScore, size_t &oovCount) const;
|
2015-01-05 00:47:46 +03:00
|
|
|
|
2015-10-29 01:22:08 +03:00
|
|
|
virtual FFState *EvaluateWhenApplied(const Hypothesis &hypo, const FFState *ps, ScoreComponentCollection *out) const;
|
2015-11-02 03:00:37 +03:00
|
|
|
/*
|
|
|
|
virtual FFState *EvaluateWhenApplied(const ChartHypothesis& cur_hypo, int featureID, ScoreComponentCollection *accumulator) const;
|
2015-01-05 00:47:46 +03:00
|
|
|
|
2015-11-02 03:00:37 +03:00
|
|
|
virtual FFState *EvaluateWhenApplied(const Syntax::SHyperedge& hyperedge, int featureID, ScoreComponentCollection *accumulator) const;
|
|
|
|
*/
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2015-05-19 04:35:39 +03:00
|
|
|
void InitializeForInput(ttasksptr const& ttask);
|
2012-07-19 19:41:41 +04:00
|
|
|
void CleanUpAfterSentenceProcessing(const InputType& source);
|
2008-06-11 14:52:57 +04:00
|
|
|
|
2011-02-24 16:14:42 +03:00
|
|
|
void set_dictionary_upperbound(int dub) {
|
|
|
|
m_lmtb_size=dub ;
|
|
|
|
};
|
2008-06-11 14:52:57 +04:00
|
|
|
};
|
2008-10-10 22:31:07 +04:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2010-02-24 14:15:44 +03:00
|
|
|
#endif
|