Class: VectorEmbed::Maker

Inherits:
Object
  • Object
show all
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

Direct Known Subclasses

Boolean, Date, Ngram, Number, Phrase

Defined Under Namespace

Classes: Boolean, Date, Ngram, Number, Phrase

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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, options = nil)
  @k = k
  @parent = parent
  @cardinality = 0
  @options = options
end

Instance Attribute Details

#cardinalityObject

Returns the value of attribute cardinality.



23
24
25
# File 'lib/vector_embed/maker.rb', line 23

def cardinality
  @cardinality
end

#kObject (readonly)

Returns the value of attribute k.



25
26
27
# File 'lib/vector_embed/maker.rb', line 25

def k
  @k
end

#optionsObject (readonly)

Returns the value of attribute options.



26
27
28
# File 'lib/vector_embed/maker.rb', line 26

def options
  @options
end

#parentObject (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, options = nil)
  if (feature_types = parent.options[: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, options
  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, options
  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