Welcome to mirror list, hosted at ThFree Co, Russian Federation.

StaticData.h « src « moses - github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 36e0be369569d23eb2f4134a809d0e0fe3bc34c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// $Id$

/***********************************************************************
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
***********************************************************************/

#pragma once

#include <list>
#include <vector>
#include <boost/shared_ptr.hpp>
#include "TypeDef.h"
#include "ScoreIndexManager.h"
#include "FactorCollection.h"
#include "Parameter.h"
#include "LanguageModel.h"
#include "InputOutput.h"
#include "DecodeStep.h"
#include "LMList.h"
#include "SentenceStats.h"
//#include "UnknownWordHandler.h"

class InputType;
class LexicalReordering;
class PhraseDictionaryBase;
class GenerationDictionary;
class DistortionScoreProducer;
class WordPenaltyProducer;

class StaticData
{
private:
	static StaticData*									s_instance;
protected:	
	FactorCollection										m_factorCollection;
	std::vector<PhraseDictionaryBase*>	m_phraseDictionary;
	std::vector<GenerationDictionary*>	m_generationDictionary;
	std::list < DecodeStep >						m_decodeStepList;
	Parameter			m_parameter;
	std::vector<FactorType>			m_inputFactorOrder, m_outputFactorOrder;
//	boost::shared_ptr<UnknownWordHandler>      m_unknownWordHandler; //defaults to NULL; pointer allows polymorphism
	LMList									m_languageModel;
	std::vector<float>			m_lexWeights;
	ScoreIndexManager				m_scoreIndexManager;
	std::vector<float>			m_allWeights;
	LexicalReordering                   *m_lexReorder;
		// Initial	= 0 = can be used when creating poss trans
		// Other		= 1 = used to calculate LM score once all steps have been processed
	float
		m_beamThreshold,
		m_weightDistortion, 
		m_weightWordPenalty, 
		m_wordDeletionWeight;
									// PhraseTrans, Generation & LanguageModelScore has multiple weights.
	int																	m_maxDistortion;
									// do it differently from old pharaoh
									// -ve	= no limit on distortion
									// 0		= no disortion (monotone in old pharaoh)
	size_t                              
			m_maxHypoStackSize //hypothesis-stack size that triggers pruning
			, m_nBestSize
			, m_maxNoTransOptPerCoverage;
	
	std::string													m_nBestFilePath, m_cachePath;
	std::vector<std::string>						m_mySQLParam;
	InputOutput													*m_inputOutput;
	bool                                m_fLMsLoaded;
	std::vector<size_t>									m_maxNgramOrderForFactor;
	/***
	 * false = treat unknown words as proper nouns, and translate them as themselves;
	 * true = drop (ignore) them
	 */
	bool m_dropUnknown;
	bool m_wordDeletionEnabled;

	int m_inputType;
	unsigned m_numInputScores;

	size_t m_verboseLevel;
	DistortionScoreProducer *m_distortionScoreProducer;
	WordPenaltyProducer *m_wpProducer;
	bool m_reportSourceSpan;
	bool m_reportAllFactors;

	mutable SentenceStats m_sentenceStats;
	
	int m_useDistortionFutureCosts;

  

public:
	StaticData();
	~StaticData();

	static const StaticData* Instance() { return s_instance; }

	/***
	 * also initialize the Parameter object
	 */
	bool LoadParameters(int argc, char* argv[]);

	/***
	 * load not only the main phrase table but also any auxiliary tables that depend on which features are being used
	 * (eg word-deletion, word-insertion tables)
	 */
	void LoadPhraseTables(bool filter
											, const std::string &inputFileHash
											, const std::list< Phrase > &inputPhraseList);
	void LoadPhraseTables()
	{
		LoadPhraseTables(false, "", std::list< Phrase >());
	}
	void LoadMapping();
/*	void SetUnknownWordHandler(boost::shared_ptr<UnknownWordHandler> unknownWordHandler)
	{
		m_unknownWordHandler = unknownWordHandler;
	}
*/
	const PARAM_VEC &GetParam(const std::string &paramName)
	{
		return m_parameter.GetParam(paramName);
	}

	InputOutput &GetInputOutput()
	{
		return *m_inputOutput;
	}

	const std::vector<FactorType> &GetInputFactorOrder() const
	{
		return m_inputFactorOrder;
	}
	const std::vector<FactorType> &GetOutputFactorOrder() const
	{
		return m_outputFactorOrder;
	}

	std::list < DecodeStep > &GetDecodeStepList()
	{
		return m_decodeStepList;
	}
	
	inline bool GetDropUnknown() const 
	{ 
		return m_dropUnknown; 
	}
	inline size_t GetMaxNoTransOptPerCoverage() const 
	{ 
		return m_maxNoTransOptPerCoverage;
	}
	FactorCollection &GetFactorCollection()
	{
		return m_factorCollection;
	}
	size_t GetMaxNGramOrderForFactorId(size_t factorType) const
	{
		if (factorType >= m_maxNgramOrderForFactor.size()) return 0;
		return m_maxNgramOrderForFactor[factorType];
	}
	LexicalReordering *GetLexReorder() const
	{
		return m_lexReorder;
	}
	float GetWeightDistortion() const
	{
		return m_weightDistortion;
	}
	float GetWeightWordPenalty() const
	{
		return m_weightWordPenalty;
	}
	bool IsWordDeletionEnabled() const
	{
		return m_wordDeletionEnabled;
	}
	size_t GetMaxHypoStackSize() const
	{
		return m_maxHypoStackSize;
	}
	int GetMaxDistortion() const
	{
		return m_maxDistortion;
	}
	float GetBeamThreshold() const
	{
		return m_beamThreshold;
	}
	//! returns the total number of score components across all types, all factors
	size_t GetTotalScoreComponents() const
	{
		return m_scoreIndexManager.GetTotalNumberOfScores();
	}
	const ScoreIndexManager& GetScoreIndexManager() const
	{
		return m_scoreIndexManager;
	}
	IOMethod GetIOMethod();
	const std::vector<std::string> &GetMySQLParam()
	{
		return m_mySQLParam;
	}

	size_t GetLMSize() const
	{
		return m_languageModel.size();
	}
	const LMList &GetAllLM() const
	{
		return m_languageModel;
	}
	size_t GetPhraseDictionarySize() const
	{
		return m_phraseDictionary.size();
	}
	std::vector<PhraseDictionaryBase*> GetPhraseDictionaries() const
	{
		return m_phraseDictionary;
	}
	std::vector<GenerationDictionary*> GetGenerationDictionaries() const
	{
		return m_generationDictionary;
	}
	size_t GetGenerationDictionarySize() const
	{
		return m_generationDictionary.size();
	}
	const std::string GetCachePath() const
	{
		return m_cachePath;
	}
	size_t GetVerboseLevel() const
	{
		return m_verboseLevel;
	}
	bool GetReportSourceSpan() const
	{
		return m_reportSourceSpan;
	}
	bool GetReportAllFactors() const
	{
		return m_reportAllFactors;
	}

	// for mert
	size_t GetNBestSize() const
	{
		return m_nBestSize;
	}
	const std::string &GetNBestFilePath() const
	{
		return m_nBestFilePath;
	}
  // TODO use IsNBestEnabled instead of conditional compilation
  const bool IsNBestEnabled() const {
    return !m_nBestFilePath.empty();
  }
	void SetWeightDistortion(float weightDistortion)
	{
		m_weightDistortion = weightDistortion;
	}
	void SetWeightWordPenalty(float weightWordPenalty)
	{
		m_weightWordPenalty = weightWordPenalty;
	}
//! Sets the global score vector weights for a given ScoreProducer.
	void SetWeightsForScoreProducer(const ScoreProducer* sp, const std::vector<float>& weights);
	void SetWeightTransModel(const std::vector<float> &weight);
	void SetWeightLM(const std::vector<float> &weight);
	void SetWeightGeneration(const std::vector<float> &weight);
	int GetInputType() const {return m_inputType;}
	unsigned GetNumInputScores() const {return m_numInputScores;}
	void InitializeBeforeSentenceProcessing(InputType const&);
	void CleanUpAfterSentenceProcessing();
	SentenceStats& GetSentenceStats() const
	{
		return m_sentenceStats;
	}
	const std::vector<float>& GetAllWeights() const
	{
		return m_allWeights;
	}
	const DistortionScoreProducer *GetDistortionScoreProducer() const { return m_distortionScoreProducer; }
	const WordPenaltyProducer *GetWordPenaltyProducer() const { return m_wpProducer; }

	bool UseDistortionFutureCosts() const {return m_useDistortionFutureCosts;}
};