2 * @brief generates qrel file needed to prepare training file for letor
4 /* Copyright (C) 2017 Vivek Pal
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 Foundation,
18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
29 #include "gnu_getopt.h"
31 #include "clickmodel/simplifieddbn.h"
35 #define PROG_NAME "generate-qrel-file"
36 #define PROG_DESC "Generate qrel file needed to prepare training file for letor"
41 static void show_usage() {
42 cout
<< "Usage: " PROG_NAME
" [OPTIONS] FINAL_LOG QREL_FILE\n\n"
43 "FINAL_LOG is the path to log file from the 'postprocess' script.\n\n"
44 "QREL_FILE is the path to save the qrel file to.\n\n"
46 " --help display this help and exit\n"
47 " --version output version information and exit" << endl
;
51 main(int argc
, char **argv
)
53 const char * opts
= "";
54 static const struct option long_opts
[] = {
55 { "help", no_argument
, 0, OPT_HELP
},
56 { "version", no_argument
, 0, OPT_VERSION
},
61 while ((c
= gnu_getopt_long(argc
, argv
, opts
, long_opts
, 0)) != -1) {
64 cout
<< PROG_NAME
" - " PROG_DESC
"\n\n";
68 cout
<< PROG_NAME
" - " PACKAGE_STRING
<< endl
;
76 if (argc
- optind
!= 2) {
81 string final_log_file
= argv
[optind
];
82 string qrel_file
= argv
[optind
+ 1];
86 vector
<Session
> sessions
;
88 sessions
= sdbn
.build_sessions(final_log_file
);
89 } catch (std::exception
&ex
) {
90 cerr
<< ex
.what() << endl
;
95 file_q
.open(qrel_file
, ios::out
);
99 // Extract doc relevances and doc ids from each session and write
100 // to the qrel file in the required format.
101 for (auto&& session
: sessions
) {
102 vector
<pair
<string
, double>> docid_relevances
=
103 sdbn
.get_predicted_relevances(session
);
105 auto reliter
= docid_relevances
.begin();
107 for (; reliter
!= docid_relevances
.end(); ++reliter
)
108 file_q
<< session
.get_qid() << " Q0 " << (*reliter
).first
<< ' '
109 << (*reliter
).second
<< endl
;