This file is indexed.

/usr/include/irstlm/dictionary.h is in libirstlm-dev 6.00.05-2.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
// $Id: dictionary.h 3679 2010-10-13 09:10:01Z bertoldi $

/******************************************************************************
 IrstLM: IRST Language Model Toolkit
 Copyright (C) 2006 Marcello Federico, ITC-irst Trento, Italy
 
 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
 
 ******************************************************************************/

#ifndef MF_DICTIONARY_H
#define MF_DICTIONARY_H

#include "mfstream.h"
#include "htable.h"
#include <cstring>
#include <iostream>


using namespace std;

#define MAX_WORD 1000
#define DICTIONARY_LOAD_FACTOR  2.0


#ifndef GROWTH_STEP
#define GROWTH_STEP 1.5
#endif

#ifndef DICT_INITSIZE
#define DICT_INITSIZE 100000
#endif

//Begin of sentence symbol
#ifndef BOS_
#define BOS_ "<s>"
#endif


//End of sentence symbol
#ifndef EOS_
#define EOS_ "</s>"
#endif

//End of document symbol
#ifndef BOD_
#define BOD_ "<d>"
#endif

//End of document symbol
#ifndef EOD_
#define EOD_ "</d>"
#endif


//Out-Of-Vocabulary symbol
#ifndef OOV_
#define OOV_ "<unk>"
#endif

typedef struct {
	const char *word;
	int  code;
	long long freq;
} dict_entry;

typedef htable<char*> HASHTABLE_t;

class strstack;

class dictionary
{
	strstack   *st;  //!< stack of strings
	dict_entry *tb;  //!< entry table
	HASHTABLE_t  *htb;  //!< hash table
	int          n;  //!< number of entries
	long long    N;  //!< total frequency
	int        lim;  //!< limit of entries
	int   oov_code;  //!< code assigned to oov words
	char       ifl;  //!< increment flag
	int        dubv; //!< dictionary size upper bound
	float        load_factor; //!< dictionary loading factor
	char* oov_str;    //!< oov string
	
	void test(int* OOVchart, int* NwTest, int curvesize, const char *filename, int listflag=0);	// prepare into testOOV the OOV statistics computed on test set
	
public:
	
	friend class dictionary_iter;
	
	dictionary* oovlex; //<! additional dictionary
	
	inline int dub() const {
		return dubv;
	}
	
	inline int dub(int value) {
		return dubv=value;
	}
	
	inline static const char *OOV() {
		return (char*) OOV_;
	}
	
	inline static const char *BoS() {
		return (char*) BOS_;
	}
	
	inline static const char *EoS() {
		return (char*) EOS_;
	}
	
	inline static const char *BoD() {
		return (char*) BOD_;
	}
	
	inline static const char *EoD() {
		return (char*) EOD_;
	}
	
	inline int oovcode(int v=-1) {
		return oov_code=(v>=0?v:oov_code);
	}
	
	inline int incflag() const {
		return ifl;
	}
	
	inline int incflag(int v) {
		return ifl=v;
	}
	
	int getword(fstream& inp , char* buffer) const;
	
	int isprintable(char* w) const {
		char buffer[MAX_WORD];
		sprintf(buffer,"%s",w);
		return strcmp(w,buffer)==0;
	}
	
	inline void genoovcode() {
		int c=encode(OOV());
		std::cerr << "OOV code is "<< c << std::endl;
		cerr << "OOV code is "<< c << std::endl;
		oovcode(c);
	}
	
	inline void genBoScode() {
		int c=encode(BoS());
		std::cerr << "BoS code is "<< c << std::endl;
	}
	
	inline void genEoScode() {
		int c=encode(EoS());
		std::cerr << "EoS code is "<< c << std::endl;
	}
	
	inline long long setoovrate(double oovrate) {
		encode(OOV()); //be sure OOV code exists
		long long oovfreq=(long long)(oovrate * totfreq());
		std::cerr << "setting OOV rate to: " << oovrate << " -- freq= " << oovfreq << std::endl;
		return freq(oovcode(),oovfreq);
	}
	
	inline long long incfreq(int code,long long value) {
		N+=value;
		return tb[code].freq+=value;
	}
	
	inline long long multfreq(int code,double value) {
		N+=(long long)(value * tb[code].freq)-tb[code].freq;
		return tb[code].freq=(long long)(value * tb[code].freq);
	}
	
	inline long long freq(int code,long long value=-1) {
		if (value>=0) {
			N+=value-tb[code].freq;
			tb[code].freq=value;
		}
		return tb[code].freq;
	}
	
	inline long long totfreq() const {
		return N;
	}
	
	inline float set_load_factor(float value) {
		return load_factor=value;
	}
	
	void grow();
	void sort();
	
	dictionary(char *filename,int size=DICT_INITSIZE,float lf=DICTIONARY_LOAD_FACTOR);
	dictionary(dictionary* d, bool prune=false,int prunethresh=0); //make a copy and eventually filter out unfrequent words
	
	~dictionary();
	void generate(char *filename,bool header=false);
	void load(char *filename);
	void save(char *filename, int freqflag=0);
	void load(std::istream& fd);
	void save(std::ostream& fd);
	
	void augment(dictionary *d);
	
	int size() const {
		return n;
	}
	int getcode(const char *w);
	int encode(const char *w);
	
	const char *decode(int c) const;
	void stat() const;
	
	void print_curve_growth(int curvesize) const;
	void print_curve_oov(int curvesize, const char *filename, int listflag=0);
	
	void cleanfreq() {
		for (int i=0; i<n; ++i){ tb[i].freq=0; };
		N=0;
	}
	
	inline dict_entry* scan(HT_ACTION action) {
		return  (dict_entry*) htb->scan(action);
	}
};

class dictionary_iter
{
public:
	dictionary_iter(dictionary *dict);
	dict_entry* next();
private:
	dictionary* m_dict;
};
#endif