Class: Factbase::IndexedUnique
- Inherits:
-
Object
- Object
- Factbase::IndexedUnique
- Defined in:
- lib/factbase/indexed/indexed_unique.rb
Overview
TODO:
#249:30min Improve prediction for ‘unique’ term. Current prediction is quite naive and returns many false positives because it just filters facts which have exactly the same set of keys regardless the values. We should introduce more smart prediction.
Indexed term ‘unique’.
Instance Method Summary collapse
-
#initialize(term, idx) ⇒ IndexedUnique
constructor
A new instance of IndexedUnique.
- #predict(maps, _fb, _params) ⇒ Object
Constructor Details
#initialize(term, idx) ⇒ IndexedUnique
Returns a new instance of IndexedUnique.
11 12 13 14 |
# File 'lib/factbase/indexed/indexed_unique.rb', line 11 def initialize(term, idx) @term = term @idx = idx end |
Instance Method Details
#predict(maps, _fb, _params) ⇒ Object
16 17 18 19 20 21 22 23 24 |
# File 'lib/factbase/indexed/indexed_unique.rb', line 16 def predict(maps, _fb, _params) return nil if @idx.nil? key = [maps.object_id, @term.operands.first, @term.op] if @idx[key].nil? props = @term.operands.map(&:to_s) @idx[key] = maps.to_a.select { |m| props.all? { |p| !m[p].nil? } } end (maps & []) | @idx[key] end |