commendo 1.1.0 → 1.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9504182a72226de650736e2b987eda2734a5f3bf
4
- data.tar.gz: ff9fb6d451b160f8f2ac4da2d4cb2688621ad7ff
3
+ metadata.gz: c9c9e5e5c280d0f1ec32c258aa01875eadb369a4
4
+ data.tar.gz: 370760fc75db86566eaa79684f345aef76176fd7
5
5
  SHA512:
6
- metadata.gz: 7669f08e1c313865623360a14f72d7686da669c36c7a096485f9da9d9552f904b7cf808bbdaf2379af32d681939a6ab5d587759cbead1fb8037d6869ef91e048
7
- data.tar.gz: e8a729ece664f9167e0f2efd8212f5d1ac87ab5edd5dc443ff561ae047d81a97ab6d1d5dafccf7b2c8aac209bc38bc34cdd456e01816bba050ad03cd32a8c8b8
6
+ metadata.gz: feb82aed9f709bb50357bfa0de939bb6c941a5d7e2b593dd9b1cbf46a0dfd1190e1d703df54ba8e234872d032c452e54b7a9b2ce648722d5b4883711badf69ab
7
+ data.tar.gz: c040aa4d208403f52f3bf54d63ab0d5bc5868e4a621175642f539872ce5d444bd8e73f39492ec521bb1cb6b3cd640dc14a83666db5e3aa3a9208c9c219fb7b6d
data/CHANGELOG.md CHANGED
@@ -1,3 +1,6 @@
1
+ # 1.2.0 / 2015-04-01
2
+ * [FEATURE] Add ability to remove select tags for a resource
3
+
1
4
  # 1.1.0 / 2015-04-01
2
5
  * [FEATURE] Add ability to remove a resource from a group and recalculate similarity
3
6
 
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'redis'
4
+ require 'commendo'
5
+ require 'progressbar'
6
+
7
+ filename = ARGV[0]
8
+ redis_db = ARGV[1].to_i
9
+ base_key = ARGV[2]
10
+
11
+ redis = Redis.new(db: redis_db, timeout: 60)
12
+ ts = Commendo::TagSet.new(redis, base_key)
13
+
14
+ puts "Loading."
15
+ file_length = `wc -l #{filename}`.to_i
16
+ pbar = ProgressBar.new('Loading TSV file', file_length)
17
+ File.open(filename) do |f|
18
+ f.each_line.with_index do |line, i|
19
+ pbar.inc
20
+ tags = line.split("\t")
21
+ resource = tags.shift
22
+ ts.add(resource, *tags)
23
+ end
24
+ end
25
+ puts "\nFinished loading"
@@ -0,0 +1,32 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'redis'
4
+ require 'commendo'
5
+ require 'progressbar'
6
+
7
+ filename = ARGV[0]
8
+ redis_db = ARGV[1].to_i
9
+ base_key = ARGV[2]
10
+
11
+ redis = Redis.new(db: redis_db, timeout: 60)
12
+ cs = Commendo::ContentSet.new(redis, base_key)
13
+
14
+ puts "Loading."
15
+ file_length = `wc -l #{filename}`.to_i
16
+ pbar = ProgressBar.new('Loading TSV file', file_length)
17
+ File.open(filename) do |f|
18
+ f.each_line.with_index do |line, i|
19
+ pbar.inc
20
+ ids = line.split("\t")
21
+ resource = ids.shift
22
+ cs.add(resource, *ids)
23
+ end
24
+ end
25
+ puts "\nFinished loading"
26
+
27
+ puts 'Calculating similarities'
28
+ pbar = nil
29
+ cs.calculate_similarity do |key, i, total|
30
+ pbar ||= ProgressBar.new('Calculating similarity', total)
31
+ pbar.inc
32
+ end
@@ -33,8 +33,12 @@ module Commendo
33
33
  return can_include && !should_exclude
34
34
  end
35
35
 
36
- def delete(resource)
36
+ def delete(resource, *tags)
37
+ if tags.empty?
37
38
  redis.del(resource_key(resource))
39
+ else
40
+ redis.srem(resource_key(resource), tags)
41
+ end
38
42
  end
39
43
 
40
44
  private
@@ -1,3 +1,3 @@
1
1
  module Commendo
2
- VERSION = '1.1.0'
2
+ VERSION = '1.2.0'
3
3
  end
data/test/tag_set_test.rb CHANGED
@@ -50,7 +50,7 @@ module Commendo
50
50
  assert_equal ['qip', 'qux'], @ts.get(2)
51
51
  end
52
52
 
53
- def test_deletes_tags_for_resource
53
+ def test_deletes_all_tags_for_resource
54
54
  @ts.set(1, 'foo', 'bar', 'baz')
55
55
  @ts.set(2, 'qux', 'qip')
56
56
  assert_equal ['bar', 'baz', 'foo'], @ts.get(1)
@@ -60,6 +60,13 @@ module Commendo
60
60
  assert_equal ['qip', 'qux'], @ts.get(2)
61
61
  end
62
62
 
63
+ def test_deletes_given_tags_for_resource
64
+ assert_equal [], @ts.get(1)
65
+ @ts.set(1, 'foo', 'bar', 'baz', 'qux', 'qip')
66
+ @ts.delete(1, 'qux', 'qip')
67
+ assert_equal ['bar', 'baz', 'foo'], @ts.get(1)
68
+ end
69
+
63
70
  def test_matches_tags
64
71
  @ts.set(1, 'foo', 'bar', 'baz')
65
72
  @ts.set(2, 'qux', 'qip')
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commendo
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Rob Styles
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-01 00:00:00.000000000 Z
11
+ date: 2015-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: redis
@@ -114,6 +114,8 @@ email:
114
114
  executables:
115
115
  - commendo-find-identical-pairs
116
116
  - commendo-load
117
+ - commendo-load-tags-tsv
118
+ - commendo-load-tsv
117
119
  - commendo-recommendations-distribution
118
120
  - commendo-similarity-distribution
119
121
  extensions: []
@@ -127,6 +129,8 @@ files:
127
129
  - Rakefile
128
130
  - bin/commendo-find-identical-pairs
129
131
  - bin/commendo-load
132
+ - bin/commendo-load-tags-tsv
133
+ - bin/commendo-load-tsv
130
134
  - bin/commendo-recommendations-distribution
131
135
  - bin/commendo-similarity-distribution
132
136
  - commendo.gemspec