Class: Factbase::IndexedNot
- Inherits:
-
Object
- Object
- Factbase::IndexedNot
- Defined in:
- lib/factbase/indexed/indexed_not.rb
Overview
Indexed term ‘not’.
Instance Method Summary collapse
-
#initialize(term, idx) ⇒ IndexedNot
constructor
A new instance of IndexedNot.
- #predict(maps, fb, params) ⇒ Object
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 32 33 34 35 36 37 38 39 40 |
# 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] entry = @idx[key] maps_array = maps.to_a if entry.nil? entry = { facts: nil, indexed_count: 0, yes_set: nil } @idx[key] = entry end if entry[:indexed_count] < maps_array.size yes = @term.operands.first.predict(maps, fb, params) if yes.nil? entry[:facts] = nil entry[:yes_set] = nil else yes_set = yes.to_a.to_set entry[:yes_set] = yes_set entry[:facts] = maps_array.reject { |m| yes_set.include?(m) } end entry[:indexed_count] = maps_array.size end r = entry[:facts] if r.nil? nil else (maps & []) | r end end |