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,429 @@
|
|
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::QueryResultSet</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-add_result">#add_result</a></li>
|
75
|
+
|
76
|
+
<li><a href="#method-i-load_from_yaml_file">#load_from_yaml_file</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-i-mean_average_precision">#mean_average_precision</a></li>
|
79
|
+
|
80
|
+
</ul>
|
81
|
+
</div>
|
82
|
+
|
83
|
+
|
84
|
+
<!-- Included Modules -->
|
85
|
+
|
86
|
+
</div>
|
87
|
+
|
88
|
+
<div id="project-metadata">
|
89
|
+
|
90
|
+
|
91
|
+
<div id="fileindex-section" class="section project-section">
|
92
|
+
<h3 class="section-header">Files</h3>
|
93
|
+
<ul>
|
94
|
+
|
95
|
+
<li class="file"><a href="../CHANGELOG.html">CHANGELOG</a></li>
|
96
|
+
|
97
|
+
<li class="file"><a href="../TODO.html">TODO</a></li>
|
98
|
+
|
99
|
+
</ul>
|
100
|
+
</div>
|
101
|
+
|
102
|
+
|
103
|
+
<div id="classindex-section" class="section project-section">
|
104
|
+
<h3 class="section-header">Class Index
|
105
|
+
<span class="search-toggle"><img src="../images/find.png"
|
106
|
+
height="16" width="16" alt="[+]"
|
107
|
+
title="show/hide quicksearch" /></span></h3>
|
108
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
109
|
+
<fieldset>
|
110
|
+
<legend>Quicksearch</legend>
|
111
|
+
<input type="text" name="quicksearch" value=""
|
112
|
+
class="quicksearch-field" />
|
113
|
+
</fieldset>
|
114
|
+
</form>
|
115
|
+
|
116
|
+
<ul class="link-list">
|
117
|
+
|
118
|
+
<li><a href="../Retreval.html">Retreval</a></li>
|
119
|
+
|
120
|
+
<li><a href="../Retreval/Document.html">Retreval::Document</a></li>
|
121
|
+
|
122
|
+
<li><a href="../Retreval/GoldStandard.html">Retreval::GoldStandard</a></li>
|
123
|
+
|
124
|
+
<li><a href="../Retreval/Judgement.html">Retreval::Judgement</a></li>
|
125
|
+
|
126
|
+
<li><a href="../Retreval/Options.html">Retreval::Options</a></li>
|
127
|
+
|
128
|
+
<li><a href="../Retreval/Query.html">Retreval::Query</a></li>
|
129
|
+
|
130
|
+
<li><a href="../Retreval/QueryResult.html">Retreval::QueryResult</a></li>
|
131
|
+
|
132
|
+
<li><a href="../Retreval/QueryResultSet.html">Retreval::QueryResultSet</a></li>
|
133
|
+
|
134
|
+
<li><a href="../Retreval/RankedQueryResult.html">Retreval::RankedQueryResult</a></li>
|
135
|
+
|
136
|
+
<li><a href="../Retreval/ResultDocument.html">Retreval::ResultDocument</a></li>
|
137
|
+
|
138
|
+
<li><a href="../Retreval/Runner.html">Retreval::Runner</a></li>
|
139
|
+
|
140
|
+
<li><a href="../Retreval/UnrankedQueryResult.html">Retreval::UnrankedQueryResult</a></li>
|
141
|
+
|
142
|
+
<li><a href="../Retreval/User.html">Retreval::User</a></li>
|
143
|
+
|
144
|
+
<li><a href="../TestGoldStandard.html">TestGoldStandard</a></li>
|
145
|
+
|
146
|
+
<li><a href="../TestQueryResult.html">TestQueryResult</a></li>
|
147
|
+
|
148
|
+
</ul>
|
149
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
150
|
+
</div>
|
151
|
+
|
152
|
+
|
153
|
+
</div>
|
154
|
+
</div>
|
155
|
+
|
156
|
+
<div id="documentation">
|
157
|
+
<h1 class="class">Retreval::QueryResultSet</h1>
|
158
|
+
|
159
|
+
<div id="description">
|
160
|
+
<p>
|
161
|
+
A <a href="QueryResultSet.html">QueryResultSet</a> combines multiple
|
162
|
+
QueryResults and stores them. It is possible to load a set of QueryResults
|
163
|
+
from a YAML file.
|
164
|
+
</p>
|
165
|
+
|
166
|
+
</div>
|
167
|
+
|
168
|
+
<!-- Constants -->
|
169
|
+
|
170
|
+
|
171
|
+
<!-- Attributes -->
|
172
|
+
|
173
|
+
<div id="attribute-method-details" class="method-section section">
|
174
|
+
<h3 class="section-header">Attributes</h3>
|
175
|
+
|
176
|
+
|
177
|
+
<div id="query-results-attribute-method" class="method-detail">
|
178
|
+
<a name="query_results"></a>
|
179
|
+
|
180
|
+
<div class="method-heading attribute-method-heading">
|
181
|
+
<span class="method-name">query_results</span><span
|
182
|
+
class="attribute-access-type">[R]</span>
|
183
|
+
</div>
|
184
|
+
|
185
|
+
<div class="method-description">
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
</div>
|
190
|
+
</div>
|
191
|
+
|
192
|
+
</div>
|
193
|
+
|
194
|
+
|
195
|
+
<!-- Methods -->
|
196
|
+
|
197
|
+
<div id="public-class-method-details" class="method-section section">
|
198
|
+
<h3 class="section-header">Public Class Methods</h3>
|
199
|
+
|
200
|
+
|
201
|
+
<div id="new-method" class="method-detail ">
|
202
|
+
<a name="method-c-new"></a>
|
203
|
+
|
204
|
+
<div class="method-heading">
|
205
|
+
|
206
|
+
<span class="method-name">new</span><span
|
207
|
+
class="method-args">(args)</span>
|
208
|
+
<span class="method-click-advice">click to toggle source</span>
|
209
|
+
|
210
|
+
</div>
|
211
|
+
|
212
|
+
<div class="method-description">
|
213
|
+
|
214
|
+
<p>
|
215
|
+
Creates a new <a href="QueryResultSet.html">QueryResultSet</a>, with a
|
216
|
+
specified <a href="GoldStandard.html">GoldStandard</a> Called by:
|
217
|
+
</p>
|
218
|
+
<pre>
|
219
|
+
QueryResultSet.new :gold_standard => my_gold_standard</pre>
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
<div class="method-source-code"
|
224
|
+
id="new-source">
|
225
|
+
<pre>
|
226
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 15</span>
|
227
|
+
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">args</span>)
|
228
|
+
16: <span class="ruby-ivar">@query_results</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
|
229
|
+
17: <span class="ruby-ivar">@gold_standard</span> = <span class="ruby-identifier">args</span>[<span class="ruby-value">:gold_standard</span>]
|
230
|
+
18: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Can not create a Query Result set without a gold standard that they belong 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>
|
231
|
+
19: <span class="ruby-keyword kw">end</span></pre>
|
232
|
+
</div>
|
233
|
+
|
234
|
+
</div>
|
235
|
+
|
236
|
+
|
237
|
+
|
238
|
+
|
239
|
+
</div>
|
240
|
+
|
241
|
+
|
242
|
+
</div>
|
243
|
+
|
244
|
+
<div id="public-instance-method-details" class="method-section section">
|
245
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
246
|
+
|
247
|
+
|
248
|
+
<div id="add-result-method" class="method-detail ">
|
249
|
+
<a name="method-i-add_result"></a>
|
250
|
+
|
251
|
+
<div class="method-heading">
|
252
|
+
|
253
|
+
<span class="method-name">add_result</span><span
|
254
|
+
class="method-args">(result)</span>
|
255
|
+
<span class="method-click-advice">click to toggle source</span>
|
256
|
+
|
257
|
+
</div>
|
258
|
+
|
259
|
+
<div class="method-description">
|
260
|
+
|
261
|
+
<p>
|
262
|
+
Adds a <a href="QueryResult.html">QueryResult</a> to the list of results
|
263
|
+
for this set
|
264
|
+
</p>
|
265
|
+
|
266
|
+
|
267
|
+
|
268
|
+
<div class="method-source-code"
|
269
|
+
id="add-result-source">
|
270
|
+
<pre>
|
271
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 72</span>
|
272
|
+
72: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">add_result</span>(<span class="ruby-identifier">result</span>)
|
273
|
+
73: <span class="ruby-ivar">@query_results</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">result</span>
|
274
|
+
74: <span class="ruby-keyword kw">end</span></pre>
|
275
|
+
</div>
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
</div>
|
283
|
+
|
284
|
+
|
285
|
+
<div id="load-from-yaml-file-method" class="method-detail ">
|
286
|
+
<a name="method-i-load_from_yaml_file"></a>
|
287
|
+
|
288
|
+
<div class="method-heading">
|
289
|
+
|
290
|
+
<span class="method-name">load_from_yaml_file</span><span
|
291
|
+
class="method-args">(file)</span>
|
292
|
+
<span class="method-click-advice">click to toggle source</span>
|
293
|
+
|
294
|
+
</div>
|
295
|
+
|
296
|
+
<div class="method-description">
|
297
|
+
|
298
|
+
<p>
|
299
|
+
Parses a YAML file containing many result sets, either ranked or unranked.
|
300
|
+
The file should look like this:
|
301
|
+
</p>
|
302
|
+
<pre>
|
303
|
+
* query: Test query
|
304
|
+
ranked: true
|
305
|
+
documents:
|
306
|
+
* id: first_document.txt
|
307
|
+
score: 95
|
308
|
+
* id: second_document.txt
|
309
|
+
score: 38
|
310
|
+
* query: Second query
|
311
|
+
ranked: true
|
312
|
+
documents:
|
313
|
+
* id: another_doc.txt
|
314
|
+
score: 12
|
315
|
+
* id: yet_another_one.txt
|
316
|
+
score: 1
|
317
|
+
</pre>
|
318
|
+
<p>
|
319
|
+
… and so on.
|
320
|
+
</p>
|
321
|
+
|
322
|
+
|
323
|
+
|
324
|
+
<div class="method-source-code"
|
325
|
+
id="load-from-yaml-file-source">
|
326
|
+
<pre>
|
327
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 38</span>
|
328
|
+
38: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">load_from_yaml_file</span>(<span class="ruby-identifier">file</span>)
|
329
|
+
39: <span class="ruby-keyword kw">begin</span>
|
330
|
+
40:
|
331
|
+
41: <span class="ruby-identifier">ydoc</span> = <span class="ruby-constant">YAML</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>))
|
332
|
+
42:
|
333
|
+
43: <span class="ruby-identifier">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>
|
334
|
+
44: <span class="ruby-identifier">query</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">"query"</span>] <span class="ruby-comment cmt"># => the query string</span>
|
335
|
+
45: <span class="ruby-identifier">ranked</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">"ranked"</span>] <span class="ruby-comment cmt"># => a boolean flag if ranked or not</span>
|
336
|
+
46: <span class="ruby-identifier">documents</span> = <span class="ruby-identifier">entry</span>[<span class="ruby-value str">"documents"</span>] <span class="ruby-comment cmt"># => an array of documents</span>
|
337
|
+
47:
|
338
|
+
48: <span class="ruby-comment cmt"># Determine whether this will be a ranked or unranked result set</span>
|
339
|
+
49: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">ranked</span>
|
340
|
+
50: <span class="ruby-identifier">resultset</span> = <span class="ruby-constant">RankedQueryResult</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:query</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">query</span>, <span class="ruby-value">:gold_standard</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@gold_standard</span>
|
341
|
+
51: <span class="ruby-keyword kw">else</span>
|
342
|
+
52: <span class="ruby-identifier">resultset</span> = <span class="ruby-constant">UnrankedQueryResult</span>.<span class="ruby-identifier">new</span> <span class="ruby-value">:query</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">query</span>, <span class="ruby-value">:gold_standard</span> =<span class="ruby-operator">></span> <span class="ruby-ivar">@gold_standard</span>
|
343
|
+
53: <span class="ruby-keyword kw">end</span>
|
344
|
+
54:
|
345
|
+
55: <span class="ruby-comment cmt"># Find all documents for this query result</span>
|
346
|
+
56: <span class="ruby-identifier">documents</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">document_element</span><span class="ruby-operator">|</span>
|
347
|
+
57: <span class="ruby-identifier">document</span> = <span class="ruby-identifier">document_element</span>[<span class="ruby-value str">"id"</span>]
|
348
|
+
58: <span class="ruby-identifier">score</span> = <span class="ruby-identifier">document_element</span>[<span class="ruby-value str">"score"</span>]
|
349
|
+
59: <span class="ruby-identifier">resultset</span>.<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>
|
350
|
+
60: <span class="ruby-keyword kw">end</span>
|
351
|
+
61:
|
352
|
+
62: <span class="ruby-ivar">@query_results</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">resultset</span>
|
353
|
+
63:
|
354
|
+
64: <span class="ruby-keyword kw">end</span>
|
355
|
+
65: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
356
|
+
66: <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>
|
357
|
+
67: <span class="ruby-keyword kw">end</span>
|
358
|
+
68: <span class="ruby-keyword kw">end</span></pre>
|
359
|
+
</div>
|
360
|
+
|
361
|
+
</div>
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
|
366
|
+
</div>
|
367
|
+
|
368
|
+
|
369
|
+
<div id="mean-average-precision-method" class="method-detail ">
|
370
|
+
<a name="method-i-mean_average_precision"></a>
|
371
|
+
|
372
|
+
<div class="method-heading">
|
373
|
+
|
374
|
+
<span class="method-name">mean_average_precision</span><span
|
375
|
+
class="method-args">()</span>
|
376
|
+
<span class="method-click-advice">click to toggle source</span>
|
377
|
+
|
378
|
+
</div>
|
379
|
+
|
380
|
+
<div class="method-description">
|
381
|
+
|
382
|
+
<p>
|
383
|
+
Calculates the Mean Average Precision for each <a
|
384
|
+
href="RankedQueryResult.html">RankedQueryResult</a> in this set. This
|
385
|
+
method should only be called when all sets have been calculated, or else it
|
386
|
+
will take a really long time to perform all necessary calculations.
|
387
|
+
</p>
|
388
|
+
|
389
|
+
|
390
|
+
|
391
|
+
<div class="method-source-code"
|
392
|
+
id="mean-average-precision-source">
|
393
|
+
<pre>
|
394
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 79</span>
|
395
|
+
79: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">mean_average_precision</span>
|
396
|
+
80: <span class="ruby-identifier">total_ranked_query_results</span> = <span class="ruby-ivar">@query_results</span>.<span class="ruby-identifier">count</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">result</span><span class="ruby-operator">|</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">RankedQueryResult</span> }
|
397
|
+
81: <span class="ruby-ivar">@mean_average_precision</span> = <span class="ruby-ivar">@query_results</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0.0</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">sum</span>, <span class="ruby-identifier">result</span><span class="ruby-operator">|</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">RankedQueryResult</span> <span class="ruby-operator">?</span> <span class="ruby-identifier">sum</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">result</span>.<span class="ruby-identifier">average_precision</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">sum</span> } <span class="ruby-operator">/</span> <span class="ruby-identifier">total_ranked_query_results</span>
|
398
|
+
82: <span class="ruby-keyword kw">end</span></pre>
|
399
|
+
</div>
|
400
|
+
|
401
|
+
</div>
|
402
|
+
|
403
|
+
|
404
|
+
|
405
|
+
|
406
|
+
</div>
|
407
|
+
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
|
412
|
+
</div>
|
413
|
+
|
414
|
+
|
415
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
416
|
+
|
417
|
+
<p>Disabled; run with --debug to generate this.</p>
|
418
|
+
|
419
|
+
</div>
|
420
|
+
|
421
|
+
<div id="validator-badges">
|
422
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
423
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
424
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
425
|
+
</div>
|
426
|
+
|
427
|
+
</body>
|
428
|
+
</html>
|
429
|
+
|
@@ -0,0 +1,556 @@
|
|
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::RankedQueryResult</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"><a href="QueryResult.html">Retreval::QueryResult</a></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-average_precision">#average_precision</a></li>
|
75
|
+
|
76
|
+
<li><a href="#method-i-eleven_point_precision">#eleven_point_precision</a></li>
|
77
|
+
|
78
|
+
<li><a href="#method-i-print_eleven_point_precision_table">#print_eleven_point_precision_table</a></li>
|
79
|
+
|
80
|
+
<li><a href="#method-i-print_ranked_table">#print_ranked_table</a></li>
|
81
|
+
|
82
|
+
<li><a href="#method-i-statistics">#statistics</a></li>
|
83
|
+
|
84
|
+
</ul>
|
85
|
+
</div>
|
86
|
+
|
87
|
+
|
88
|
+
<!-- Included Modules -->
|
89
|
+
|
90
|
+
</div>
|
91
|
+
|
92
|
+
<div id="project-metadata">
|
93
|
+
|
94
|
+
|
95
|
+
<div id="fileindex-section" class="section project-section">
|
96
|
+
<h3 class="section-header">Files</h3>
|
97
|
+
<ul>
|
98
|
+
|
99
|
+
<li class="file"><a href="../CHANGELOG.html">CHANGELOG</a></li>
|
100
|
+
|
101
|
+
<li class="file"><a href="../TODO.html">TODO</a></li>
|
102
|
+
|
103
|
+
</ul>
|
104
|
+
</div>
|
105
|
+
|
106
|
+
|
107
|
+
<div id="classindex-section" class="section project-section">
|
108
|
+
<h3 class="section-header">Class Index
|
109
|
+
<span class="search-toggle"><img src="../images/find.png"
|
110
|
+
height="16" width="16" alt="[+]"
|
111
|
+
title="show/hide quicksearch" /></span></h3>
|
112
|
+
<form action="#" method="get" accept-charset="utf-8" class="initially-hidden">
|
113
|
+
<fieldset>
|
114
|
+
<legend>Quicksearch</legend>
|
115
|
+
<input type="text" name="quicksearch" value=""
|
116
|
+
class="quicksearch-field" />
|
117
|
+
</fieldset>
|
118
|
+
</form>
|
119
|
+
|
120
|
+
<ul class="link-list">
|
121
|
+
|
122
|
+
<li><a href="../Retreval.html">Retreval</a></li>
|
123
|
+
|
124
|
+
<li><a href="../Retreval/Document.html">Retreval::Document</a></li>
|
125
|
+
|
126
|
+
<li><a href="../Retreval/GoldStandard.html">Retreval::GoldStandard</a></li>
|
127
|
+
|
128
|
+
<li><a href="../Retreval/Judgement.html">Retreval::Judgement</a></li>
|
129
|
+
|
130
|
+
<li><a href="../Retreval/Options.html">Retreval::Options</a></li>
|
131
|
+
|
132
|
+
<li><a href="../Retreval/Query.html">Retreval::Query</a></li>
|
133
|
+
|
134
|
+
<li><a href="../Retreval/QueryResult.html">Retreval::QueryResult</a></li>
|
135
|
+
|
136
|
+
<li><a href="../Retreval/QueryResultSet.html">Retreval::QueryResultSet</a></li>
|
137
|
+
|
138
|
+
<li><a href="../Retreval/RankedQueryResult.html">Retreval::RankedQueryResult</a></li>
|
139
|
+
|
140
|
+
<li><a href="../Retreval/ResultDocument.html">Retreval::ResultDocument</a></li>
|
141
|
+
|
142
|
+
<li><a href="../Retreval/Runner.html">Retreval::Runner</a></li>
|
143
|
+
|
144
|
+
<li><a href="../Retreval/UnrankedQueryResult.html">Retreval::UnrankedQueryResult</a></li>
|
145
|
+
|
146
|
+
<li><a href="../Retreval/User.html">Retreval::User</a></li>
|
147
|
+
|
148
|
+
<li><a href="../TestGoldStandard.html">TestGoldStandard</a></li>
|
149
|
+
|
150
|
+
<li><a href="../TestQueryResult.html">TestQueryResult</a></li>
|
151
|
+
|
152
|
+
</ul>
|
153
|
+
<div id="no-class-search-results" style="display: none;">No matching classes.</div>
|
154
|
+
</div>
|
155
|
+
|
156
|
+
|
157
|
+
</div>
|
158
|
+
</div>
|
159
|
+
|
160
|
+
<div id="documentation">
|
161
|
+
<h1 class="class">Retreval::RankedQueryResult</h1>
|
162
|
+
|
163
|
+
<div id="description">
|
164
|
+
<p>
|
165
|
+
A <a href="RankedQueryResult.html">RankedQueryResult</a> is a <a
|
166
|
+
href="QueryResult.html">QueryResult</a> with special functions for ranked
|
167
|
+
retrieval evaluation.
|
168
|
+
</p>
|
169
|
+
|
170
|
+
</div>
|
171
|
+
|
172
|
+
<!-- Constants -->
|
173
|
+
|
174
|
+
|
175
|
+
<!-- Attributes -->
|
176
|
+
|
177
|
+
|
178
|
+
<!-- Methods -->
|
179
|
+
|
180
|
+
<div id="public-class-method-details" class="method-section section">
|
181
|
+
<h3 class="section-header">Public Class Methods</h3>
|
182
|
+
|
183
|
+
|
184
|
+
<div id="new-method" class="method-detail ">
|
185
|
+
<a name="method-c-new"></a>
|
186
|
+
|
187
|
+
<div class="method-heading">
|
188
|
+
|
189
|
+
<span class="method-name">new</span><span
|
190
|
+
class="method-args">(args)</span>
|
191
|
+
<span class="method-click-advice">click to toggle source</span>
|
192
|
+
|
193
|
+
</div>
|
194
|
+
|
195
|
+
<div class="method-description">
|
196
|
+
|
197
|
+
<p>
|
198
|
+
Creates a new <a href="RankedQueryResult.html">RankedQueryResult</a>. One
|
199
|
+
has to specify the query string and can optionally pass a <a
|
200
|
+
href="Document.html">Document</a> array too. The rank of the <a
|
201
|
+
href="Document.html">Document</a> will be defined by its position in the
|
202
|
+
array only. Called by:
|
203
|
+
</p>
|
204
|
+
<pre>
|
205
|
+
RankedQueryResult.new :documents => array_of_document_ids, :query => "my query"
|
206
|
+
RankedQueryResult.new :query => "my query"</pre>
|
207
|
+
|
208
|
+
|
209
|
+
|
210
|
+
<div class="method-source-code"
|
211
|
+
id="new-source">
|
212
|
+
<pre>
|
213
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 319</span>
|
214
|
+
319: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">args</span>)
|
215
|
+
320: <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">args</span>)
|
216
|
+
321: <span class="ruby-keyword kw">end</span></pre>
|
217
|
+
</div>
|
218
|
+
|
219
|
+
</div>
|
220
|
+
|
221
|
+
|
222
|
+
|
223
|
+
|
224
|
+
</div>
|
225
|
+
|
226
|
+
|
227
|
+
</div>
|
228
|
+
|
229
|
+
<div id="public-instance-method-details" class="method-section section">
|
230
|
+
<h3 class="section-header">Public Instance Methods</h3>
|
231
|
+
|
232
|
+
|
233
|
+
<div id="average-precision-method" class="method-detail ">
|
234
|
+
<a name="method-i-average_precision"></a>
|
235
|
+
|
236
|
+
<div class="method-heading">
|
237
|
+
|
238
|
+
<span class="method-name">average_precision</span><span
|
239
|
+
class="method-args">()</span>
|
240
|
+
<span class="method-click-advice">click to toggle source</span>
|
241
|
+
|
242
|
+
</div>
|
243
|
+
|
244
|
+
<div class="method-description">
|
245
|
+
|
246
|
+
<p>
|
247
|
+
Returns the average precision. It is the average of precisions computed at
|
248
|
+
the point of each of the relevant documents in the ranked sequence.
|
249
|
+
</p>
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
<div class="method-source-code"
|
254
|
+
id="average-precision-source">
|
255
|
+
<pre>
|
256
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 417</span>
|
257
|
+
417: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">average_precision</span>
|
258
|
+
418: <span class="ruby-keyword kw">begin</span>
|
259
|
+
419: <span class="ruby-comment cmt"># Calculate the results first if we haven't done this before</span>
|
260
|
+
420: <span class="ruby-identifier">statistics</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@calculated</span>
|
261
|
+
421:
|
262
|
+
422: <span class="ruby-identifier">total_relevant_documents</span> = <span class="ruby-ivar">@gold_standard</span>.<span class="ruby-identifier">documents</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">count</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">doc</span><span class="ruby-operator">|</span> <span class="ruby-ivar">@gold_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-ivar">@query</span>.<span class="ruby-identifier">querystring</span> }
|
263
|
+
423:
|
264
|
+
424: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">total_relevant_documents</span> <span class="ruby-operator">></span> <span class="ruby-value">0</span>
|
265
|
+
425: <span class="ruby-comment cmt"># The sum is calculated by adding the precision for a relevant document, or 0 for a nonrelevant document</span>
|
266
|
+
426: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@average_precision</span> = <span class="ruby-ivar">@results</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0.0</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">sum</span>, <span class="ruby-identifier">document</span><span class="ruby-operator">|</span> <span class="ruby-identifier">document</span>[<span class="ruby-value">:relevant</span>] <span class="ruby-operator">?</span> <span class="ruby-identifier">document</span>[<span class="ruby-value">:precision</span>] <span class="ruby-operator">+</span> <span class="ruby-identifier">sum</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">sum</span> } <span class="ruby-operator">/</span> <span class="ruby-identifier">total_relevant_documents</span>
|
267
|
+
427: <span class="ruby-keyword kw">else</span>
|
268
|
+
428: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@average_precision</span> = <span class="ruby-value">0</span>
|
269
|
+
429: <span class="ruby-keyword kw">end</span>
|
270
|
+
430: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
271
|
+
431: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Error while calculating average precision: "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
272
|
+
432: <span class="ruby-keyword kw">end</span>
|
273
|
+
433:
|
274
|
+
434: <span class="ruby-keyword kw">end</span></pre>
|
275
|
+
</div>
|
276
|
+
|
277
|
+
</div>
|
278
|
+
|
279
|
+
|
280
|
+
|
281
|
+
|
282
|
+
</div>
|
283
|
+
|
284
|
+
|
285
|
+
<div id="eleven-point-precision-method" class="method-detail ">
|
286
|
+
<a name="method-i-eleven_point_precision"></a>
|
287
|
+
|
288
|
+
<div class="method-heading">
|
289
|
+
|
290
|
+
<span class="method-name">eleven_point_precision</span><span
|
291
|
+
class="method-args">()</span>
|
292
|
+
<span class="method-click-advice">click to toggle source</span>
|
293
|
+
|
294
|
+
</div>
|
295
|
+
|
296
|
+
<div class="method-description">
|
297
|
+
|
298
|
+
<p>
|
299
|
+
Calculates the 11-point precision and the average interpolated precision.
|
300
|
+
See: <a
|
301
|
+
href="http://nlp.stanford.edu/IR-book/html/htmledition/evaluation-of-ranked-retrieval-results-1.html">nlp.stanford.edu/IR-book/html/htmledition/evaluation-of-ranked-retrieval-results-1.html</a>
|
302
|
+
</p>
|
303
|
+
|
304
|
+
|
305
|
+
|
306
|
+
<div class="method-source-code"
|
307
|
+
id="eleven-point-precision-source">
|
308
|
+
<pre>
|
309
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 326</span>
|
310
|
+
326: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">eleven_point_precision</span>
|
311
|
+
327:
|
312
|
+
328: <span class="ruby-identifier">statistics</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@calculated</span>
|
313
|
+
329:
|
314
|
+
330: <span class="ruby-ivar">@recall_levels</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
|
315
|
+
331:
|
316
|
+
332: <span class="ruby-comment cmt"># Find out what recall/precision pairs we already know</span>
|
317
|
+
333: <span class="ruby-ivar">@results</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
318
|
+
334: <span class="ruby-identifier">precision</span> = <span class="ruby-identifier">row</span>[<span class="ruby-value">:precision</span>]
|
319
|
+
335: <span class="ruby-identifier">recall</span> = <span class="ruby-identifier">row</span>[<span class="ruby-value">:recall</span>]
|
320
|
+
336: <span class="ruby-ivar">@recall_levels</span>[<span class="ruby-identifier">recall</span>] = <span class="ruby-identifier">precision</span>
|
321
|
+
337: <span class="ruby-keyword kw">end</span>
|
322
|
+
338:
|
323
|
+
339: <span class="ruby-keyword kw">begin</span>
|
324
|
+
340: <span class="ruby-ivar">@eleven_point_precision</span> = <span class="ruby-constant">Hash</span>.<span class="ruby-identifier">new</span>
|
325
|
+
341:
|
326
|
+
342: <span class="ruby-comment cmt"># Calculate the 11 points</span>
|
327
|
+
343: <span class="ruby-comment cmt"># This outer loop effectively iterates from 0.0 to 1.0</span>
|
328
|
+
344: (<span class="ruby-value">0</span><span class="ruby-operator">..</span><span class="ruby-value">10</span>).<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">recall_level</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
329
|
+
345: <span class="ruby-identifier">recall_level</span> = <span class="ruby-identifier">recall_level</span>.<span class="ruby-identifier">to_f</span> <span class="ruby-operator">/</span> <span class="ruby-value">10</span>
|
330
|
+
346: <span class="ruby-ivar">@eleven_point_precision</span>[<span class="ruby-identifier">recall_level</span>] = <span class="ruby-value">0</span>
|
331
|
+
347:
|
332
|
+
348: <span class="ruby-comment cmt"># Look in our known recall levels (stored as the keys)</span>
|
333
|
+
349: <span class="ruby-ivar">@recall_levels</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">key</span><span class="ruby-operator">|</span>
|
334
|
+
350:
|
335
|
+
351: <span class="ruby-comment cmt"># If we find a known recall equal or higher to the one from the 11-point</span>
|
336
|
+
352: <span class="ruby-comment cmt"># scale, return the precision at that level</span>
|
337
|
+
353: <span class="ruby-comment cmt"># E.g. if our level is 0.3 and we have a known precision at 0.5, this</span>
|
338
|
+
354: <span class="ruby-comment cmt"># one will be used as our interpolated precision</span>
|
339
|
+
355: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">key</span> <span class="ruby-operator">>=</span> <span class="ruby-identifier">recall_level</span>
|
340
|
+
356: <span class="ruby-identifier">precision_for_level</span> = <span class="ruby-ivar">@recall_levels</span>[<span class="ruby-identifier">key</span>]
|
341
|
+
357: <span class="ruby-comment cmt"># Store the interpolated precision at the current level, e.g. 0.3</span>
|
342
|
+
358: <span class="ruby-ivar">@eleven_point_precision</span>[<span class="ruby-identifier">recall_level</span>] = <span class="ruby-identifier">precision_for_level</span>
|
343
|
+
359: <span class="ruby-keyword kw">break</span>
|
344
|
+
360: <span class="ruby-keyword kw">end</span>
|
345
|
+
361: <span class="ruby-keyword kw">end</span>
|
346
|
+
362: <span class="ruby-keyword kw">end</span>
|
347
|
+
363:
|
348
|
+
364: <span class="ruby-comment cmt"># Now calculate an average precision for this statistic</span>
|
349
|
+
365: <span class="ruby-comment cmt"># That's a neat line of ruby code, is it?</span>
|
350
|
+
366: <span class="ruby-ivar">@eleven_point_average</span> = <span class="ruby-ivar">@eleven_point_precision</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">inject</span>(<span class="ruby-value">0.0</span>) { <span class="ruby-operator">|</span><span class="ruby-identifier">sum</span>, <span class="ruby-identifier">precision</span><span class="ruby-operator">|</span> <span class="ruby-identifier">sum</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">precision</span> } <span class="ruby-operator">/</span> <span class="ruby-value">11</span>
|
351
|
+
367:
|
352
|
+
368: <span class="ruby-keyword kw">rescue</span>
|
353
|
+
369: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Error while calculating the 11-point precision map!"</span>
|
354
|
+
370: <span class="ruby-keyword kw">end</span>
|
355
|
+
371:
|
356
|
+
372: <span class="ruby-ivar">@eleven_point_precision</span>
|
357
|
+
373:
|
358
|
+
374: <span class="ruby-keyword kw">end</span></pre>
|
359
|
+
</div>
|
360
|
+
|
361
|
+
</div>
|
362
|
+
|
363
|
+
|
364
|
+
|
365
|
+
|
366
|
+
</div>
|
367
|
+
|
368
|
+
|
369
|
+
<div id="print-eleven-point-precision-table-method" class="method-detail ">
|
370
|
+
<a name="method-i-print_eleven_point_precision_table"></a>
|
371
|
+
|
372
|
+
<div class="method-heading">
|
373
|
+
|
374
|
+
<span class="method-name">print_eleven_point_precision_table</span><span
|
375
|
+
class="method-args">()</span>
|
376
|
+
<span class="method-click-advice">click to toggle source</span>
|
377
|
+
|
378
|
+
</div>
|
379
|
+
|
380
|
+
<div class="method-description">
|
381
|
+
|
382
|
+
<p>
|
383
|
+
Prints a pretty table for 11-point interpolated precision
|
384
|
+
</p>
|
385
|
+
|
386
|
+
|
387
|
+
|
388
|
+
<div class="method-source-code"
|
389
|
+
id="print-eleven-point-precision-table-source">
|
390
|
+
<pre>
|
391
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 438</span>
|
392
|
+
438: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_eleven_point_precision_table</span>
|
393
|
+
439:
|
394
|
+
440: <span class="ruby-comment cmt"># Calculate the results first if we haven't done this before</span>
|
395
|
+
441: <span class="ruby-identifier">statistics</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@calculated</span>
|
396
|
+
442:
|
397
|
+
443: <span class="ruby-identifier">data</span> = <span class="ruby-identifier">eleven_point_precision</span>
|
398
|
+
444: <span class="ruby-identifier">print</span> <span class="ruby-value str">"Recall\tInterpolated Precision\n"</span>
|
399
|
+
445: <span class="ruby-identifier">data</span>.<span class="ruby-identifier">each_pair</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">recall</span>, <span class="ruby-identifier">precision</span><span class="ruby-operator">|</span>
|
400
|
+
446: <span class="ruby-identifier">print</span> <span class="ruby-identifier">recall</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\t"</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"%.3f"</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">precision</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>
|
401
|
+
447: <span class="ruby-keyword kw">end</span>
|
402
|
+
448: <span class="ruby-identifier">print</span> <span class="ruby-value str">"--------------------------------------\n"</span>
|
403
|
+
449: <span class="ruby-identifier">print</span> <span class="ruby-value str">"Avg.\t"</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"%.3f"</span> <span class="ruby-operator">%</span> <span class="ruby-ivar">@eleven_point_average</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>
|
404
|
+
450: <span class="ruby-identifier">print</span> <span class="ruby-value str">"\n"</span>
|
405
|
+
451:
|
406
|
+
452: <span class="ruby-keyword kw">end</span></pre>
|
407
|
+
</div>
|
408
|
+
|
409
|
+
</div>
|
410
|
+
|
411
|
+
|
412
|
+
|
413
|
+
|
414
|
+
</div>
|
415
|
+
|
416
|
+
|
417
|
+
<div id="print-ranked-table-method" class="method-detail ">
|
418
|
+
<a name="method-i-print_ranked_table"></a>
|
419
|
+
|
420
|
+
<div class="method-heading">
|
421
|
+
|
422
|
+
<span class="method-name">print_ranked_table</span><span
|
423
|
+
class="method-args">()</span>
|
424
|
+
<span class="method-click-advice">click to toggle source</span>
|
425
|
+
|
426
|
+
</div>
|
427
|
+
|
428
|
+
<div class="method-description">
|
429
|
+
|
430
|
+
<p>
|
431
|
+
Prints a pretty table for ranked results
|
432
|
+
</p>
|
433
|
+
|
434
|
+
|
435
|
+
|
436
|
+
<div class="method-source-code"
|
437
|
+
id="print-ranked-table-source">
|
438
|
+
<pre>
|
439
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 456</span>
|
440
|
+
456: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">print_ranked_table</span>
|
441
|
+
457:
|
442
|
+
458: <span class="ruby-comment cmt"># Calculate the results first if we haven't done this before</span>
|
443
|
+
459: <span class="ruby-identifier">statistics</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@calculated</span>
|
444
|
+
460:
|
445
|
+
461: <span class="ruby-comment cmt"># Use the results to print a table</span>
|
446
|
+
462: <span class="ruby-identifier">print</span> <span class="ruby-node">"Query: #{@query.querystring}\n"</span>
|
447
|
+
463: <span class="ruby-identifier">print</span> <span class="ruby-value str">"Index\tRelevant\tPrecision\tRecall\tScore\t\tDocument ID\n"</span>
|
448
|
+
464: <span class="ruby-ivar">@results</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">row</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
449
|
+
465: <span class="ruby-identifier">precision</span> = <span class="ruby-value str">"%.3f"</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">row</span>[<span class="ruby-value">:precision</span>]
|
450
|
+
466: <span class="ruby-identifier">document</span> = <span class="ruby-ivar">@documents</span>.<span class="ruby-identifier">values</span>[<span class="ruby-identifier">index</span>].<span class="ruby-identifier">id</span>
|
451
|
+
467: <span class="ruby-identifier">recall</span> = <span class="ruby-value str">"%.3f"</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">row</span>[<span class="ruby-value">:recall</span>]
|
452
|
+
468: <span class="ruby-identifier">relevant</span> = <span class="ruby-identifier">row</span>[<span class="ruby-value">:relevant</span>] <span class="ruby-operator">?</span> <span class="ruby-value str">"[X]"</span> <span class="ruby-operator">:</span> <span class="ruby-value str">"[ ]"</span>
|
453
|
+
469: <span class="ruby-identifier">print</span> <span class="ruby-node">"#{index+1}\t"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">relevant</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\t\t"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">precision</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\t\t"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">recall</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\t"</span> <span class="ruby-operator">+</span> <span class="ruby-ivar">@documents</span>.<span class="ruby-identifier">values</span>[<span class="ruby-identifier">index</span>].<span class="ruby-identifier">score</span>.<span class="ruby-identifier">to_s</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\t"</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">document</span> <span class="ruby-operator">+</span> <span class="ruby-value str">"\n"</span>
|
454
|
+
470: <span class="ruby-keyword kw">end</span>
|
455
|
+
471: <span class="ruby-identifier">print</span> <span class="ruby-value str">"\n"</span>
|
456
|
+
472:
|
457
|
+
473: <span class="ruby-keyword kw">end</span></pre>
|
458
|
+
</div>
|
459
|
+
|
460
|
+
</div>
|
461
|
+
|
462
|
+
|
463
|
+
|
464
|
+
|
465
|
+
</div>
|
466
|
+
|
467
|
+
|
468
|
+
<div id="statistics-method" class="method-detail ">
|
469
|
+
<a name="method-i-statistics"></a>
|
470
|
+
|
471
|
+
<div class="method-heading">
|
472
|
+
|
473
|
+
<span class="method-name">statistics</span><span
|
474
|
+
class="method-args">(max = 0)</span>
|
475
|
+
<span class="method-click-advice">click to toggle source</span>
|
476
|
+
|
477
|
+
</div>
|
478
|
+
|
479
|
+
<div class="method-description">
|
480
|
+
|
481
|
+
<p>
|
482
|
+
Calculates the precision and recall for each rank and returns it in a Hash
|
483
|
+
of results
|
484
|
+
</p>
|
485
|
+
|
486
|
+
|
487
|
+
|
488
|
+
<div class="method-source-code"
|
489
|
+
id="statistics-source">
|
490
|
+
<pre>
|
491
|
+
<span class="ruby-comment cmt"># File lib/retreval/query_result.rb, line 379</span>
|
492
|
+
379: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">statistics</span>(<span class="ruby-identifier">max</span> = <span class="ruby-value">0</span>)
|
493
|
+
380:
|
494
|
+
381: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@results</span> <span class="ruby-keyword kw">if</span> <span class="ruby-ivar">@calculated</span>
|
495
|
+
382:
|
496
|
+
383: <span class="ruby-keyword kw">begin</span>
|
497
|
+
384:
|
498
|
+
385: <span class="ruby-comment cmt"># If no maximum parameter is given, all documents are evalutated</span>
|
499
|
+
386: <span class="ruby-comment cmt"># This should be the default for normal evaluations</span>
|
500
|
+
387: <span class="ruby-identifier">max</span> = <span class="ruby-ivar">@documents</span>.<span class="ruby-identifier">length</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">max</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> <span class="ruby-keyword kw">or</span> <span class="ruby-identifier">max</span> <span class="ruby-operator">></span> <span class="ruby-ivar">@documents</span>.<span class="ruby-identifier">length</span>
|
501
|
+
388:
|
502
|
+
389: <span class="ruby-comment cmt"># Calculate precision and recall for the top i documents only</span>
|
503
|
+
390: <span class="ruby-ivar">@results</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
|
504
|
+
391: <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-identifier">max</span>)
|
505
|
+
392: <span class="ruby-identifier">subset</span> = <span class="ruby-constant">OpenStruct</span>.<span class="ruby-identifier">new</span>
|
506
|
+
393: <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">documents</span> = <span class="ruby-constant">Array</span>.<span class="ruby-identifier">new</span>
|
507
|
+
394: <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">query</span> = <span class="ruby-ivar">@query</span>
|
508
|
+
395: <span class="ruby-ivar">@documents</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">each_with_index</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">doc</span>, <span class="ruby-identifier">index</span><span class="ruby-operator">|</span>
|
509
|
+
396: <span class="ruby-comment cmt"># Only get the subset of documents</span>
|
510
|
+
397: <span class="ruby-identifier">subset</span>.<span class="ruby-identifier">documents</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">doc</span>
|
511
|
+
398: <span class="ruby-keyword kw">break</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">index</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">i</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>
|
512
|
+
399: <span class="ruby-keyword kw">end</span>
|
513
|
+
400: <span class="ruby-identifier">results</span> = <span class="ruby-identifier">calculate</span>(<span class="ruby-identifier">subset</span>)
|
514
|
+
401: <span class="ruby-ivar">@results</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">results</span>
|
515
|
+
402: <span class="ruby-keyword kw">end</span>
|
516
|
+
403:
|
517
|
+
404: <span class="ruby-comment cmt"># Now mark everything as calculated and return it</span>
|
518
|
+
405: <span class="ruby-ivar">@calculated</span> = <span class="ruby-keyword kw">true</span>
|
519
|
+
406: <span class="ruby-ivar">@results</span>
|
520
|
+
407:
|
521
|
+
408: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
522
|
+
409: <span class="ruby-identifier">raise</span> <span class="ruby-value str">"Error while calculating results: "</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
523
|
+
410: <span class="ruby-keyword kw">end</span>
|
524
|
+
411:
|
525
|
+
412: <span class="ruby-keyword kw">end</span></pre>
|
526
|
+
</div>
|
527
|
+
|
528
|
+
</div>
|
529
|
+
|
530
|
+
|
531
|
+
|
532
|
+
|
533
|
+
</div>
|
534
|
+
|
535
|
+
|
536
|
+
</div>
|
537
|
+
|
538
|
+
|
539
|
+
</div>
|
540
|
+
|
541
|
+
|
542
|
+
<div id="rdoc-debugging-section-dump" class="debugging-section">
|
543
|
+
|
544
|
+
<p>Disabled; run with --debug to generate this.</p>
|
545
|
+
|
546
|
+
</div>
|
547
|
+
|
548
|
+
<div id="validator-badges">
|
549
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
550
|
+
<p><small>Generated with the <a href="http://deveiate.org/projects/Darkfish-Rdoc/">Darkfish
|
551
|
+
Rdoc Generator</a> 1.1.6</small>.</p>
|
552
|
+
</div>
|
553
|
+
|
554
|
+
</body>
|
555
|
+
</html>
|
556
|
+
|