1 /* config_file.cc: configuration load for trec experiments
3 * ----START-LICENCE----
4 * Copyright 2003 Andy MacFarlane, City University
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License as
8 * published by the Free Software Foundation; either version 2 of the
9 * License, or (at your option) any later version.
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.
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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * -----END-LICENCE-----
28 #include "config_file.h"
31 using namespace Xapian
;
34 void CONFIG_TREC::record_tag( string config_tag
, string config_value
) {
38 if( config_tag
== "textfile" ) {
39 textfile
= config_value
;
42 if( config_tag
== "stopsfile" ) {
43 stopsfile
= config_value
;
46 if( config_tag
== "language" ) {
47 language
= config_value
;
50 if( config_tag
== "db" ) {
54 if( config_tag
== "querytype" ) {
55 querytype
= config_value
;
58 if( config_tag
== "queryfile" ) {
59 queryfile
= config_value
;
62 if( config_tag
== "resultsfile" ) {
63 resultsfile
= config_value
;
66 if( config_tag
== "transfile" ) {
67 transfile
= config_value
;
70 if( config_tag
== "noresults" ) {
71 noresults
= atoi(config_value
.c_str());
74 if( config_tag
== "const_k1" ) {
75 const_k1
= atof(config_value
.c_str());
78 if( config_tag
== "const_b" ) {
79 const_b
= atof(config_value
.c_str());
82 if( config_tag
== "topicfile" ) {
83 topicfile
= config_value
;
86 if( config_tag
== "topicfields" ) {
87 topicfields
= config_value
;
90 if( config_tag
== "relfile" ) {
91 relfile
= config_value
;
94 if( config_tag
== "runname" ) {
95 runname
= config_value
;
98 if( config_tag
== "nterms" ) {
99 nterms
= atoi(config_value
.c_str());
104 cout
<< "ERROR: could not locate tag [" << config_tag
<< "] for value [" << config_value
110 void CONFIG_TREC::setup_config( string filename
) {
113 textfile
= "noneassigned"; // must enter a file/dir for text
114 language
= "english"; // corpus language
115 db
= "noneassigned"; // must enter path of database
116 querytype
= "n"; // type of query: default is n=normal
117 queryfile
= "noneassigned"; // must enter path/filename of query file
118 resultsfile
= "trec.log"; // path/filename of results file
119 transfile
= "transaction.log"; // transaction log file (timings etc)
120 noresults
= 1000; // no of results to save in results log file
121 const_k1
= 1.2; // value for K1 constant (BM25)
122 const_b
= 0.75; // value for B constant (BM25)
123 topicfile
= "noneassigned"; // path/filename of topic file
124 topicfields
= "t"; // fields of topic to use from topic file: default title
125 relfile
= "noneassigned"; // path/filename of relevance judgements file
126 runname
= "xapiantrec"; // name of the run
127 nterms
= 100; // no of terms to pick from the topic
129 std::ifstream
configfile( filename
.c_str() );
132 cerr
<< "ERROR: you must specify a valid configuration file name" << endl
;
134 } //else cout << "CONFIG) Opened configuration file: " << filename << endl;
136 while( !configfile
.eof() ) {
138 // read in lines from the configuration file
145 // identify and save information from the configuration file
146 if( !configfile
.eof() ) {
151 //cout << "GOT) values [" << config_tag << "] and [" << config_value << "]" << endl;
154 if( !configfile
.eof() ) record_tag( config_tag
, config_value
);
159 } // END setup_config
161 int CONFIG_TREC::check_query_config() {
162 // ensure that all the information required by query generator has been entered in config file
164 if( queryfile
== "noneassigned" ) {
165 cerr
<< "ERROR: you must specify the query file" << endl
;
168 if( stopsfile
== "noneassigned" ) {
169 cerr
<< "ERROR: you must specify the stop word file" << endl
;
172 if( topicfile
== "noneassigned" ) {
173 cerr
<< "ERROR: you must specify the topic file" << endl
;
176 if( db
== "noneassigned" ) {
177 cerr
<< "ERROR: you must specify the db path" << endl
;
183 } // END check_query_config
185 int CONFIG_TREC::check_index_config( ) {
186 // ensure that all the information required by indexer has been entered in config file
188 if( stopsfile
== "noneassigned" ) {
189 cerr
<< "ERROR: you must specify the stops file" << endl
;
193 if( db
== "noneassigned" ) {
194 cerr
<< "ERROR: you must specify the db path" << endl
;
198 if( textfile
== "noneassigned" ) {
199 cerr
<< "ERROR: you must specify the db path" << endl
;
205 } // END check_index_config
207 int CONFIG_TREC::check_search_config( ) {
208 // ensure that all the information required by search program has been entered in config file
210 if( queryfile
== "noneassigned" ) {
211 cerr
<< "ERROR: you must specify the " << endl
;
214 if( stopsfile
== "noneassigned" ) {
215 cerr
<< "ERROR: you must specify the " << endl
;
221 } // END check_search_config