Blame view

lib/rir/query.rb 2.54 KB
b843bae6b   Romain Deveaud   new files + tests
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
  #!/usr/bin/env ruby
  
  # This file is a part of an Information Retrieval oriented Ruby library
  #
  # Copyright (C) 2010-2011 Romain Deveaud <romain.deveaud@gmail.com>
  #
  # This program is free software: you can redistribute it and/or modify
  # it under the terms of the GNU General Public License as published by
  # the Free Software Foundation, either version 3 of the License, or
  # (at your option) any later version.
  #
  # This program is distributed in the hope that it will be useful,
  # but WITHOUT ANY WARRANTY; without even the implied warranty of
  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  # GNU General Public License for more details.
  #
  # You should have received a copy of the GNU General Public License
  # along with this program.  If not, see <http://www.gnu.org/licenses/>.
b843bae6b   Romain Deveaud   new files + tests
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
  module RIR
  
    class Query
    end
  
    module Indri
  
      class Parameters
        attr_accessor :corpus, :memory, :count, :offset, :run_id, :print_query, :print_docs, :rule, :baseline
  
        def initialize(corpus,mem="1g",count="1000",offset="1",run_id="default",print_query=false,print_docs=false)
          @corpus      = corpus
          @memory      = mem
          @count       = count
          @offset      = offset
          @run_id      = run_id
          @print_query = print_query ? "true" : "false"
          @print_docs  = print_docs  ? "true" : "false"
        end
  
        def to_s
          h = "<parameters>
  "
          h += "<memory>#{@memory}</memory>
  "
          h += "<index>#{@corpus}</index>
  "
          h += "<count>#{@count}</count>
  "
          unless @baseline.nil?
            h += "<baseline>#{@baseline}</baseline>
  " 
          else
            h += "<rule>#{@rule}</rule>
  "
          end
          h += "<queryOffset>#{@offset}</queryOffset>
  "
          h += "<runID>#{@run_id}</runID>
  "
          h += "<printQuery>#{@print_query}</printQuery>
  "
          h += "<printDocuments>#{@print_docs}</printDocuments>
  "
  
          h
        end
      end
      
      class IndriQuery < Query
        attr_accessor :id, :query, :params, :rule
  
        def initialize(id,query,params)
b843bae6b   Romain Deveaud   new files + tests
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
          @params = params
          # Here we set the default retrieval model as Language Modeling
          # with a Dirichlet smoothing at 2500.
          # TODO: maybe a Rule class...
          @params.rule  = 'method:dirichlet,mu:2500' if @params.rule.nil?
  
          @id     = id
          @query  = query
        end
  
        def to_s
          h = @params.to_s
          h += "<query>
  "
          h += "<number>#{@id}</number>
  "
          h += "<text>#{@query}</text>
  "
          h += "</query>
  "
          h += "</parameters>"
  
          h
        end
      end
  
    end
  end