source: trunk/gsdl/src/mgpp/text/bool_tester.cpp@ 711

Last change on this file since 711 was 711, checked in by cs025, 25 years ago

Changes to eradicate Xmalloc

  • Property svn:executable set to *
  • Property svn:keywords set to Author Date Id Revision
File size: 5.0 KB
Line 
1/**************************************************************************
2 *
3 * bool_tester -- used to test bool_tree, bool_parser, bool_optimiser
4 * Copyright (C) 1994 Authors
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: bool_tester.cpp 711 1999-10-17 23:43:31Z cs025 $
21 *
22 **************************************************************************/
23
24/*
25 $Log$
26 Revision 1.2 1999/10/17 23:43:23 cs025
27 Changes to eradicate Xmalloc
28
29 Revision 1.1 1999/10/11 02:57:06 cs025
30 Base install of MG-PP
31
32 Revision 1.1 1999/08/10 21:17:45 sjboddie
33 renamed mg-1.3d directory mg
34
35 Revision 1.2 1998/11/25 07:55:41 rjmcnab
36
37 Modified mg to that you can specify the stemmer you want
38 to use via a command line option. You specify it to
39 mg_passes during the build process. The number of the
40 stemmer that you used is stored within the inverted
41 dictionary header and the stemmed dictionary header so
42 the correct stemmer is used in later stages of building
43 and querying.
44
45 Revision 1.1 1998/11/17 09:34:29 rjmcnab
46 *** empty log message ***
47
48 * Revision 1.2 1995/03/14 05:15:23 tes
49 * Updated the boolean query optimiser to do different types of optimisation.
50 * A query environment variable "optimise_type" specifies which one is to be
51 * used. Type 1 is the new one which is faster than 2.
52 *
53 * Revision 1.2 1994/10/18 06:11:05 tes
54 * The boolean optimiser seems to be modifying the parse tree
55 * like it is supposed to.
56 * Paragraph ranking now works without any text files if required to.
57 *
58 * Revision 1.1 1994/10/12 01:15:33 tes
59 * Found bugs in the existing boolean query optimiser.
60 * So decided to rewrite it.
61 * I accidentally deleted query.bool.y, but I have replaced it
62 * with bool_parser.y (which I have forgotten to add here ! ;-(
63 *
64 */
65
66static char *RCSID = "$Id: bool_tester.cpp 711 1999-10-17 23:43:31Z cs025 $";
67
68#include "sysfuncs.h"
69
70#include "local_strings.h"
71#include "term_lists.h"
72#include "bool_tree.h"
73#include "bool_parser.h"
74#include "bool_optimiser.h"
75#include "query_term_list.h" /* [RPAP - Feb 97: Term Frequency] */
76
77#define MAX_LINE_LEN 255
78#define STEMMER_NUM 0 /* Lovin's stemmer */
79#define STEM_METHOD 3
80
81#define FILE_IN stdin
82#define FILE_OUT stdout
83static char line[MAX_LINE_LEN + 1];
84
85/* --- prototypes --- */
86static char *prompt (char *str);
87
88
89/* =========================================================================
90 * Function: main
91 * Description:
92 * Input:
93 * Output:
94 * ========================================================================= */
95
96int main (int argc, char *argv[])
97{
98 bool_tree_node *tree = NULL;
99 TermList *term_list = NULL;
100 QueryTermList *query_term_list = NULL; /* [RPAP - Feb 97: Term Frequency] */
101 int opt_type = 0;
102
103 while (1)
104 {
105 int res = 0;
106 int len = 0;
107
108 /* get a line */
109 if (!prompt ("Please enter boolean expression..."))
110 break;
111
112 len = strlen (line) - 1; /* -1 => ignore the \n */
113
114 tree = ParseBool (line, len, &term_list, STEMMER_NUM, STEM_METHOD, &res,
115 NULL, 0, /* [RPAP - Jan 97: Stem Index Change] */
116 &query_term_list); /* [RPAP - Feb 97: Term Frequency] */
117
118 {
119 int done = 0;
120 while (!done)
121 {
122 if (!prompt ("Which type of optimisation 1 or 2 ?"))
123 break;
124 opt_type = atoi (line);
125 done = (opt_type == 1 || opt_type == 2);
126 }
127 }
128
129 if (!prompt ("Do you want to assign doc_counts to terms ?"))
130 break;
131
132 if (toupper (line[0]) == 'Y')
133 {
134 /* cycle thru terms asking for doc_counts */
135 int i;
136 for (i = 0; i < term_list->num; i++)
137 {
138 char str[80];
139 TermEntry *te = &(term_list->TE[i]);
140
141 sprintf (str, "Please enter doc count for term '%s'",
142 str255_to_string (te->Word, NULL));
143 prompt (str);
144 te->WE.doc_count = atoi (line);
145 printf ("doc_count = %ld\n", te->WE.doc_count);
146 } /*for */
147 } /*if */
148
149
150 if (res == 0)
151 {
152 fprintf (FILE_OUT, "\n***Parsed Expression***\n");
153 PrintBoolTree (tree, FILE_OUT);
154 fputc ('\n', FILE_OUT);
155 OptimiseBoolTree (tree, term_list, opt_type);
156 fprintf (FILE_OUT, "\n***Optimised Expression ***\n");
157 PrintBoolTree (tree, FILE_OUT);
158 fputc ('\n', FILE_OUT);
159 }
160
161 }
162 return 0;
163}
164
165/* =========================================================================
166 * Function:
167 * Description:
168 * Input:
169 * Output:
170 * ========================================================================= */
171
172static char *
173prompt (char *str)
174{
175 fprintf (FILE_OUT, "\n%s\n", str);
176 return fgets (line, MAX_LINE_LEN, FILE_IN);
177}
Note: See TracBrowser for help on using the repository browser.