recommendify 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -152,13 +152,3 @@ Permission is hereby granted, free of charge, to any person obtaining a copy of
152
152
  The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
153
153
 
154
154
  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
155
-
156
-
157
-
158
- ### todo
159
-
160
- + implement CosineInputMatrix
161
- + forbid ':' and '|' in item_ids
162
- + recommendify::base no key part issue
163
- + make max_row length configurable
164
-
data/ext/recommendify.c CHANGED
@@ -3,7 +3,7 @@
3
3
  #include <stdlib.h>
4
4
  #include <hiredis/hiredis.h>
5
5
 
6
- #include "version.h"
6
+ #include "version.h"
7
7
  #include "cc_item.h"
8
8
  #include "jaccard.c"
9
9
  #include "cosine.c"
@@ -27,7 +27,11 @@ int main(int argc, char **argv){
27
27
  int batch_size = 200; /* FIXPAUL: make option */
28
28
  int maxItems = 50; /* FIXPAUL: make option */
29
29
 
30
-
30
+ struct {
31
+ char host[1024];
32
+ int port;
33
+ } redis_addr;
34
+
31
35
  /* option parsing */
32
36
  if(argc < 2)
33
37
  return print_usage(argv[0]);
@@ -44,7 +48,7 @@ int main(int argc, char **argv){
44
48
  if(!similarityFunc){
45
49
  printf("invalid option: %s\n", argv[1]);
46
50
  return 1;
47
- } else if(argc != 4){
51
+ } else if(argc < 4 || argc > 5){
48
52
  printf("wrong number of arguments\n");
49
53
  print_usage(argv[0]);
50
54
  return 1;
@@ -52,17 +56,35 @@ int main(int argc, char **argv){
52
56
 
53
57
  redisPrefix = argv[2];
54
58
  itemID = argv[3];
59
+ redis_addr.host[0] = 0;
60
+
61
+ /* configure redis location */
62
+ if(argc > 4){
63
+ char* has_port = strchr(argv[4], ':');
64
+ if(has_port){
65
+ strncpy(redis_addr.host, argv[4], strlen(argv[4]) - strlen(has_port));
66
+ redis_addr.host[strlen(argv[4]) - strlen(has_port)] = 0;
67
+ redis_addr.port = atoi(has_port + 1);
68
+ } else {
69
+ strncpy(redis_addr.host, argv[4], sizeof(redis_addr.host));
70
+ }
71
+ }
72
+
73
+ /* default redis location */
74
+ if(strlen(redis_addr.host) == 0)
75
+ strcpy(redis_addr.host, "localhost");
55
76
 
77
+ if(!redis_addr.port)
78
+ redis_addr.port = 6379;
56
79
 
57
80
  /* connect to redis */
58
81
  struct timeval timeout = { 1, 500000 };
59
- c = redisConnectWithTimeout("127.0.0.2", 6379, timeout);
82
+ c = redisConnectWithTimeout(redis_addr.host, redis_addr.port, timeout);
60
83
 
61
84
  if(c->err){
62
85
  printf("connection to redis failed: %s\n", c->errstr);
63
86
  return 1;
64
87
  }
65
-
66
88
 
67
89
  /* get item count */
68
90
  reply = redisCommand(c,"HGET %s:items %s", redisPrefix, itemID);
@@ -8,6 +8,7 @@ module Recommendify::CCMatrix
8
8
  end
9
9
 
10
10
  def add_set(set_id, item_ids)
11
+ # FIXPAUL: forbid | and : in item_ids
11
12
  item_ids.each do |item_id|
12
13
  item_count_incr(item_id)
13
14
  end
@@ -48,4 +49,4 @@ private
48
49
  Recommendify.redis.hget(redis_key(:items), key).to_i
49
50
  end
50
51
 
51
- end
52
+ end
@@ -34,7 +34,7 @@ private
34
34
  end
35
35
 
36
36
  def run_native(item_id)
37
- res = %x{#{native_path} --jaccard "#{redis_key}" "#{item_id}"}
37
+ res = %x{#{native_path} --jaccard "#{redis_key}" "#{item_id}" "#{redis_url}"}
38
38
  res.split("\n").map do |line|
39
39
  sim = line.match(/OUT: \(([^\)]*)\) \(([^\)]*)\)/)
40
40
  raise "error: #{res}" unless sim
@@ -51,4 +51,8 @@ private
51
51
  ::File.expand_path('../../../bin/recommendify', __FILE__)
52
52
  end
53
53
 
54
+ def redis_url
55
+ Recommendify.redis.client.location
56
+ end
57
+
54
58
  end
data/recommendify.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "recommendify"
6
- s.version = "0.3.0"
6
+ s.version = "0.3.1"
7
7
  s.date = Date.today.to_s
8
8
  s.platform = Gem::Platform::RUBY
9
9
  s.authors = ["Paul Asmuth"]
@@ -55,6 +55,20 @@ describe Recommendify::JaccardInputMatrix do
55
55
  res.should include ["fnord", 0.4]
56
56
  end
57
57
 
58
+ it "should call run_native when the native option was passed" do
59
+ matrix = Recommendify::JaccardInputMatrix.new(
60
+ :redis_prefix => "recommendify-test",
61
+ :native => true,
62
+ :key => "mymatrix"
63
+ )
64
+ matrix.should_receive(:run_native).with("fnord").and_return(true)
65
+ matrix.similarities_for("fnord")
66
+ end
67
+
68
+ it "should return the correct redis url" do
69
+ @matrix.send(:redis_url).should == "127.0.0.1:6379"
70
+ end
71
+
58
72
  private
59
73
 
60
74
  def add_two_item_test_data!(matrix)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recommendify
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-03-08 00:00:00.000000000 Z
12
+ date: 2012-03-09 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: redis
16
- requirement: &71701010 !ruby/object:Gem::Requirement
16
+ requirement: &6965060 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: 2.2.2
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *71701010
24
+ version_requirements: *6965060
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rspec
27
- requirement: &71700770 !ruby/object:Gem::Requirement
27
+ requirement: &6964420 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ~>
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: 2.8.0
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *71700770
35
+ version_requirements: *6964420
36
36
  description: Recommendify is a distributed, incremental item-based recommendation
37
37
  engine for binary input ratings. It's based on ruby and redis and uses an approach
38
38
  called "Collaborative Filtering"
@@ -100,7 +100,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
100
100
  version: '0'
101
101
  requirements: []
102
102
  rubyforge_project:
103
- rubygems_version: 1.8.6
103
+ rubygems_version: 1.8.17
104
104
  signing_key:
105
105
  specification_version: 3
106
106
  summary: ruby/redis based recommendation engine (collaborative filtering)
@@ -115,4 +115,3 @@ test_files:
115
115
  - spec/similarity_matrix_spec.rb
116
116
  - spec/sparse_matrix_spec.rb
117
117
  - spec/spec_helper.rb
118
- has_rdoc: