source: indexers/trunk/mgpp/text/mgpp_invf_dump.cpp@ 19822

Last change on this file since 19822 was 19822, checked in by mdewsnip, 15 years ago

Commented out all occurrences of

#define _XOPEN_SOURCE_EXTENDED 1

This was allegedly added for compilation on Solaris, but it just causes errors for me (on the NLNZ Solaris machines).

  • Property svn:keywords set to Author Date Id Revision
File size: 6.7 KB
Line 
1/**************************************************************************
2 *
3 * mgpp_invf_dump.cpp -- Program to dump uot an inverted fil
4 * Copyright (C) 1994 Neil Sharman
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19 *
20 **************************************************************************/
21
22#define _XOPEN_SOURCE 1
23// This was added for Solaris, but it makes things worse on Solaris for me...
24// #define _XOPEN_SOURCE_EXTENDED 1
25
26// need this to avoid bizarre compiler problems under VC++ 6.0
27#if defined (__WIN32__) && !defined (GSDL_USE_IOS_H)
28# include <iostream>
29#endif
30
31/* getopt is in posix.2, so cygwin should have it in unistd, but doesn't */
32#if defined (__WIN32__) || defined (__CYGWIN__)
33# include "getopt_old.h"
34#else
35# include <unistd.h>
36#endif
37
38#include "sysfuncs.h"
39#include "messages.h"
40#include "bitio_m_stdio.h"
41#include "bitio_gen.h"
42#include "netorder.h" /* [RPAP - Jan 97: Endian Ordering] */
43
44#include "mg_files.h"
45#include "locallib.h"
46#include "words.h"
47#include "invf.h"
48#include "WordData.h"
49
50static void PrintInvfWord (FILE *invfFile,
51 invf_dict_header &idh,
52 invf_file_header &ifh,
53 word_dict_el &wordEl,
54 unsigned long wordStart,
55 bool printFrags) {
56 cout << wordEl.frag_occur << " \"" << wordEl.el << "\"\n";
57
58 if (printFrags) {
59 // seek to the appropriate place in the inverted file
60 fseek (invfFile, wordStart, SEEK_SET);
61
62 stdio_bitio_buffer buffer(invfFile);
63
64 unsigned long B = BIO_Bblock_Init (idh.num_frags, wordEl.frag_occur);
65 unsigned long fragNum = 0;
66 unsigned long i;
67 for (i=0; i<wordEl.frag_occur; ++i) {
68 unsigned long delta = buffer.bblock_decode (B, NULL);
69 fragNum += delta;
70 cout << " " << fragNum;
71
72 if (!ifh.word_level_index ) {
73 unsigned long count = buffer.gamma_decode (NULL);
74 cout << "(" << count << ")";
75 } else {
76 cout << "(1)";
77 }
78 }
79
80 cout << "\n";
81
82 buffer.done();
83 }
84}
85
86static void PrintInvfTag (FILE *invfFile,
87 invf_dict_header &idh,
88 invf_file_header &/*ifh*/,
89 dict_el &tagEl,
90 unsigned long tagStart,
91 bool printFrags) {
92 cout << tagEl.frag_occur << " \"<" << tagEl.el << ">\"\n";
93
94 if (printFrags) {
95 // seek to the appropriate place in the inverted file
96 fseek (invfFile, tagStart, SEEK_SET);
97
98 stdio_bitio_buffer buffer(invfFile);
99
100 unsigned long pTag = tagEl.frag_occur*2;
101 unsigned long B = BIO_Bblock_Init (idh.num_frags+pTag, pTag);
102 unsigned long fragNum = 0;
103 unsigned long i;
104 for (i=0; i<tagEl.frag_occur; ++i) {
105 unsigned long delta = buffer.bblock_decode (B, NULL)-1;
106 fragNum += delta;
107 cout << " " << fragNum;
108 cout << "-";
109 delta = buffer.bblock_decode (B, NULL)-1;
110 fragNum += delta;
111 cout << fragNum;
112 }
113
114 cout << "\n";
115
116 buffer.done();
117 }
118}
119
120static void PrintHeaderInfo (invf_dict_header &idh,
121 invf_file_header &ifh) {
122 cerr << "Lookback: " << idh.lookback << "\n";
123 cerr << "Word Dict Size: " << idh.word_dict_size << "\n";
124 cerr << "Tag Dict Size: " << idh.tag_dict_size << "\n";
125 cerr << "Num Documents: " << idh.num_docs << "\n";
126 cerr << "Num Fragments: " << idh.num_frags << "\n";
127 cerr << "Num Words: " << idh.num_words << "\n";
128
129 cerr << "Skip Mode: " << ifh.skip_mode << "\n";
130 cerr << "Word Level Index: " << ifh.word_level_index << "\n";
131
132 cerr << "\n";
133}
134
135
136static void process_files (char *filename,
137 bool printHeader,
138 bool printWords,
139 bool printTags,
140 bool printFrags) {
141 // open the dictionary
142 FILE *dictFile = open_file (filename, INVF_DICT_SUFFIX, "rb",
143 MAGIC_STEM_BUILD, MG_ABORT);
144 invf_dict_header idh;
145 idh.Read (dictFile);
146
147 // open the inverted file
148 FILE *invfFile = open_file (filename, INVF_SUFFIX, "rb",
149 MAGIC_INVF, MG_ABORT);
150
151 invf_file_header ifh;
152 ifh.Read (invfFile);
153
154 if (ifh.skip_mode != SKIP_MODE_NO_SKIPS)
155 FatalError (1, "The invf file contains skips. Unable to dump.");
156
157 // print out header information
158 if (printHeader) {
159 PrintHeaderInfo (idh, ifh);
160 }
161
162 // open the inverted index
163 FILE *invfIdxFile = open_file (filename, INVF_IDX_SUFFIX, "rb",
164 MAGIC_INVI, MG_ABORT);
165
166 // go to the start of the word dictionary
167 fseek (dictFile, idh.word_dict_start, SEEK_SET);
168
169 // process all the words
170 if (printWords) {
171 unsigned long wordNum;
172 unsigned long wordStart;
173 word_dict_el wordEl;
174 wordEl.SetNumLevels (idh.num_levels);
175 for (wordNum=0; wordNum<idh.word_dict_size; ++wordNum) {
176 wordEl.Read (dictFile, idh.num_levels);
177 ReadUL (invfIdxFile, wordStart);
178 PrintInvfWord (invfFile, idh, ifh, wordEl, wordStart, printFrags);
179 }
180 }
181
182 // process all the tags
183 if (printTags) {
184 unsigned long tagNum;
185 unsigned long tagStart;
186 dict_el tagEl;
187 for (tagNum=0; tagNum<idh.tag_dict_size; ++tagNum) {
188 tagEl.Read (dictFile);
189 ReadUL (invfIdxFile, tagStart);
190 PrintInvfTag (invfFile, idh, ifh, tagEl, tagStart, printFrags);
191 }
192 }
193 // close the open files
194 fclose (invfIdxFile);
195 fclose (invfFile);
196 fclose (dictFile);
197}
198
199
200int main (int argc, char **argv) {
201 char *dir_name, *filename = "";
202 int ch;
203 msg_prefix = argv[0];
204 dir_name = getenv ("MGDATA");
205 opterr = 0;
206
207 bool printHeader = false;
208 bool printWords = false;
209 bool printTags = false;
210 bool printFrags = false;
211
212 msg_prefix = argv[0];
213 while ((ch = getopt (argc, argv, "hrwtnf:d:")) != -1) {
214 switch (ch) {
215 case 'f': // input file
216 filename = optarg;
217 break;
218 case 'd':
219 set_basepath(optarg);
220 break;
221 case 'r':
222 printHeader = true;
223 break;
224 case 'w':
225 printWords = true;
226 break;
227 case 'n':
228 printFrags = true;
229 break;
230 case 't':
231 printTags = true;
232 break;
233 case 'h':
234 case '?':
235 fprintf (stderr, "usage: %s [-h] [-r] [-w] [-t] [-n] [-f input_file]"
236 "[-d data directory]\n(-rwnt:print header, words, tags, fragnums)\n",
237 argv[0]);
238 exit (1);
239 }
240 }
241
242 process_files (filename, printHeader, printWords, printTags, printFrags);
243
244 return 0;
245}
Note: See TracBrowser for help on using the repository browser.