retreval 0.1 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/TODO +1 -1
- data/doc/CHANGELOG.html +124 -0
- data/doc/Retreval.html +212 -0
- data/doc/Retreval/Document.html +297 -0
- data/doc/Retreval/GoldStandard.html +1013 -0
- data/doc/Retreval/Judgement.html +353 -0
- data/doc/Retreval/Options.html +406 -0
- data/doc/Retreval/Query.html +296 -0
- data/doc/Retreval/QueryResult.html +746 -0
- data/doc/Retreval/QueryResultSet.html +429 -0
- data/doc/Retreval/RankedQueryResult.html +556 -0
- data/doc/Retreval/ResultDocument.html +253 -0
- data/doc/Retreval/Runner.html +506 -0
- data/doc/Retreval/UnrankedQueryResult.html +278 -0
- data/doc/Retreval/User.html +354 -0
- data/doc/TODO.html +124 -0
- data/doc/TestGoldStandard.html +551 -0
- data/doc/TestQueryResult.html +606 -0
- data/doc/bin/retreval.html +54 -0
- data/doc/created.rid +10 -0
- data/doc/index.html +218 -0
- data/doc/lib/retreval/gold_standard_rb.html +52 -0
- data/doc/lib/retreval/options_rb.html +56 -0
- data/doc/lib/retreval/query_result_rb.html +54 -0
- data/doc/lib/retreval/runner_rb.html +56 -0
- data/doc/rdoc.css +706 -0
- data/doc/test/test_gold_standard_rb.html +56 -0
- data/doc/test/test_query_result_rb.html +58 -0
- data/lib/retreval/gold_standard.rb +6 -9
- data/lib/retreval/query_result.rb +5 -2
- data/retreval.gemspec +1 -1
- metadata +29 -2
@@ -0,0 +1,296 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Class: Retreval::Query</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="../js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="../js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="../js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="../js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="class">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="../index.html">Home</a>
|
29
|
+
<a href="../index.html#classes">Classes</a>
|
30
|
+
<a href="../index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="../lib/retreval/gold_standard_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="lib/retreval/gold_standard.rb">lib/retreval/gold_standard.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="class-metadata">
|
52
|
+
|
53
|
+
<!-- Parent Class -->
|
54
|
+
|
55
|
+
<div id="parent-class-section" class="section">
|
56
|
+
<h3 class="section-header">Parent</h3>
|
57
|
+
|
58
|
+
<p class="link">Object</p>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
|
62
|
+
|
63
|
+
<!-- Namespace Contents -->
|
64
|
+
|
65
|
+
|
66
|
+
<!-- Method Quickref -->
|
67
|
+
|
68
|
+
<div id="method-list-section" class="section">
|
69
|
+
<h3 class="section-header">Methods</h3>
|
70
|
+
<ul class="link-list">
|
71
|
+
|
72
|
+
<li><a href="#method-c-new">::new</a></li>
|
73
|
+
|
74
|
+
<li><a href="#method-i-%3D%3D">#==</a></li>
|
75
|
+
|
76
|
+
</ul>
|
77
|
+
</div>
|
78
|
+
|
79
|
+
|
80
|
+
<!-- Included Modules -->
|
81
|
+
|
82
|
+
</div>
|
83
|
+
|
84
|
+
<div id="project-metadata">
|
85
|
+
|
86
|
+
|
87
|
+
<div id="fileindex-section" class="section project-section">
|
88
|
+
<h3 class="section-header">Files</h3>
|
89
|
+
<ul>
|
90
|
+
|
91
|
+
<li class="file"><a href="../CHANGELOG.html">CHANGELOG</a></li>
|
92
|
+
|
93
|
+
<li class="file"><a href="../TODO.html">TODO</a></li>
|
94
|
+
|
95
|
+
</ul>
|
96
|
+
</div>
|
97
|
+
|
98
|
+
|
99
|
+
<div id="classindex-section" class="section project-section">
|
100
|
+
<h3 class="section-header">Class Index
|
101
|
+
<span class="search-toggle"><img src="../images/find.png"
|
102
|
+
height="16" width="16" alt="[+]"
|
103
|
+
title="show/hide quicksearch" /></span></h3>
|
104
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
105
|
+
<fieldset>
|
106
|
+
<legend>Quicksearch</legend>
|
107
|
+
<input type="text" name="quicksearch" value=""
|
108
|
+
class="quicksearch-field" />
|
109
|
+
</fieldset>
|
110
|
+
</form>
|
111
|
+
|
112
|
+
<ul class="link-list">
|
113
|
+
|
114
|
+
<li><a href="../Retreval.html">Retreval</a></li>
|
115
|
+
|
116
|
+
<li><a href="../Retreval/Document.html">Retreval::Document</a></li>
|
117
|
+
|
118
|
+
<li><a href="../Retreval/GoldStandard.html">Retreval::GoldStandard</a></li>
|
119
|
+
|
120
|
+
<li><a href="../Retreval/Judgement.html">Retreval::Judgement</a></li>
|
121
|
+
|
122
|
+
<li><a href="../Retreval/Options.html">Retreval::Options</a></li>
|
123
|
+
|
124
|
+
<li><a href="../Retreval/Query.html">Retreval::Query</a></li>
|
125
|
+
|
126
|
+
<li><a href="../Retreval/QueryResult.html">Retreval::QueryResult</a></li>
|
127
|
+
|
128
|
+
<li><a href="../Retreval/QueryResultSet.html">Retreval::QueryResultSet</a></li>
|
129
|
+
|
130
|
+
<li><a href="../Retreval/RankedQueryResult.html">Retreval::RankedQueryResult</a></li>
|
131
|
+
|
132
|
+
<li><a href="../Retreval/ResultDocument.html">Retreval::ResultDocument</a></li>
|
133
|
+
|
134
|
+
<li><a href="../Retreval/Runner.html">Retreval::Runner</a></li>
|
135
|
+
|
136
|
+
<li><a href="../Retreval/UnrankedQueryResult.html">Retreval::UnrankedQueryResult</a></li>
|
137
|
+
|
138
|
+
<li><a href="../Retreval/User.html">Retreval::User</a></li>
|
139
|
+
|
140
|
+
<li><a href="../TestGoldStandard.html">TestGoldStandard</a></li>
|
141
|
+
|
142
|
+
<li><a href="../TestQueryResult.html">TestQueryResult</a></li>
|
143
|
+
|
144
|
+
</ul>
|
145
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
146
|
+
</div>
|
147
|
+
|
148
|
+
|
149
|
+
</div>
|
150
|
+
</div>
|
151
|
+
|
152
|
+
<div id="documentation">
|
153
|
+
<h1 class="class">Retreval::Query</h1>
|
154
|
+
|
155
|
+
<div id="description">
|
156
|
+
<p>
|
157
|
+
A <a href="Query.html">Query</a> is effectively a string that is used as
|
158
|
+
its ID.
|
159
|
+
</p>
|
160
|
+
|
161
|
+
</div>
|
162
|
+
|
163
|
+
<!-- Constants -->
|
164
|
+
|
165
|
+
|
166
|
+
<!-- Attributes -->
|
167
|
+
|
168
|
+
<div id="attribute-method-details" class="method-section section">
|
169
|
+
<h3 class="section-header">Attributes</h3>
|
170
|
+
|
171
|
+
|
172
|
+
<div id="querystring-attribute-method" class="method-detail">
|
173
|
+
<a name="querystring"></a>
|
174
|
+
|
175
|
+
<div class="method-heading attribute-method-heading">
|
176
|
+
<span class="method-name">querystring</span><span
|
177
|
+
class="attribute-access-type">[R]</span>
|
178
|
+
</div>
|
179
|
+
|
180
|
+
<div class="method-description">
|
181
|
+
|
182
|
+
|
183
|
+
|
184
|
+
</div>
|
185
|
+
</div>
|
186
|
+
|
187
|
+
</div>
|
188
|
+
|
189
|
+
|
190
|
+
<!-- Methods -->
|
191
|
+
|
192
|
+
<div id="public-class-method-details" class="method-section section">
|
193
|
+
<h3 class="section-header">Public Class Methods</h3>
|
194
|
+
|
195
|
+
|
196
|
+
<div id="new-method" class="method-detail ">
|
197
|
+
<a name="method-c-new"></a>
|
198
|
+
|
199
|
+
<div class="method-heading">
|
200
|
+
|
201
|
+
<span class="method-name">new</span><span
|
202
|
+
class="method-args">(args)</span>
|
203
|
+
<span class="method-click-advice">click to toggle source</span>
|
204
|
+
|
205
|
+
</div>
|
206
|
+
|
207
|
+
<div class="method-description">
|
208
|
+
|
209
|
+
<p>
|
210
|
+
Creates a new <a href="Query.html">Query</a> object with a specified string
|
211
|
+
</p>
|
212
|
+
|
213
|
+
|
214
|
+
|
215
|
+
<div class="method-source-code"
|
216
|
+
id="new-source">
|
217
|
+
<pre>
|
218
|
+
<span class="ruby-comment cmt"># File lib/retreval/gold_standard.rb, line 342</span>
|
219
|
+
342: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">args</span>)
|
220
|
+
343: <span class="ruby-ivar">@querystring</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:querystring</span>].<span class="ruby-identifier">to_s</span>
|
221
|
+
344: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can not construct a Query with an empty query string"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@querystring</span>.<span class="ruby-identifier">nil?</span>
|
222
|
+
345: <span class="ruby-keyword kw">end</span></pre>
|
223
|
+
</div>
|
224
|
+
|
225
|
+
</div>
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
|
230
|
+
</div>
|
231
|
+
|
232
|
+
|
233
|
+
</div>
|
234
|
+
|
235
|
+
<div id="public-instance-method-details" class="method-section section">
|
236
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
237
|
+
|
238
|
+
|
239
|
+
<div id="--method" class="method-detail ">
|
240
|
+
<a name="method-i-%3D%3D"></a>
|
241
|
+
|
242
|
+
<div class="method-heading">
|
243
|
+
|
244
|
+
<span class="method-name">==</span><span
|
245
|
+
class="method-args">(query)</span>
|
246
|
+
<span class="method-click-advice">click to toggle source</span>
|
247
|
+
|
248
|
+
</div>
|
249
|
+
|
250
|
+
<div class="method-description">
|
251
|
+
|
252
|
+
<p>
|
253
|
+
Compares two <a href="Query.html">Query</a> objects according to their
|
254
|
+
query string
|
255
|
+
</p>
|
256
|
+
|
257
|
+
|
258
|
+
|
259
|
+
<div class="method-source-code"
|
260
|
+
id="--source">
|
261
|
+
<pre>
|
262
|
+
<span class="ruby-comment cmt"># File lib/retreval/gold_standard.rb, line 337</span>
|
263
|
+
337: <span class="ruby-keyword kw">def</span> <span class="ruby-operator">==</span>(<span class="ruby-identifier">query</span>)
|
264
|
+
338: <span class="ruby-identifier">query</span>.<span class="ruby-identifier">querystring</span> <span class="ruby-operator">==</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">querystring</span>
|
265
|
+
339: <span class="ruby-keyword kw">end</span></pre>
|
266
|
+
</div>
|
267
|
+
|
268
|
+
</div>
|
269
|
+
|
270
|
+
|
271
|
+
|
272
|
+
|
273
|
+
</div>
|
274
|
+
|
275
|
+
|
276
|
+
</div>
|
277
|
+
|
278
|
+
|
279
|
+
</div>
|
280
|
+
|
281
|
+
|
282
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
283
|
+
|
284
|
+
<p>Disabled; run with --debug to generate this.</p>
|
285
|
+
|
286
|
+
</div>
|
287
|
+
|
288
|
+
<div id="validator-badges">
|
289
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
290
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
291
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
292
|
+
</div>
|
293
|
+
|
294
|
+
</body>
|
295
|
+
</html>
|
296
|
+
|
@@ -0,0 +1,746 @@
|
|
1
|
+
<?xml version="1.0" encoding="utf-8"?>
|
2
|
+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
|
3
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
4
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
5
|
+
<head>
|
6
|
+
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
|
7
|
+
|
8
|
+
<title>Class: Retreval::QueryResult</title>
|
9
|
+
|
10
|
+
<link rel="stylesheet" href="../rdoc.css" type="text/css" media="screen" />
|
11
|
+
|
12
|
+
<script src="../js/jquery.js" type="text/javascript"
|
13
|
+
charset="utf-8"></script>
|
14
|
+
<script src="../js/thickbox-compressed.js" type="text/javascript"
|
15
|
+
charset="utf-8"></script>
|
16
|
+
<script src="../js/quicksearch.js" type="text/javascript"
|
17
|
+
charset="utf-8"></script>
|
18
|
+
<script src="../js/darkfish.js" type="text/javascript"
|
19
|
+
charset="utf-8"></script>
|
20
|
+
|
21
|
+
</head>
|
22
|
+
<body class="class">
|
23
|
+
|
24
|
+
<div id="metadata">
|
25
|
+
<div id="home-metadata">
|
26
|
+
<div id="home-section" class="section">
|
27
|
+
<h3 class="section-header">
|
28
|
+
<a href="../index.html">Home</a>
|
29
|
+
<a href="../index.html#classes">Classes</a>
|
30
|
+
<a href="../index.html#methods">Methods</a>
|
31
|
+
</h3>
|
32
|
+
</div>
|
33
|
+
</div>
|
34
|
+
|
35
|
+
<div id="file-metadata">
|
36
|
+
<div id="file-list-section" class="section">
|
37
|
+
<h3 class="section-header">In Files</h3>
|
38
|
+
<div class="section-body">
|
39
|
+
<ul>
|
40
|
+
|
41
|
+
<li><a href="../lib/retreval/query_result_rb.html?TB_iframe=true&height=550&width=785"
|
42
|
+
class="thickbox" title="lib/retreval/query_result.rb">lib/retreval/query_result.rb</a></li>
|
43
|
+
|
44
|
+
</ul>
|
45
|
+
</div>
|
46
|
+
</div>
|
47
|
+
|
48
|
+
|
49
|
+
</div>
|
50
|
+
|
51
|
+
<div id="class-metadata">
|
52
|
+
|
53
|
+
<!-- Parent Class -->
|
54
|
+
|
55
|
+
<div id="parent-class-section" class="section">
|
56
|
+
<h3 class="section-header">Parent</h3>
|
57
|
+
|
58
|
+
<p class="link">Object</p>
|
59
|
+
|
60
|
+
</div>
|
61
|
+
|
62
|
+
|
63
|
+
<!-- Namespace Contents -->
|
64
|
+
|
65
|
+
|
66
|
+
<!-- Method Quickref -->
|
67
|
+
|
68
|
+
<div id="method-list-section" class="section">
|
69
|
+
<h3 class="section-header">Methods</h3>
|
70
|
+
<ul class="link-list">
|
71
|
+
|
72
|
+
<li><a href="#method-c-new">::new</a></li>
|
73
|
+
|
74
|
+
<li><a href="#method-i-%3C%3C">#<<</a></li>
|
75
|
+
|
76
|
+
<li><a href="#method-i-add_document">#add_document</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-i-calculate">#calculate</a></li>
|
79
|
+
|
80
|
+
<li><a href="#method-i-cleanup">#cleanup</a></li>
|
81
|
+
|
82
|
+
<li><a href="#method-i-f_measure">#f_measure</a></li>
|
83
|
+
|
84
|
+
<li><a href="#method-i-load_from_yaml_file">#load_from_yaml_file</a></li>
|
85
|
+
|
86
|
+
<li><a href="#method-i-print_contingency_table">#print_contingency_table</a></li>
|
87
|
+
|
88
|
+
</ul>
|
89
|
+
</div>
|
90
|
+
|
91
|
+
|
92
|
+
<!-- Included Modules -->
|
93
|
+
|
94
|
+
</div>
|
95
|
+
|
96
|
+
<div id="project-metadata">
|
97
|
+
|
98
|
+
|
99
|
+
<div id="fileindex-section" class="section project-section">
|
100
|
+
<h3 class="section-header">Files</h3>
|
101
|
+
<ul>
|
102
|
+
|
103
|
+
<li class="file"><a href="../CHANGELOG.html">CHANGELOG</a></li>
|
104
|
+
|
105
|
+
<li class="file"><a href="../TODO.html">TODO</a></li>
|
106
|
+
|
107
|
+
</ul>
|
108
|
+
</div>
|
109
|
+
|
110
|
+
|
111
|
+
<div id="classindex-section" class="section project-section">
|
112
|
+
<h3 class="section-header">Class Index
|
113
|
+
<span class="search-toggle"><img src="../images/find.png"
|
114
|
+
height="16" width="16" alt="[+]"
|
115
|
+
title="show/hide quicksearch" /></span></h3>
|
116
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
117
|
+
<fieldset>
|
118
|
+
<legend>Quicksearch</legend>
|
119
|
+
<input type="text" name="quicksearch" value=""
|
120
|
+
class="quicksearch-field" />
|
121
|
+
</fieldset>
|
122
|
+
</form>
|
123
|
+
|
124
|
+
<ul class="link-list">
|
125
|
+
|
126
|
+
<li><a href="../Retreval.html">Retreval</a></li>
|
127
|
+
|
128
|
+
<li><a href="../Retreval/Document.html">Retreval::Document</a></li>
|
129
|
+
|
130
|
+
<li><a href="../Retreval/GoldStandard.html">Retreval::GoldStandard</a></li>
|
131
|
+
|
132
|
+
<li><a href="../Retreval/Judgement.html">Retreval::Judgement</a></li>
|
133
|
+
|
134
|
+
<li><a href="../Retreval/Options.html">Retreval::Options</a></li>
|
135
|
+
|
136
|
+
<li><a href="../Retreval/Query.html">Retreval::Query</a></li>
|
137
|
+
|
138
|
+
<li><a href="../Retreval/QueryResult.html">Retreval::QueryResult</a></li>
|
139
|
+
|
140
|
+
<li><a href="../Retreval/QueryResultSet.html">Retreval::QueryResultSet</a></li>
|
141
|
+
|
142
|
+
<li><a href="../Retreval/RankedQueryResult.html">Retreval::RankedQueryResult</a></li>
|
143
|
+
|
144
|
+
<li><a href="../Retreval/ResultDocument.html">Retreval::ResultDocument</a></li>
|
145
|
+
|
146
|
+
<li><a href="../Retreval/Runner.html">Retreval::Runner</a></li>
|
147
|
+
|
148
|
+
<li><a href="../Retreval/UnrankedQueryResult.html">Retreval::UnrankedQueryResult</a></li>
|
149
|
+
|
150
|
+
<li><a href="../Retreval/User.html">Retreval::User</a></li>
|
151
|
+
|
152
|
+
<li><a href="../TestGoldStandard.html">TestGoldStandard</a></li>
|
153
|
+
|
154
|
+
<li><a href="../TestQueryResult.html">TestQueryResult</a></li>
|
155
|
+
|
156
|
+
</ul>
|
157
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
158
|
+
</div>
|
159
|
+
|
160
|
+
|
161
|
+
</div>
|
162
|
+
</div>
|
163
|
+
|
164
|
+
<div id="documentation">
|
165
|
+
<h1 class="class">Retreval::QueryResult</h1>
|
166
|
+
|
167
|
+
<div id="description">
|
168
|
+
<p>
|
169
|
+
A <a href="QueryResult.html">QueryResult</a> contains a list of results for
|
170
|
+
a given query. It can either be ranked or unranked. You can’t
|
171
|
+
instantiate such a class - use the subclasses <a
|
172
|
+
href="RankedQueryResult.html">RankedQueryResult</a> and <a
|
173
|
+
href="UnrankedQueryResult.html">UnrankedQueryResult</a> instead.
|
174
|
+
</p>
|
175
|
+
|
176
|
+
</div>
|
177
|
+
|
178
|
+
<!-- Constants -->
|
179
|
+
|
180
|
+
|
181
|
+
<!-- Attributes -->
|
182
|
+
|
183
|
+
<div id="attribute-method-details" class="method-section section">
|
184
|
+
<h3 class="section-header">Attributes</h3>
|
185
|
+
|
186
|
+
|
187
|
+
<div id="query-attribute-method" class="method-detail">
|
188
|
+
<a name="query"></a>
|
189
|
+
|
190
|
+
<div class="method-heading attribute-method-heading">
|
191
|
+
<span class="method-name">query</span><span
|
192
|
+
class="attribute-access-type">[R]</span>
|
193
|
+
</div>
|
194
|
+
|
195
|
+
<div class="method-description">
|
196
|
+
|
197
|
+
|
198
|
+
|
199
|
+
</div>
|
200
|
+
</div>
|
201
|
+
|
202
|
+
<div id="documents-attribute-method" class="method-detail">
|
203
|
+
<a name="documents"></a>
|
204
|
+
|
205
|
+
<div class="method-heading attribute-method-heading">
|
206
|
+
<span class="method-name">documents</span><span
|
207
|
+
class="attribute-access-type">[R]</span>
|
208
|
+
</div>
|
209
|
+
|
210
|
+
<div class="method-description">
|
211
|
+
|
212
|
+
|
213
|
+
|
214
|
+
</div>
|
215
|
+
</div>
|
216
|
+
|
217
|
+
<div id="gold-standard-attribute-method" class="method-detail">
|
218
|
+
<a name="gold_standard"></a>
|
219
|
+
|
220
|
+
<a name="gold_standard="></a>
|
221
|
+
|
222
|
+
<div class="method-heading attribute-method-heading">
|
223
|
+
<span class="method-name">gold_standard</span><span
|
224
|
+
class="attribute-access-type">[RW]</span>
|
225
|
+
</div>
|
226
|
+
|
227
|
+
<div class="method-description">
|
228
|
+
|
229
|
+
|
230
|
+
|
231
|
+
</div>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
</div>
|
235
|
+
|
236
|
+
|
237
|
+
<!-- Methods -->
|
238
|
+
|
239
|
+
<div id="public-class-method-details" class="method-section section">
|
240
|
+
<h3 class="section-header">Public Class Methods</h3>
|
241
|
+
|
242
|
+
|
243
|
+
<div id="new-method" class="method-detail ">
|
244
|
+
<a name="method-c-new"></a>
|
245
|
+
|
246
|
+
<div class="method-heading">
|
247
|
+
|
248
|
+
<span class="method-name">new</span><span
|
249
|
+
class="method-args">(args)</span>
|
250
|
+
<span class="method-click-advice">click to toggle source</span>
|
251
|
+
|
252
|
+
</div>
|
253
|
+
|
254
|
+
<div class="method-description">
|
255
|
+
|
256
|
+
<p>
|
257
|
+
Creates a new <a href="QueryResult.html">QueryResult</a> with a specified
|
258
|
+
query string and an optional array of documents. This class is abstract, so
|
259
|
+
you have to create an <a
|
260
|
+
href="UnrankedQueryResult.html">UnrankedQueryResult</a> or a <a
|
261
|
+
href="RankedQueryResult.html">RankedQueryResult</a> instead
|
262
|
+
</p>
|
263
|
+
|
264
|
+
|
265
|
+
|
266
|
+
<div class="method-source-code"
|
267
|
+
id="new-source">
|
268
|
+
<pre>
|
269
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 96</span>
|
270
|
+
96: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">args</span>)
|
271
|
+
97:
|
272
|
+
98: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">QueryResult</span>
|
273
|
+
99: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can not instantiate a QueryResult. Use a RankedQueryResult or UnrankedQueryResult instead."</span>
|
274
|
+
100: <span class="ruby-keyword kw">end</span>
|
275
|
+
101:
|
276
|
+
102: <span class="ruby-comment cmt"># Get the string of the query</span>
|
277
|
+
103: <span class="ruby-ivar">@query</span> = <span class="ruby-constant">Query</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:querystring</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:query</span>]
|
278
|
+
104: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can not create a Query Result without a query string specified"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:query</span>].<span class="ruby-identifier">nil?</span>
|
279
|
+
105:
|
280
|
+
106: <span class="ruby-comment cmt"># get the documents</span>
|
281
|
+
107: <span class="ruby-comment cmt"># documents is a Hash - each document contains a document (from the Class document) with a score</span>
|
282
|
+
108: <span class="ruby-comment cmt"># documents can also be omitted from the call and can be added later</span>
|
283
|
+
109: <span class="ruby-ivar">@documents</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
|
284
|
+
110: <span class="ruby-identifier">args</span>[<span class="ruby-value">:documents</span>].<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">document</span><span class="ruby-operator">|</span> <span class="ruby-identifier">add_document</span>(<span class="ruby-identifier">document</span>) } <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:documents</span>].<span class="ruby-identifier">nil?</span>
|
285
|
+
111:
|
286
|
+
112: <span class="ruby-comment cmt"># set the gold standard</span>
|
287
|
+
113: <span class="ruby-ivar">@gold_standard</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:gold_standard</span>]
|
288
|
+
114: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can not create a Query Result without a gold standard that it belongs to"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:gold_standard</span>].<span class="ruby-identifier">nil?</span>
|
289
|
+
115:
|
290
|
+
116: <span class="ruby-keyword kw">end</span></pre>
|
291
|
+
</div>
|
292
|
+
|
293
|
+
</div>
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
|
298
|
+
</div>
|
299
|
+
|
300
|
+
|
301
|
+
</div>
|
302
|
+
|
303
|
+
<div id="public-instance-method-details" class="method-section section">
|
304
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
305
|
+
|
306
|
+
|
307
|
+
<div id="--method" class="method-detail ">
|
308
|
+
<a name="method-i-%3C%3C"></a>
|
309
|
+
|
310
|
+
<div class="method-heading">
|
311
|
+
|
312
|
+
<span class="method-name"><<</span><span
|
313
|
+
class="method-args">(args)</span>
|
314
|
+
<span class="method-click-advice">click to toggle source</span>
|
315
|
+
|
316
|
+
</div>
|
317
|
+
|
318
|
+
<div class="method-description">
|
319
|
+
|
320
|
+
<p>
|
321
|
+
This is essentially the same as <a
|
322
|
+
href="QueryResult.html#method-i-add_document">add_document</a>
|
323
|
+
</p>
|
324
|
+
|
325
|
+
|
326
|
+
|
327
|
+
<div class="method-source-code"
|
328
|
+
id="--source">
|
329
|
+
<pre>
|
330
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 161</span>
|
331
|
+
161: <span class="ruby-keyword kw">def</span> <span class="ruby-operator"><<</span>(<span class="ruby-identifier">args</span>)
|
332
|
+
162: <span class="ruby-identifier">add_document</span> <span class="ruby-identifier">args</span>
|
333
|
+
163: <span class="ruby-keyword kw">end</span></pre>
|
334
|
+
</div>
|
335
|
+
|
336
|
+
</div>
|
337
|
+
|
338
|
+
|
339
|
+
|
340
|
+
|
341
|
+
</div>
|
342
|
+
|
343
|
+
|
344
|
+
<div id="add-document-method" class="method-detail ">
|
345
|
+
<a name="method-i-add_document"></a>
|
346
|
+
|
347
|
+
<div class="method-heading">
|
348
|
+
|
349
|
+
<span class="method-name">add_document</span><span
|
350
|
+
class="method-args">(args)</span>
|
351
|
+
<span class="method-click-advice">click to toggle source</span>
|
352
|
+
|
353
|
+
</div>
|
354
|
+
|
355
|
+
<div class="method-description">
|
356
|
+
|
357
|
+
<p>
|
358
|
+
Adds a single <a href="ResultDocument.html">ResultDocument</a> to the
|
359
|
+
result Call this with:
|
360
|
+
</p>
|
361
|
+
<pre>
|
362
|
+
add_document :document => "test_document", :score => 13
|
363
|
+
</pre>
|
364
|
+
<p>
|
365
|
+
Alternatively:
|
366
|
+
</p>
|
367
|
+
<pre>
|
368
|
+
add_document :id => "test_document", :score => 13</pre>
|
369
|
+
|
370
|
+
|
371
|
+
|
372
|
+
<div class="method-source-code"
|
373
|
+
id="add-document-source">
|
374
|
+
<pre>
|
375
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 145</span>
|
376
|
+
145: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_document</span>(<span class="ruby-identifier">args</span>)
|
377
|
+
146: <span class="ruby-identifier">document_id</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:document</span>]
|
378
|
+
147: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">document_id</span>.<span class="ruby-identifier">nil?</span>
|
379
|
+
148: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:id</span>].<span class="ruby-identifier">nil?</span>
|
380
|
+
149: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can not add a new Document to a Query Result without a document identifier"</span>
|
381
|
+
150: <span class="ruby-keyword kw">else</span>
|
382
|
+
151: <span class="ruby-identifier">document_id</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:id</span>]
|
383
|
+
152: <span class="ruby-keyword kw">end</span>
|
384
|
+
153: <span class="ruby-keyword kw">end</span>
|
385
|
+
154:
|
386
|
+
155: <span class="ruby-identifier">doc</span> = <span class="ruby-constant">ResultDocument</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:id</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">document_id</span>, <span class="ruby-value">:score</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:score</span>]
|
387
|
+
156: <span class="ruby-ivar">@documents</span>[<span class="ruby-identifier">document_id</span>] = <span class="ruby-identifier">doc</span>
|
388
|
+
157: <span class="ruby-keyword kw">end</span></pre>
|
389
|
+
</div>
|
390
|
+
|
391
|
+
</div>
|
392
|
+
|
393
|
+
|
394
|
+
|
395
|
+
|
396
|
+
</div>
|
397
|
+
|
398
|
+
|
399
|
+
<div id="cleanup-method" class="method-detail ">
|
400
|
+
<a name="method-i-cleanup"></a>
|
401
|
+
|
402
|
+
<div class="method-heading">
|
403
|
+
|
404
|
+
<span class="method-name">cleanup</span><span
|
405
|
+
class="method-args">()</span>
|
406
|
+
<span class="method-click-advice">click to toggle source</span>
|
407
|
+
|
408
|
+
</div>
|
409
|
+
|
410
|
+
<div class="method-description">
|
411
|
+
|
412
|
+
<p>
|
413
|
+
Clean up every <a href="ResultDocument.html">ResultDocument</a> from this
|
414
|
+
<a href="QueryResult.html">QueryResult</a> that does not appear to have a
|
415
|
+
<a href="Judgement.html">Judgement</a> in the <a
|
416
|
+
href="GoldStandard.html">GoldStandard</a>.
|
417
|
+
</p>
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
<div class="method-source-code"
|
422
|
+
id="cleanup-source">
|
423
|
+
<pre>
|
424
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 219</span>
|
425
|
+
219: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">cleanup</span>
|
426
|
+
220: <span class="ruby-ivar">@documents</span>.<span class="ruby-identifier">keep_if</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">document</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@gold_standard</span>.<span class="ruby-identifier">contains_judgement?</span> <span class="ruby-value">:document</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">document</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:query</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@query</span>.<span class="ruby-identifier">querystring</span> }
|
427
|
+
221: <span class="ruby-keyword kw">end</span></pre>
|
428
|
+
</div>
|
429
|
+
|
430
|
+
</div>
|
431
|
+
|
432
|
+
|
433
|
+
|
434
|
+
|
435
|
+
</div>
|
436
|
+
|
437
|
+
|
438
|
+
<div id="f-measure-method" class="method-detail ">
|
439
|
+
<a name="method-i-f_measure"></a>
|
440
|
+
|
441
|
+
<div class="method-heading">
|
442
|
+
|
443
|
+
<span class="method-name">f_measure</span><span
|
444
|
+
class="method-args">(args = {:beta => 1})</span>
|
445
|
+
<span class="method-click-advice">click to toggle source</span>
|
446
|
+
|
447
|
+
</div>
|
448
|
+
|
449
|
+
<div class="method-description">
|
450
|
+
|
451
|
+
<p>
|
452
|
+
Calculates the F-measure, weighing precision and recall. See: <a
|
453
|
+
href="http://nlp.stanford.edu/IR-book/html/htmledition/evaluation-of-unranked-retrieval-sets-1.html">nlp.stanford.edu/IR-book/html/htmledition/evaluation-of-unranked-retrieval-sets-1.html</a>
|
454
|
+
</p>
|
455
|
+
|
456
|
+
|
457
|
+
|
458
|
+
<div class="method-source-code"
|
459
|
+
id="f-measure-source">
|
460
|
+
<pre>
|
461
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 188</span>
|
462
|
+
188: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">f_measure</span>(<span class="ruby-identifier">args</span> = {<span class="ruby-value">:beta</span> =<span class="ruby-operator">></span> <span class="ruby-value">1</span>})
|
463
|
+
189:
|
464
|
+
190: <span class="ruby-comment cmt"># Get intermediate results for both un/ranked results</span>
|
465
|
+
191: <span class="ruby-identifier">results</span> = <span class="ruby-identifier">calculate</span>
|
466
|
+
192:
|
467
|
+
193: <span class="ruby-identifier">precision</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:precision</span>]
|
468
|
+
194: <span class="ruby-identifier">recall</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:recall</span>]
|
469
|
+
195:
|
470
|
+
196: <span class="ruby-keyword kw">begin</span>
|
471
|
+
197: <span class="ruby-comment cmt"># The user has the option to supply either alpha or beta (or both, doesn't matter)</span>
|
472
|
+
198: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:alpha</span>].<span class="ruby-identifier">nil?</span>
|
473
|
+
199: <span class="ruby-identifier">alpha</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:alpha</span>].<span class="ruby-identifier">to_f</span>
|
474
|
+
200: <span class="ruby-identifier">beta_squared</span> = (<span class="ruby-value">1</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">alpha</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">alpha</span>
|
475
|
+
201: <span class="ruby-keyword kw">end</span>
|
476
|
+
202:
|
477
|
+
203: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">args</span>[<span class="ruby-value">:beta</span>].<span class="ruby-identifier">nil?</span>
|
478
|
+
204: <span class="ruby-identifier">beta</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:beta</span>].<span class="ruby-identifier">to_f</span>
|
479
|
+
205: <span class="ruby-identifier">beta_squared</span> = <span class="ruby-identifier">beta</span> * <span class="ruby-identifier">beta</span>
|
480
|
+
206: <span class="ruby-keyword kw">end</span>
|
481
|
+
207:
|
482
|
+
208: ((<span class="ruby-identifier">beta_squared</span> <span class="ruby-operator">+</span> <span class="ruby-value">1</span>) * <span class="ruby-identifier">precision</span> * <span class="ruby-identifier">recall</span>) <span class="ruby-operator">/</span> ((<span class="ruby-identifier">beta_squared</span> * <span class="ruby-identifier">precision</span>) <span class="ruby-operator">+</span> <span class="ruby-identifier">recall</span>)
|
483
|
+
209:
|
484
|
+
210: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
485
|
+
211: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Error while calculating F-Measure: "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
486
|
+
212: <span class="ruby-keyword kw">end</span>
|
487
|
+
213:
|
488
|
+
214: <span class="ruby-keyword kw">end</span></pre>
|
489
|
+
</div>
|
490
|
+
|
491
|
+
</div>
|
492
|
+
|
493
|
+
|
494
|
+
|
495
|
+
|
496
|
+
</div>
|
497
|
+
|
498
|
+
|
499
|
+
<div id="load-from-yaml-file-method" class="method-detail ">
|
500
|
+
<a name="method-i-load_from_yaml_file"></a>
|
501
|
+
|
502
|
+
<div class="method-heading">
|
503
|
+
|
504
|
+
<span class="method-name">load_from_yaml_file</span><span
|
505
|
+
class="method-args">(file)</span>
|
506
|
+
<span class="method-click-advice">click to toggle source</span>
|
507
|
+
|
508
|
+
</div>
|
509
|
+
|
510
|
+
<div class="method-description">
|
511
|
+
|
512
|
+
<p>
|
513
|
+
Loads Documents from a simple YAML file Each entry should contain:
|
514
|
+
</p>
|
515
|
+
<ul>
|
516
|
+
<li><p>
|
517
|
+
“document” The identifier of the <a
|
518
|
+
href="Document.html">Document</a>
|
519
|
+
</p>
|
520
|
+
</li>
|
521
|
+
<li><p>
|
522
|
+
“score” The relevancy score for this <a
|
523
|
+
href="Document.html">Document</a>
|
524
|
+
</p>
|
525
|
+
</li>
|
526
|
+
</ul>
|
527
|
+
|
528
|
+
|
529
|
+
|
530
|
+
<div class="method-source-code"
|
531
|
+
id="load-from-yaml-file-source">
|
532
|
+
<pre>
|
533
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 123</span>
|
534
|
+
123: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_from_yaml_file</span>(<span class="ruby-identifier">file</span>)
|
535
|
+
124:
|
536
|
+
125: <span class="ruby-keyword kw">begin</span>
|
537
|
+
126: <span class="ruby-ivar">@ydoc</span> = <span class="ruby-constant">YAML</span><span class="ruby-operator">::</span><span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">open</span>(<span class="ruby-identifier">file</span>, <span class="ruby-value str">"r"</span>))
|
538
|
+
127: <span class="ruby-ivar">@ydoc</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">entry</span><span class="ruby-operator">|</span>
|
539
|
+
128: <span class="ruby-identifier">document</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">"document"</span>] <span class="ruby-comment cmt"># => the identifier of the document</span>
|
540
|
+
129: <span class="ruby-identifier">score</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">"score"</span>] <span class="ruby-comment cmt"># => the relevancy score</span>
|
541
|
+
130: <span class="ruby-identifier">add_document</span> <span class="ruby-value">:document</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">document</span>, <span class="ruby-value">:score</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">score</span>
|
542
|
+
131: <span class="ruby-keyword kw">end</span>
|
543
|
+
132:
|
544
|
+
133: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
545
|
+
134: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Error while parsing the YAML document: "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
546
|
+
135: <span class="ruby-keyword kw">end</span>
|
547
|
+
136:
|
548
|
+
137: <span class="ruby-keyword kw">end</span></pre>
|
549
|
+
</div>
|
550
|
+
|
551
|
+
</div>
|
552
|
+
|
553
|
+
|
554
|
+
|
555
|
+
|
556
|
+
</div>
|
557
|
+
|
558
|
+
|
559
|
+
<div id="print-contingency-table-method" class="method-detail ">
|
560
|
+
<a name="method-i-print_contingency_table"></a>
|
561
|
+
|
562
|
+
<div class="method-heading">
|
563
|
+
|
564
|
+
<span class="method-name">print_contingency_table</span><span
|
565
|
+
class="method-args">()</span>
|
566
|
+
<span class="method-click-advice">click to toggle source</span>
|
567
|
+
|
568
|
+
</div>
|
569
|
+
|
570
|
+
<div class="method-description">
|
571
|
+
|
572
|
+
<p>
|
573
|
+
Prints a pretty contingency table summary
|
574
|
+
</p>
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
<div class="method-source-code"
|
579
|
+
id="print-contingency-table-source">
|
580
|
+
<pre>
|
581
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 167</span>
|
582
|
+
167: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_contingency_table</span>
|
583
|
+
168: <span class="ruby-identifier">results</span> = <span class="ruby-identifier">calculate</span>
|
584
|
+
169:
|
585
|
+
170: <span class="ruby-identifier">tp</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:true_positives</span>]
|
586
|
+
171: <span class="ruby-identifier">fp</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:false_positives</span>]
|
587
|
+
172: <span class="ruby-identifier">tn</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:true_negatives</span>]
|
588
|
+
173: <span class="ruby-identifier">fn</span> = <span class="ruby-identifier">results</span>[<span class="ruby-value">:false_negatives</span>]
|
589
|
+
174:
|
590
|
+
175: <span class="ruby-identifier">print</span> <span class="ruby-value str">"\t\t"</span>
|
591
|
+
176: <span class="ruby-identifier">print</span> <span class="ruby-value str">"| Relevant\t| Nonrelevant\t| Total\n"</span>
|
592
|
+
177: <span class="ruby-identifier">print</span> <span class="ruby-value str">"---------------------------------------------------------\n"</span>
|
593
|
+
178: <span class="ruby-identifier">print</span> <span class="ruby-value str">"Retrieved\t| "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">tp</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \t\t| "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">fp</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \t\t| "</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">tp</span><span class="ruby-operator">+</span><span class="ruby-identifier">fp</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \n"</span>
|
594
|
+
179: <span class="ruby-identifier">print</span> <span class="ruby-value str">"Not Retrieved\t| "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">fn</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \t\t| "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">tn</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \t\t| "</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">fn</span><span class="ruby-operator">+</span><span class="ruby-identifier">tn</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \n"</span>
|
595
|
+
180: <span class="ruby-identifier">print</span> <span class="ruby-value str">"---------------------------------------------------------\n"</span>
|
596
|
+
181: <span class="ruby-identifier">print</span> <span class="ruby-value str">"\t\t| "</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">tp</span><span class="ruby-operator">+</span><span class="ruby-identifier">fn</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \t\t| "</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">fp</span><span class="ruby-operator">+</span><span class="ruby-identifier">tn</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">" \t\t| "</span> <span class="ruby-operator">+</span> (<span class="ruby-identifier">tp</span><span class="ruby-operator">+</span><span class="ruby-identifier">fp</span><span class="ruby-operator">+</span><span class="ruby-identifier">tn</span><span class="ruby-operator">+</span><span class="ruby-identifier">fn</span>).<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>
|
597
|
+
182: <span class="ruby-identifier">print</span> <span class="ruby-value str">"\n"</span>
|
598
|
+
183: <span class="ruby-keyword kw">end</span></pre>
|
599
|
+
</div>
|
600
|
+
|
601
|
+
</div>
|
602
|
+
|
603
|
+
|
604
|
+
|
605
|
+
|
606
|
+
</div>
|
607
|
+
|
608
|
+
|
609
|
+
</div>
|
610
|
+
|
611
|
+
<div id="private-instance-method-details" class="method-section section">
|
612
|
+
<h3 class="section-header">Private Instance Methods</h3>
|
613
|
+
|
614
|
+
|
615
|
+
<div id="calculate-method" class="method-detail ">
|
616
|
+
<a name="method-i-calculate"></a>
|
617
|
+
|
618
|
+
<div class="method-heading">
|
619
|
+
|
620
|
+
<span class="method-name">calculate</span><span
|
621
|
+
class="method-args">(resultset = nil)</span>
|
622
|
+
<span class="method-click-advice">click to toggle source</span>
|
623
|
+
|
624
|
+
</div>
|
625
|
+
|
626
|
+
<div class="method-description">
|
627
|
+
|
628
|
+
<p>
|
629
|
+
This is the method that performs all necessary calculations on a set of
|
630
|
+
results. Never call this. It should be called automatically.
|
631
|
+
</p>
|
632
|
+
|
633
|
+
|
634
|
+
|
635
|
+
<div class="method-source-code"
|
636
|
+
id="calculate-source">
|
637
|
+
<pre>
|
638
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 228</span>
|
639
|
+
228: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">calculate</span>(<span class="ruby-identifier">resultset</span> = <span class="ruby-keyword kw">nil</span>)
|
640
|
+
229:
|
641
|
+
230: <span class="ruby-comment cmt"># Use the gold standard we initially received</span>
|
642
|
+
231: <span class="ruby-identifier">standard</span> = <span class="ruby-ivar">@gold_standard</span>
|
643
|
+
232:
|
644
|
+
233: <span class="ruby-comment cmt"># If there is an unranked result to be calculated ..</span>
|
645
|
+
234: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">resultset</span>.<span class="ruby-identifier">nil?</span>
|
646
|
+
235: <span class="ruby-identifier">unranked</span> = <span class="ruby-keyword kw">true</span>
|
647
|
+
236: <span class="ruby-comment cmt"># ... we'll just take the array of documents for this result</span>
|
648
|
+
237: <span class="ruby-identifier">resultset</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>
|
649
|
+
238: <span class="ruby-identifier">resultset</span>.<span class="ruby-identifier">documents</span> = <span class="ruby-ivar">@documents</span>.<span class="ruby-identifier">values</span>
|
650
|
+
239: <span class="ruby-identifier">resultset</span>.<span class="ruby-identifier">query</span> = <span class="ruby-ivar">@query</span>
|
651
|
+
240: <span class="ruby-keyword kw">end</span>
|
652
|
+
241:
|
653
|
+
242: <span class="ruby-keyword kw">begin</span>
|
654
|
+
243: <span class="ruby-identifier">all_items</span> = <span class="ruby-identifier">standard</span>.<span class="ruby-identifier">documents</span>.<span class="ruby-identifier">length</span> <span class="ruby-comment cmt"># => all documents this gold standard contains</span>
|
655
|
+
244: <span class="ruby-identifier">retrieved_items</span> = <span class="ruby-identifier">resultset</span>.<span class="ruby-identifier">documents</span>.<span class="ruby-identifier">length</span> <span class="ruby-comment cmt"># => all items retrieved for this information need</span>
|
656
|
+
245: <span class="ruby-identifier">not_retrieved_items</span> = <span class="ruby-identifier">all_items</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">retrieved_items</span> <span class="ruby-comment cmt"># => all items NOT retrieved for this information need</span>
|
657
|
+
246: <span class="ruby-identifier">retrieved_relevant_items</span> = <span class="ruby-value">0</span> <span class="ruby-comment cmt"># => the count of retrieved and relevant documents</span>
|
658
|
+
247: <span class="ruby-identifier">not_retrieved_relevant_items</span> = <span class="ruby-value">0</span> <span class="ruby-comment cmt"># => the count of nonretrieved relevant documents</span>
|
659
|
+
248:
|
660
|
+
249: <span class="ruby-comment cmt"># Get the query we are working on</span>
|
661
|
+
250: <span class="ruby-identifier">query</span> = <span class="ruby-identifier">resultset</span>.<span class="ruby-identifier">query</span>
|
662
|
+
251:
|
663
|
+
252: <span class="ruby-comment cmt"># Get the document sets we are working on</span>
|
664
|
+
253: <span class="ruby-identifier">retrieved_documents</span> = <span class="ruby-identifier">resultset</span>.<span class="ruby-identifier">documents</span> <span class="ruby-comment cmt"># => This is an Array all the time</span>
|
665
|
+
254: <span class="ruby-comment cmt"># This means that we will filter out all retreived documents from the Gold Standard</span>
|
666
|
+
255: <span class="ruby-comment cmt"># TODO: This can definitely be improved, but how?</span>
|
667
|
+
256: <span class="ruby-identifier">not_retrieved_documents</span> = <span class="ruby-identifier">standard</span>.<span class="ruby-identifier">documents</span>.<span class="ruby-identifier">reject</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">key</span>, <span class="ruby-identifier">doc</span><span class="ruby-operator">|</span> <span class="ruby-identifier">retrieved_documents</span>.<span class="ruby-identifier">include?</span> <span class="ruby-identifier">doc</span> } <span class="ruby-comment cmt"># => This is a Hash as it refers to the Gold Standard</span>
|
668
|
+
257:
|
669
|
+
258: <span class="ruby-comment cmt"># Check whether each of the retrieved documents is relevant or not ...</span>
|
670
|
+
259: <span class="ruby-identifier">retrieved_documents</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">doc</span><span class="ruby-operator">|</span>
|
671
|
+
260: <span class="ruby-identifier">relevant</span> = <span class="ruby-identifier">standard</span>.<span class="ruby-identifier">relevant?</span> <span class="ruby-value">:document</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:query</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">query</span>.<span class="ruby-identifier">querystring</span>
|
672
|
+
261: <span class="ruby-identifier">retrieved_relevant_items</span> <span class="ruby-operator">+=</span><span class="ruby-value">1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">relevant</span>
|
673
|
+
262: <span class="ruby-keyword kw">end</span>
|
674
|
+
263: <span class="ruby-identifier">retrieved_nonrelevant_items</span> = <span class="ruby-identifier">retrieved_items</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">retrieved_relevant_items</span>
|
675
|
+
264:
|
676
|
+
265: <span class="ruby-comment cmt"># ... do the same for nonretrieved documents. This is a hash, so we only take the values</span>
|
677
|
+
266: <span class="ruby-identifier">not_retrieved_documents</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">doc</span><span class="ruby-operator">|</span>
|
678
|
+
267: <span class="ruby-identifier">relevant</span> = <span class="ruby-identifier">standard</span>.<span class="ruby-identifier">relevant?</span> <span class="ruby-value">:document</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">doc</span>.<span class="ruby-identifier">id</span>, <span class="ruby-value">:query</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">query</span>.<span class="ruby-identifier">querystring</span>
|
679
|
+
268: <span class="ruby-identifier">not_retrieved_relevant_items</span> <span class="ruby-operator">+=</span> <span class="ruby-value">1</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">relevant</span>
|
680
|
+
269: <span class="ruby-keyword kw">end</span>
|
681
|
+
270: <span class="ruby-identifier">not_retrieved_nonrelevant_items</span> = <span class="ruby-identifier">not_retrieved_items</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">not_retrieved_relevant_items</span>
|
682
|
+
271:
|
683
|
+
272: <span class="ruby-comment cmt"># Now calculate the sum counts</span>
|
684
|
+
273: <span class="ruby-identifier">relevant_items</span> = <span class="ruby-identifier">retrieved_relevant_items</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">not_retrieved_relevant_items</span>
|
685
|
+
274: <span class="ruby-identifier">nonrelevant_items</span> = <span class="ruby-identifier">retrieved_nonrelevant_items</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">not_retrieved_nonrelevant_items</span>
|
686
|
+
275:
|
687
|
+
276: <span class="ruby-comment cmt"># Finally, calculate precision and recall</span>
|
688
|
+
277: <span class="ruby-identifier">precision</span> = <span class="ruby-identifier">retrieved_relevant_items</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">retrieved_items</span>.<span class="ruby-identifier">to_f</span>
|
689
|
+
278: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">relevant_items</span> <span class="ruby-operator">!=</span> <span class="ruby-value">0</span>
|
690
|
+
279: <span class="ruby-identifier">recall</span> = <span class="ruby-identifier">retrieved_relevant_items</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">relevant_items</span>.<span class="ruby-identifier">to_f</span>
|
691
|
+
280: <span class="ruby-keyword kw">else</span>
|
692
|
+
281: <span class="ruby-identifier">recall</span> = <span class="ruby-value">0</span>
|
693
|
+
282: <span class="ruby-keyword kw">end</span>
|
694
|
+
283:
|
695
|
+
284: <span class="ruby-comment cmt"># This hash will be available as the result later</span>
|
696
|
+
285: <span class="ruby-identifier">results</span> = {
|
697
|
+
286: <span class="ruby-value">:precision</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">precision</span>,
|
698
|
+
287: <span class="ruby-value">:recall</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">recall</span>,
|
699
|
+
288: <span class="ruby-value">:false_negatives</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">not_retrieved_relevant_items</span>,
|
700
|
+
289: <span class="ruby-value">:false_positives</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">retrieved_nonrelevant_items</span>,
|
701
|
+
290: <span class="ruby-value">:true_negatives</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">not_retrieved_nonrelevant_items</span>,
|
702
|
+
291: <span class="ruby-value">:true_positives</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">retrieved_relevant_items</span>
|
703
|
+
292: }
|
704
|
+
293:
|
705
|
+
294: <span class="ruby-comment cmt"># Also, if we're doing a ranked evaluation, we want to find out if the</span>
|
706
|
+
295: <span class="ruby-comment cmt"># newly added document is relevant (thus increasing precision and recall)</span>
|
707
|
+
296: <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">unranked</span>
|
708
|
+
297: <span class="ruby-identifier">results</span>[<span class="ruby-value">:document</span>] = <span class="ruby-identifier">retrieved_documents</span>.<span class="ruby-identifier">last</span>.<span class="ruby-identifier">id</span>
|
709
|
+
298: <span class="ruby-identifier">results</span>[<span class="ruby-value">:relevant</span>] = <span class="ruby-identifier">standard</span>.<span class="ruby-identifier">relevant?</span> <span class="ruby-value">:document</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">results</span>[<span class="ruby-value">:document</span>], <span class="ruby-value">:query</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">query</span>.<span class="ruby-identifier">querystring</span>
|
710
|
+
299: <span class="ruby-keyword kw">end</span>
|
711
|
+
300:
|
712
|
+
301: <span class="ruby-identifier">results</span>
|
713
|
+
302:
|
714
|
+
303: <span class="ruby-keyword kw">end</span>
|
715
|
+
304: <span class="ruby-keyword kw">end</span></pre>
|
716
|
+
</div>
|
717
|
+
|
718
|
+
</div>
|
719
|
+
|
720
|
+
|
721
|
+
|
722
|
+
|
723
|
+
</div>
|
724
|
+
|
725
|
+
|
726
|
+
</div>
|
727
|
+
|
728
|
+
|
729
|
+
</div>
|
730
|
+
|
731
|
+
|
732
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
733
|
+
|
734
|
+
<p>Disabled; run with --debug to generate this.</p>
|
735
|
+
|
736
|
+
</div>
|
737
|
+
|
738
|
+
<div id="validator-badges">
|
739
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
740
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
741
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
742
|
+
</div>
|
743
|
+
|
744
|
+
</body>
|
745
|
+
</html>
|
746
|
+
|