vector_embed 0.5.0 → 0.5.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG CHANGED
@@ -1,3 +1,9 @@
1
+ 0.5.1 / 2013-07-09
2
+
3
+ * Bug fixes
4
+
5
+ * Don't drop 0 labels like you would for features (sorry!)
6
+
1
7
  0.5.0 / 2013-07-08
2
8
 
3
9
  * Breaking changes
@@ -109,7 +109,7 @@ class VectorEmbed
109
109
 
110
110
  def label_maker(label)
111
111
  @label_maker || @mutex.synchronize do
112
- @label_maker ||= Maker.pick(LABEL_MAKERS, 'label', label, self)
112
+ @label_maker ||= Maker.pick(LABEL_MAKERS, 'label', label, self, keep_zero: true)
113
113
  end
114
114
  end
115
115
 
@@ -7,13 +7,13 @@ require 'vector_embed/maker/date'
7
7
  class VectorEmbed
8
8
  class Maker
9
9
  class << self
10
- def pick(choices, k, first_v, parent)
10
+ def pick(choices, k, first_v, parent, options = nil)
11
11
  if (feature_types = parent.options[:features]) and (type = feature_types.detect { |kk, v| kk.to_s == k.to_s })
12
12
  klass = const_get type[1].to_sym
13
- klass.new k, parent
13
+ klass.new k, parent, options
14
14
  elsif klass = choices.detect { |klass| klass.want?(first_v, parent) }
15
15
  parent.logger.debug { "Interpreting #{k.inspect} as #{klass.name.split('::').last} given first value #{first_v.inspect}" }
16
- klass.new k, parent
16
+ klass.new k, parent, options
17
17
  else
18
18
  raise "Can't use #{first_v.class} for #{k.inspect} given #{first_v.inspect} and choices #{choices.inspect}"
19
19
  end
@@ -23,11 +23,13 @@ class VectorEmbed
23
23
  attr_accessor :cardinality
24
24
  attr_reader :parent
25
25
  attr_reader :k
26
+ attr_reader :options
26
27
 
27
- def initialize(k, parent)
28
+ def initialize(k, parent, options = nil)
28
29
  @k = k
29
30
  @parent = parent
30
31
  @cardinality = 0
32
+ @options = options
31
33
  end
32
34
 
33
35
  def pairs(v)
@@ -15,7 +15,7 @@ class VectorEmbed
15
15
  attr_reader :len
16
16
  attr_reader :delim
17
17
 
18
- def initialize(k, parent)
18
+ def initialize(k, parent, options = nil)
19
19
  super
20
20
  @len = parent.options[:ngram_len].to_i
21
21
  raise ArgumentError, ":ngram_len must be > 0" unless @len > 0
@@ -23,22 +23,29 @@ class VectorEmbed
23
23
  else
24
24
  v
25
25
  end
26
- if num.nonzero?
27
- '%.16g' % num
28
- end
29
26
  end
30
27
  end
28
+
29
+ FORMAT = '%.16g'
31
30
 
32
31
  def value(v)
33
32
  case v
34
33
  when Numeric, JUST_A_NUMBER, UGLY_FLOAT
35
- Number.numify v
34
+ num = Number.numify v
35
+ if num.nonzero? or keep_zero?
36
+ FORMAT % num
37
+ end
36
38
  when NilClass, NULL, SLASH_N
37
39
  nil
38
40
  else
39
41
  raise ArgumentError, "Can't embed #{v.inspect} in number feature #{k.inspect}"
40
42
  end
41
43
  end
44
+
45
+ def keep_zero?
46
+ return @keep_zero_query if defined?(@keep_zero_query)
47
+ @keep_zero = options && !!options[:keep_zero]
48
+ end
42
49
  end
43
50
  end
44
51
  end
@@ -1,3 +1,3 @@
1
1
  class VectorEmbed
2
- VERSION = '0.5.0'
2
+ VERSION = '0.5.1'
3
3
  end
@@ -12,6 +12,7 @@ describe VectorEmbed do
12
12
 
13
13
  it "stores numbers as numbers" do
14
14
  v = VectorEmbed.new
15
+ v.line(0).should == '0'
15
16
  v.line(5.4).should == '5.4'
16
17
  v.line(-3.9).should == '-3.9'
17
18
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vector_embed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.5.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-07-08 00:00:00.000000000 Z
12
+ date: 2013-07-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: murmurhash3