Class: Textpow::ScoreManager

Inherits:
Object
  • Object
show all
Defined in:
lib/textpow/score_manager.rb

Constant Summary collapse

POINT_DEPTH =
4
NESTING_DEPTH =
40
START_VALUE =
2 ** ( POINT_DEPTH * NESTING_DEPTH )
BASE =
2 ** POINT_DEPTH

Instance Method Summary collapse

Constructor Details

#initializeScoreManager

Returns a new instance of ScoreManager.



8
9
10
# File 'lib/textpow/score_manager.rb', line 8

def initialize
   @scores = {}
end

Instance Method Details

#score(search_scope, reference_scope) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/textpow/score_manager.rb', line 12

def score search_scope, reference_scope
   max = 0
   search_scope.split( ',' ).each do |scope|
      arrays = scope.split(/\B-/)
      if arrays.size == 1
         max = [max, score_term( arrays[0], reference_scope )].max
      elsif arrays.size > 1
         excluded = false
         arrays[1..-1].each do |a| 
            if score_term( arrays[1], reference_scope ) > 0
               excluded = true
               break
            end
         end
         max = [max, score_term( arrays[0], reference_scope )].max unless excluded
      else
         raise ParsingError, "Error in scope string: '#{search_scope}' #{arrays.size} is not a valid number of operands" if arrays.size < 1
      end
   end
   max
end