Class: Factbase::IndexedAbsent
- Inherits:
-
Object
- Object
- Factbase::IndexedAbsent
- Defined in:
- lib/factbase/indexed/indexed_absent.rb
Overview
Indexed term ‘absent’.
Instance Method Summary collapse
-
#initialize(term, idx) ⇒ IndexedAbsent
constructor
A new instance of IndexedAbsent.
- #predict(maps, _fb, _params) ⇒ Object
Constructor Details
#initialize(term, idx) ⇒ IndexedAbsent
Returns a new instance of IndexedAbsent.
8 9 10 11 |
# File 'lib/factbase/indexed/indexed_absent.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 |
# File 'lib/factbase/indexed/indexed_absent.rb', line 13 def predict(maps, _fb, _params) return nil if @idx.nil? key = [maps.object_id, @term.operands.first, @term.op] entry = @idx[key] maps_array = maps.to_a if entry.nil? entry = { facts: [], indexed_count: 0 } @idx[key] = entry end if entry[:indexed_count] < maps_array.size prop = @term.operands.first.to_s maps_array[entry[:indexed_count]..].each do |m| entry[:facts] << m if m[prop].nil? end entry[:indexed_count] = maps_array.size end (maps & []) | entry[:facts] end |