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

Last change on this file since 855 was 855, checked in by sjboddie, 24 years ago

Rodgers new C++ mg

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