source: trunk/gsdl/packages/mg/src/text/bool_tester.c@ 1017

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

compiler complained about using stdin and stdout to do global
initialization - variables were never changed so they were
replaced with #defines

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