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