Class: Factbase::IndexedExists

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

Overview

Indexed term ‘exists’. The @idx structure:

count: Integer (number of facts already processed),
facts: Array (facts found),

Instance Method Summary collapse

Constructor Details

#initialize(term, idx) ⇒ IndexedExists

Returns a new instance of IndexedExists.



13
14
15
16
# File 'lib/factbase/indexed/indexed_exists.rb', line 13

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

Instance Method Details

#predict(maps, _fb, _params) ⇒ Object



18
19
20
21
22
23
24
25
# File 'lib/factbase/indexed/indexed_exists.rb', line 18

def predict(maps, _fb, _params)
  operand = @term.operands.first.to_s
  key = [maps.object_id, operand, @term.op]
  @idx[key] = { facts: [], count: 0 } if @idx[key].nil?
  entry = @idx[key]
  _feed(maps.to_a, entry, operand)
  maps.respond_to?(:repack) ? maps.repack(entry[:facts]) : entry[:facts]
end