Class: VectorEmbed::Maker
- Inherits:
-
Object
- Object
- VectorEmbed::Maker
- Defined in:
- lib/vector_embed/maker.rb,
lib/vector_embed/maker/date.rb,
lib/vector_embed/maker/ngram.rb,
lib/vector_embed/maker/number.rb,
lib/vector_embed/maker/phrase.rb,
lib/vector_embed/maker/boolean.rb
Defined Under Namespace
Classes: Boolean, Date, Ngram, Number, Phrase
Instance Attribute Summary collapse
-
#cardinality ⇒ Object
Returns the value of attribute cardinality.
-
#k ⇒ Object
readonly
Returns the value of attribute k.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#parent ⇒ Object
readonly
Returns the value of attribute parent.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(k, parent, options = nil) ⇒ Maker
constructor
A new instance of Maker.
- #pairs(v) ⇒ Object
Constructor Details
#initialize(k, parent, options = nil) ⇒ Maker
Returns a new instance of Maker.
28 29 30 31 32 33 |
# File 'lib/vector_embed/maker.rb', line 28 def initialize(k, parent, = nil) @k = k @parent = parent @cardinality = 0 = end |
Instance Attribute Details
#cardinality ⇒ Object
Returns the value of attribute cardinality.
23 24 25 |
# File 'lib/vector_embed/maker.rb', line 23 def cardinality @cardinality end |
#k ⇒ Object (readonly)
Returns the value of attribute k.
25 26 27 |
# File 'lib/vector_embed/maker.rb', line 25 def k @k end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
26 27 28 |
# File 'lib/vector_embed/maker.rb', line 26 def end |
#parent ⇒ Object (readonly)
Returns the value of attribute parent.
24 25 26 |
# File 'lib/vector_embed/maker.rb', line 24 def parent @parent end |
Class Method Details
.pick(choices, k, first_v, parent, options = nil) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/vector_embed/maker.rb', line 10 def pick(choices, k, first_v, parent, = nil) if (feature_types = parent.[:features]) and (type = feature_types.detect { |kk, v| kk.to_s == k.to_s }) klass = const_get type[1].to_sym klass.new k, parent, elsif klass = choices.detect { |klass| klass.want?(first_v, parent) } parent.logger.debug { "Interpreting #{k.inspect} as #{klass.name.split('::').last} given first value #{first_v.inspect}" } klass.new k, parent, else raise "Can't use #{first_v.class} for #{k.inspect} given #{first_v.inspect} and choices #{choices.inspect}" end end |
Instance Method Details
#pairs(v) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/vector_embed/maker.rb', line 35 def pairs(v) case v when Array memo = [] v.each_with_index do |vv, i| unless (vvv = value(vv)).nil? memo << [ parent.index([k, i]), vvv ] end end memo else if (vv = value(v)).nil? [] else [ [ parent.index([k]), vv ] ] end end end |