Class: Factbase::Head
Overview
It retrieves the first N results from a query.
Instance Method Summary collapse
-
#evaluate(_fact, _maps, _fb) ⇒ Boolean
Evaluate term on a fact.
-
#initialize(operands) ⇒ Head
constructor
Constructor.
- #predict(maps, fb, params) ⇒ Object
Methods included from TermShared
Constructor Details
#initialize(operands) ⇒ Head
Constructor.
12 13 14 15 16 |
# File 'lib/factbase/terms/head.rb', line 12 def initialize(operands) super() @operands = operands @op = 'head' end |
Instance Method Details
#evaluate(_fact, _maps, _fb) ⇒ Boolean
Evaluate term on a fact.
23 24 25 |
# File 'lib/factbase/terms/head.rb', line 23 def evaluate(_fact, _maps, _fb) true end |
#predict(maps, fb, params) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/factbase/terms/head.rb', line 27 def predict(maps, fb, params) assert_args(2) max = @operands[0] raise "An integer is expected as first argument of '#{@op}'" unless max.is_a?(Integer) term = @operands[1] raise "A term is expected, but '#{term}' provided" unless term.is_a?(Factbase::Term) fb.query(term, maps).each(fb, params).to_a .take(max) .map { |m| m.all_properties.to_h { |k| [k, m[k]] } } end |