source: trunk/gsdl/src/mgpp/text/mg_invf_dict_dump.cpp@ 2468

Last change on this file since 2468 was 2468, checked in by sjboddie, 23 years ago

Fiddled about with mgpp to get it compiling on Windows under VC++ 6.0. I
still can't get it to compile under VC++ 4.2 because of some weird
behaviour in STLport.

Also tidied up a little and removed some of the old log information
that was scattered about in some of the files.

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 3.9 KB
Line 
1/**************************************************************************
2 *
3 * mg_invf_dict_dump.cpp -- Program to printthe various inverted dictionaries
4 * Copyright (C) 1999 Rodger McNab
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#define _XOPEN_SOURCE_EXTENDED 1
24
25// need this to avoid bizarre compiler problems under VC++ 6.0
26#if defined (__WIN32__) && !defined (GSDL_USE_IOS_H)
27# include <iostream>
28#endif
29
30#if defined (__WIN32__)
31# include "getopt.h"
32#else
33# include <unistd.h>
34#endif
35
36#include "sysfuncs.h"
37#include "messages.h"
38#include "mg_files.h"
39#include "invf.h"
40
41static void process_files (char *filename,
42 bool printHeader,
43 bool printWords,
44 bool printTags) {
45 // open the dictionary
46 FILE *dictFile = open_file (filename, INVF_DICT_SUFFIX, "rb",
47 MAGIC_STEM_BUILD, MG_ABORT);
48 invf_dict_header idh;
49 idh.Read (dictFile);
50
51 // print the information from the inverted dictionary file header
52 if (printHeader) {
53 cout << "lookback: " << idh.lookback << "\n";
54 cout << "word_dict_start: " << idh.word_dict_start << "\n";
55 cout << "word_dict_size: " << idh.word_dict_size << "\n";
56 cout << "tag_dict_start: " << idh.tag_dict_start << "\n";
57 cout << "tag_dict_size: " << idh.tag_dict_size << "\n";
58 cout << "num_docs: " << idh.num_docs << "\n";
59 cout << "num_frags: " << idh.num_frags << "\n";
60 cout << "num_words: " << idh.num_words << "\n";
61 cout << "total_bytes: " << idh.total_bytes << "\n";
62 cout << "index_string_bytes: " << idh.index_string_bytes << "\n";
63 cout << "num_levels: " << idh.num_levels << "\n";
64
65 cout << "\n";
66 }
67
68
69 if (printWords) {
70 fseek (dictFile, idh.word_dict_start, SEEK_SET);
71
72 unsigned long wordNum;
73 word_dict_el wordEl;
74 wordEl.SetNumLevels (idh.num_levels);
75 for (wordNum=0; wordNum<idh.word_dict_size; wordNum++) {
76 wordEl.Read (dictFile, idh.num_levels);
77 cout << "\"" << wordEl.el << "\"\n";// (" << wordNum << ")\n";
78 }
79
80 cout << "\n";
81 }
82
83 // write out the tag part of the dictionary
84 if (printTags) {
85 fseek (dictFile, idh.tag_dict_start, SEEK_SET);
86
87 unsigned long tagNum;
88 dict_el tagEl;
89 for (tagNum=0; tagNum<idh.tag_dict_size; tagNum++) {
90 // read in the next tag and inverted file pointer
91 tagEl.Read (dictFile);
92
93 cout << "\"" << tagEl.el << "\" (" << tagNum << ")\n";
94 }
95 }
96
97 // close open files
98 fclose (dictFile);
99}
100
101
102int main (int argc, char **argv) {
103 char *filename = "";
104 int ch;
105 msg_prefix = argv[0];
106 opterr = 0;
107
108 bool printHeader = false;
109 bool printWords = false;
110 bool printTags = false;
111
112 while ((ch = getopt (argc, argv, "f:d:rwth")) != -1) {
113 switch (ch) {
114 case 'f': // input file
115 filename = optarg;
116 break;
117 case 'd':
118 set_basepath (optarg);
119 break;
120 case 'r':
121 printHeader = true;
122 break;
123 case 'w':
124 printWords = true;
125 break;
126 case 't':
127 printTags = true;
128 break;
129 case 'h':
130 case '?':
131 fprintf (stderr, "usage: %s [-h] [-r] [-w] [-t] [-f input_file] "
132 "[-d data directory]\n(-rwt:print header, words, tags)\n",
133 argv[0]);
134 exit (1);
135 }
136 }
137
138 process_files (filename, printHeader, printWords, printTags);
139 return 0;
140}
Note: See TracBrowser for help on using the repository browser.