Class: Eluka::DataPoint
- Inherits:
-
Object
- Object
- Eluka::DataPoint
- Defined in:
- lib/eluka/data_point.rb
Instance Method Summary collapse
-
#initialize(data, analyzer) ⇒ DataPoint
constructor
A new instance of DataPoint.
- #vector ⇒ Object
Constructor Details
#initialize(data, analyzer) ⇒ DataPoint
Returns a new instance of DataPoint.
4 5 6 7 8 9 10 11 12 13 14 15 16 |
# File 'lib/eluka/data_point.rb', line 4 def initialize(data, analyzer) raise "Can't find any data" unless (data) if data.instance_of?(String) data = {:text => data} end raise "Invalid data added" unless (data.instance_of? Hash) raise "Data can't be empty" unless (data.size > 0) @data = data @analyzer = analyzer end |
Instance Method Details
#vector ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/eluka/data_point.rb', line 18 def vector vector = Hash.new @data.each do |field, value| if value.instance_of?(String) then doc_vec = Eluka::Document.new(field, value, @analyzer).vector vector.merge!(doc_vec) elsif value.instance_of?(Fixnum) or value.instance_of?(Float) vector[field] = value else raise "A field can contain either an integer or a double or it can be a string" end end vector end |