-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathCS-GenerateSamples-MASTER.pl
More file actions
127 lines (100 loc) · 4.24 KB
/
CS-GenerateSamples-MASTER.pl
File metadata and controls
127 lines (100 loc) · 4.24 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#!/usr/bin/perl
use warnings;
use strict;
use utf8;
use Carp;
binmode(STDOUT, ":utf8");
binmode(STDERR, ":utf8");
### DO NOT INCLUDE
use ColdStartLib;
### DO INCLUDE
#####################################################################################
# This program generates the bootstrap-resamples file needed by the 2016 scorer
#
# Authors: Shahzad Rajput
# Please send questions or comments to shahzad "dot" "rajput "at" gmail "dot" com
#
# For usage, run with no arguments
#####################################################################################
my $version = "1.1";
# Filehandles for program and error output
my $program_output;
my $error_output;
### DO NOT INCLUDE
#####################################################################################
# Library inclusions
#####################################################################################
### DO INCLUDE
### DO INCLUDE Utils ColdStartLib.pm
### DO INCLUDE Patterns ColdStartLib.pm
### DO INCLUDE Logger ColdStartLib.pm
### DO INCLUDE Provenance ColdStartLib.pm
### DO INCLUDE Predicates ColdStartLib.pm
### DO INCLUDE Query ColdStartLib.pm
### DO INCLUDE QuerySet ColdStartLib.pm
### DO INCLUDE EvaluationQueryOutput ColdStartLib.pm
### DO INCLUDE Scoring ColdStartLib.pm
### DO INCLUDE Switches ColdStartLib.pm
### DO NOT INCLUDE
# Hush up perl worrywart module. FIXME: Not sure this is still needed.
my $pattern = $main::comment_pattern;
### DO INCLUDE
# Handle run-time switches
my $switches = SwitchProcessor->new($0,
"Generate the bootstrap samples for 2016 scorer", "", "");
$switches->addHelpSwitch("help", "Show help");
$switches->addHelpSwitch("h", undef);
$switches->addVarSwitch('output_file', "Where should program output be sent? (filename, stdout or stderr)");
$switches->put('output_file', 'stdout');
$switches->addVarSwitch("error_file", "Where should error output be sent? (filename, stdout or stderr)");
$switches->put("error_file", "stderr");
$switches->addImmediateSwitch('version', sub { print "$0 version $version\n"; exit 0; }, "Print version number and exit");
$switches->addParam("num_samples", "required", "How many random bootstrap-samples to be selected?");
$switches->addParam('queries', "required", "file (one LDC query ID, SF query ID pair, separated by space, per line with an optional number separated.");
$switches->process(@ARGV);
my $logger = Logger->new();
$logger->ignore_warning('MULTIPLE_RUNIDS');
# Allow redirection of stdout and stderr
my $output_filename = $switches->get("output_file");
if (lc $output_filename eq 'stdout') {
$program_output = *STDOUT{IO};
}
elsif (lc $output_filename eq 'stderr') {
$program_output = *STDERR{IO};
}
else {
open($program_output, ">:utf8", $output_filename) or $logger->NIST_die("Could not open $output_filename: $!");
}
my $error_filename = $switches->get("error_file");
$logger->set_error_output($error_filename);
$error_output = $logger->get_error_output();
my $queries_filename = $switches->get('queries');
my $num_samples = $switches->get("num_samples");
my $index = load_index();
$logger->report_all_problems();
# The NIST submission system wants an exit code of 255 if errors are encountered
my $num_errors = $logger->get_num_errors();
$logger->NIST_die("$num_errors error" . $num_errors == 1 ? "" : "s" . "encountered")
if $num_errors;
package main;
sub load_index {
my ($queries_file, $index);
open($queries_file, $queries_filename) or $logger->NIST_die("Could not create $queries_filename: $!");
while(<$queries_file>) {
chomp;
my ($ldc_queryid, $sf_queryid) = split(/\s+/, $_);
$index->{$sf_queryid} = $ldc_queryid;
}
close($queries_file);
$index;
}
my $samples = Bootstrap->new($logger);
print $program_output $samples->generate($num_samples, $index);
$logger->close_error_output();
################################################################################
# Revision History
################################################################################
# 1.0 - Initial version
# 1.1 - Changes the input file from queries.index to queries file (i.e. file containing assessed queries)
# - Corrected a typo in the previous change that made the script to crash
1;