Class: Factbase::IndexedNot

Inherits:
Object
  • Object
show all
Defined in:
lib/factbase/indexed/indexed_not.rb

Overview

Indexed term ‘not’.

Instance Method Summary collapse

Constructor Details

#initialize(term, idx) ⇒ IndexedNot

Returns a new instance of IndexedNot.



8
9
10
11
# File 'lib/factbase/indexed/indexed_not.rb', line 8

def initialize(term, idx)
  @term = term
  @idx = idx
end

Instance Method Details

#predict(maps, fb, params) ⇒ Object



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

def predict(maps, fb, params)
  return nil if @idx.nil?
  key = [maps.object_id, @term.operands.first, @term.op]
  if @idx[key].nil?
    yes = @term.operands.first.predict(maps, fb, params)
    if yes.nil?
      @idx[key] = { r: nil }
    else
      yes = yes.to_a.to_set
      @idx[key] = { r: maps.to_a.reject { |m| yes.include?(m) } }
    end
  end
  r = @idx[key][:r]
  if r.nil?
    nil
  else
    (maps & []) | r
  end
end