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 +6 -0
- data/lib/vector_embed.rb +1 -1
- data/lib/vector_embed/maker.rb +6 -4
- data/lib/vector_embed/maker/ngram.rb +1 -1
- data/lib/vector_embed/maker/number.rb +11 -4
- data/lib/vector_embed/version.rb +1 -1
- data/spec/vector_embed_spec.rb +1 -0
- metadata +2 -2
data/CHANGELOG
CHANGED
data/lib/vector_embed.rb
CHANGED
@@ -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
|
|
data/lib/vector_embed/maker.rb
CHANGED
@@ -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)
|
@@ -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
|
data/lib/vector_embed/version.rb
CHANGED
data/spec/vector_embed_spec.rb
CHANGED
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.
|
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-
|
12
|
+
date: 2013-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: murmurhash3
|