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