vector_embed 0.3.1 → 0.3.2

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.3.2 / 2013-06-14
2
+
3
+ * Enhancements
4
+
5
+ * Output dates as days since 2000-01-01 (pos or neg)
6
+
1
7
  0.3.1 / 2013-05-14
2
8
 
3
9
  * Enhancements
@@ -0,0 +1,36 @@
1
+ require 'vector_embed/maker'
2
+ require 'date'
3
+
4
+ class VectorEmbed
5
+ class Maker
6
+ class Date < Maker
7
+ class << self
8
+ def want?(v, parent)
9
+ v.is_a?(::Date)
10
+ end
11
+ end
12
+
13
+ BASE = ::Date.new(2000,1,1)
14
+ BLANK = /\A\s*\z/
15
+
16
+ def value(v)
17
+ date = case v
18
+ when ::String
19
+ if v !~ BLANK
20
+ ::Date.parse v
21
+ end
22
+ when ::Date
23
+ v
24
+ else
25
+ raise "Can't embed #{v.inspect} in date feature #{k.inspect}"
26
+ end
27
+ if date
28
+ num = (date - BASE).to_i
29
+ if num.nonzero?
30
+ num
31
+ end
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -2,6 +2,7 @@ require 'vector_embed/maker/phrase'
2
2
  require 'vector_embed/maker/ngram'
3
3
  require 'vector_embed/maker/number'
4
4
  require 'vector_embed/maker/boolean'
5
+ require 'vector_embed/maker/date'
5
6
 
6
7
  class VectorEmbed
7
8
  class Maker
@@ -1,3 +1,3 @@
1
1
  class VectorEmbed
2
- VERSION = '0.3.1'
2
+ VERSION = '0.3.2'
3
3
  end
data/lib/vector_embed.rb CHANGED
@@ -19,7 +19,7 @@ class VectorEmbed
19
19
  F = /\Af\z/i
20
20
  NULL_BYTE = "\x00"
21
21
  LABEL_MAKERS = [Maker::Boolean, Maker::Number]
22
- FEATURE_MAKERS = [Maker::Boolean, Maker::Number, Maker::Ngram, Maker::Phrase]
22
+ FEATURE_MAKERS = [Maker::Boolean, Maker::Date, Maker::Number, Maker::Ngram, Maker::Phrase]
23
23
 
24
24
  attr_reader :options
25
25
  attr_accessor :logger
@@ -128,6 +128,22 @@ describe VectorEmbed do
128
128
  v.line(1, 1 => '9e9').should == "1 #{l_h('1')}:9000000000"
129
129
  end
130
130
 
131
+ it "stores dates as days since 2000-01-01" do
132
+ v = VectorEmbed.new
133
+ v.line(1, 3 => Date.new(1999,12,31)).should == "1 #{l_h('3')}:-1"
134
+ v.line(1, 3 => Date.new(2000,1,1)).should == "1"
135
+ v.line(1, 3 => Date.new(2000,1,2)).should == "1 #{l_h('3')}:1"
136
+ v.line(1, 3 => Date.new(2000,1,3)).should == "1 #{l_h('3')}:2"
137
+ end
138
+
139
+ it "can parse some dates" do
140
+ v = VectorEmbed.new(features: { 3 => :Date})
141
+ v.line(1, 3 => '1999-12-31').should == "1 #{l_h('3')}:-1"
142
+ v.line(1, 3 => '2000-1-1').should == "1"
143
+ v.line(1, 3 => '2000-1-2').should == "1 #{l_h('3')}:1"
144
+ v.line(1, 3 => '2000-1-3').should == "1 #{l_h('3')}:2"
145
+ end
146
+
131
147
  it "does not output 0 in number attributes" do
132
148
  v = VectorEmbed.new
133
149
  v.line(3, 1 => 1)
@@ -286,6 +302,10 @@ describe VectorEmbed do
286
302
  end
287
303
  end
288
304
 
305
+ describe 'debug mode' do
306
+
307
+ end
308
+
289
309
  private
290
310
 
291
311
  def h(v)
metadata CHANGED
@@ -1,18 +1,20 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vector_embed
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.3.2
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - Seamus Abshere
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-05-15 00:00:00.000000000 Z
12
+ date: 2013-06-14 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: murmurhash3
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
19
  - - ! '>='
18
20
  - !ruby/object:Gem::Version
@@ -20,6 +22,7 @@ dependencies:
20
22
  type: :runtime
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
27
  - - ! '>='
25
28
  - !ruby/object:Gem::Version
@@ -27,6 +30,7 @@ dependencies:
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
35
  - - ! '>='
32
36
  - !ruby/object:Gem::Version
@@ -34,6 +38,7 @@ dependencies:
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
43
  - - ! '>='
39
44
  - !ruby/object:Gem::Version
@@ -41,6 +46,7 @@ dependencies:
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: pry
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
51
  - - ! '>='
46
52
  - !ruby/object:Gem::Version
@@ -48,6 +54,7 @@ dependencies:
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
59
  - - ! '>='
53
60
  - !ruby/object:Gem::Version
@@ -55,6 +62,7 @@ dependencies:
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: yard
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
67
  - - ! '>='
60
68
  - !ruby/object:Gem::Version
@@ -62,6 +70,7 @@ dependencies:
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
75
  - - ! '>='
67
76
  - !ruby/object:Gem::Version
@@ -87,6 +96,7 @@ files:
87
96
  - lib/vector_embed.rb
88
97
  - lib/vector_embed/maker.rb
89
98
  - lib/vector_embed/maker/boolean.rb
99
+ - lib/vector_embed/maker/date.rb
90
100
  - lib/vector_embed/maker/ngram.rb
91
101
  - lib/vector_embed/maker/number.rb
92
102
  - lib/vector_embed/maker/phrase.rb
@@ -97,26 +107,27 @@ files:
97
107
  - vector_embed.gemspec
98
108
  homepage: https://github.com/seamusabshere/vector_embed
99
109
  licenses: []
100
- metadata: {}
101
110
  post_install_message:
102
111
  rdoc_options: []
103
112
  require_paths:
104
113
  - lib
105
114
  required_ruby_version: !ruby/object:Gem::Requirement
115
+ none: false
106
116
  requirements:
107
117
  - - ! '>='
108
118
  - !ruby/object:Gem::Version
109
119
  version: '0'
110
120
  required_rubygems_version: !ruby/object:Gem::Requirement
121
+ none: false
111
122
  requirements:
112
123
  - - ! '>='
113
124
  - !ruby/object:Gem::Version
114
125
  version: '0'
115
126
  requirements: []
116
127
  rubyforge_project:
117
- rubygems_version: 2.0.3
128
+ rubygems_version: 1.8.25
118
129
  signing_key:
119
- specification_version: 4
130
+ specification_version: 3
120
131
  summary: Vector embedding of strings, booleans, numerics, and arrays into LIBSVM /
121
132
  LIBLINEAR format.
122
133
  test_files:
checksums.yaml DELETED
@@ -1,15 +0,0 @@
1
- ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- ZTI5YmZhZDkxODdmMDA5NzdmYWYyZjkwZjg5YjY4MzM3MzU1OWU1Nw==
5
- data.tar.gz: !binary |-
6
- YzhkOTNhZDk5NmE2MzNmZTdlYjQyZDJlY2NiYWM4MzBjZmEwMDM2Nw==
7
- !binary "U0hBNTEy":
8
- metadata.gz: !binary |-
9
- MGYxZTYxMDBhMDRiMzNmYjMyZDNhN2I2MDIzYmJmZGM5MzRhYzk1MWQyN2Vm
10
- OWUwMjkzNDAyZjYxNzc3NjcwYWE4YzQzNDY3NmEzMzIyMWVjZTU1Yjk0MjJj
11
- MzViMjlkOTI4ODI3MDBlZWNkODEwMWM1Y2UxODRmODQ3ZTU2ZmU=
12
- data.tar.gz: !binary |-
13
- YjQxOTUyMzEzZGRiYzcwMzNiZjViNzdjMWNlNTg1NmY2OGRmOGFhNDg4OTA0
14
- YjRiMGU3Y2Y0ZmEzZGU5ZTQ5ZGNkYWJjMjhiZWU4MDgxYzA4NzYzMWMzZmUz
15
- NmM3MmQxZGFmMmNmZGJjMzM4ZTU5MGYwYzE2Njg4ZjY0M2Y5ZWE=