ncd 0.0.1 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.travis.yml +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +9 -1
- data/lib/ncd.rb +11 -2
- data/lib/ncd/version.rb +2 -2
- data/ncd.gemspec +3 -3
- data/spec/ncd_spec.rb +21 -0
- metadata +25 -25
- checksums.yaml +0 -15
data/.travis.yml
ADDED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# NCD
|
1
|
+
# NCD [](https://travis-ci.org/masatanish/ncd)
|
2
2
|
Ruby gem for calculating Normalized Compression Distance (NCD).
|
3
3
|
|
4
4
|
It's inspired by [RubyForge code snippet](http://rubyforge.org/snippet/detail.php?type=snippet&id=3).
|
@@ -27,6 +27,14 @@ Or install it yourself as:
|
|
27
27
|
# or
|
28
28
|
distance = a.ncd(b)
|
29
29
|
```
|
30
|
+
### Setting compression level
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
NCD.level = Zlib::Defalate::DEAULT_COMPRESSION
|
34
|
+
```
|
35
|
+
Valid values of level are Zlib::Deflate::NO_COMPRESSION, BEST_SPEED, BEST_COMPRESSION, DEFAULT_COMPRESSION, and an integer from 0 to 9.
|
36
|
+
|
37
|
+
default compression level is Zlib::Defaulte::BEST_COMPRESSION.
|
30
38
|
|
31
39
|
## Contributing
|
32
40
|
|
data/lib/ncd.rb
CHANGED
@@ -2,9 +2,18 @@ require 'zlib'
|
|
2
2
|
require_relative 'ncd/version'
|
3
3
|
|
4
4
|
module NCD
|
5
|
+
@@level=Zlib::BEST_COMPRESSION
|
6
|
+
|
7
|
+
def self.level
|
8
|
+
@@level
|
9
|
+
end
|
10
|
+
|
11
|
+
def self.level=(level)
|
12
|
+
@@level = level
|
13
|
+
end
|
5
14
|
def self.distance(a, b)
|
6
|
-
min, max = [a, b].map{|d| Zlib::Deflate.deflate(d,
|
7
|
-
cab = Zlib::Deflate.deflate(a+b,
|
15
|
+
min, max = [a, b].map{|d| Zlib::Deflate.deflate(d, @@level).size }.minmax
|
16
|
+
cab = Zlib::Deflate.deflate(a+b, @@level).size
|
8
17
|
(cab.to_f - min.to_f) / max.to_f
|
9
18
|
end
|
10
19
|
end
|
data/lib/ncd/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0
|
1
|
+
module NCD
|
2
|
+
VERSION = "0.1.0"
|
3
3
|
end
|
data/ncd.gemspec
CHANGED
@@ -5,11 +5,11 @@ require 'ncd/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ncd"
|
8
|
-
spec.version =
|
8
|
+
spec.version = NCD::VERSION
|
9
9
|
spec.authors = ["Masata Nishida"]
|
10
10
|
spec.email = ["masatanish@gmail.com"]
|
11
|
-
spec.description = %q{
|
12
|
-
spec.summary = %q{
|
11
|
+
spec.description = %q{calculating Normalized Compression Distance(NCD).}
|
12
|
+
spec.summary = %q{calculating Normalized Compression Distance(NCD).}
|
13
13
|
spec.homepage = "https://github.com/masatanish/ncd"
|
14
14
|
spec.license = "MIT"
|
15
15
|
|
data/spec/ncd_spec.rb
CHANGED
@@ -19,6 +19,27 @@ describe NCD do
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
describe '.level' do
|
23
|
+
subject { NCD.level }
|
24
|
+
it 'should eq Zlib::BEST_COMPRESSION' do
|
25
|
+
expect(subject).to eq Zlib::BEST_COMPRESSION
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe '.level=' do
|
30
|
+
let(:level_value) { 0 }
|
31
|
+
subject { NCD.level = level_value }
|
32
|
+
it { expect{ subject }.to change(NCD, :level).to(level_value) }
|
33
|
+
context 'when invoke NCD.distance' do
|
34
|
+
it 'level value should be assigned to arguments of Zlib::Defaulte.deflate method' do
|
35
|
+
Zlib::Deflate.should_receive(:deflate).with(kind_of(String), level_value).exactly(3).times.and_return('aaa')
|
36
|
+
subject
|
37
|
+
NCD.distance(a, b)
|
38
|
+
end
|
39
|
+
after { NCD.level = Zlib::BEST_COMPRESSION }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
22
43
|
describe 'String#ncd' do
|
23
44
|
context 'when assigned values are same.' do
|
24
45
|
it { expect(a.ncd(a)).to be < 0.1 }
|
metadata
CHANGED
@@ -1,58 +1,50 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ncd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
5
6
|
platform: ruby
|
6
7
|
authors:
|
7
8
|
- Masata Nishida
|
8
9
|
autorequire:
|
9
10
|
bindir: bin
|
10
11
|
cert_chain: []
|
11
|
-
date: 2013-05-
|
12
|
+
date: 2013-05-20 00:00:00.000000000 Z
|
12
13
|
dependencies:
|
13
14
|
- !ruby/object:Gem::Dependency
|
14
15
|
name: bundler
|
15
|
-
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirement: &70110069779540 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
16
18
|
requirements:
|
17
19
|
- - ~>
|
18
20
|
- !ruby/object:Gem::Version
|
19
21
|
version: '1.3'
|
20
22
|
type: :development
|
21
23
|
prerelease: false
|
22
|
-
version_requirements:
|
23
|
-
requirements:
|
24
|
-
- - ~>
|
25
|
-
- !ruby/object:Gem::Version
|
26
|
-
version: '1.3'
|
24
|
+
version_requirements: *70110069779540
|
27
25
|
- !ruby/object:Gem::Dependency
|
28
26
|
name: rake
|
29
|
-
requirement: !ruby/object:Gem::Requirement
|
27
|
+
requirement: &70110069778780 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
30
29
|
requirements:
|
31
30
|
- - ! '>='
|
32
31
|
- !ruby/object:Gem::Version
|
33
32
|
version: '0'
|
34
33
|
type: :development
|
35
34
|
prerelease: false
|
36
|
-
version_requirements:
|
37
|
-
requirements:
|
38
|
-
- - ! '>='
|
39
|
-
- !ruby/object:Gem::Version
|
40
|
-
version: '0'
|
35
|
+
version_requirements: *70110069778780
|
41
36
|
- !ruby/object:Gem::Dependency
|
42
37
|
name: rspec
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
38
|
+
requirement: &70110069778100 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
44
40
|
requirements:
|
45
41
|
- - ! '>='
|
46
42
|
- !ruby/object:Gem::Version
|
47
43
|
version: 2.13.0
|
48
44
|
type: :development
|
49
45
|
prerelease: false
|
50
|
-
version_requirements:
|
51
|
-
|
52
|
-
- - ! '>='
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 2.13.0
|
55
|
-
description: gem for calculating Normalized Compression Distance.
|
46
|
+
version_requirements: *70110069778100
|
47
|
+
description: calculating Normalized Compression Distance(NCD).
|
56
48
|
email:
|
57
49
|
- masatanish@gmail.com
|
58
50
|
executables: []
|
@@ -60,6 +52,7 @@ extensions: []
|
|
60
52
|
extra_rdoc_files: []
|
61
53
|
files:
|
62
54
|
- .gitignore
|
55
|
+
- .travis.yml
|
63
56
|
- Gemfile
|
64
57
|
- LICENSE.txt
|
65
58
|
- README.md
|
@@ -72,27 +65,34 @@ files:
|
|
72
65
|
homepage: https://github.com/masatanish/ncd
|
73
66
|
licenses:
|
74
67
|
- MIT
|
75
|
-
metadata: {}
|
76
68
|
post_install_message:
|
77
69
|
rdoc_options: []
|
78
70
|
require_paths:
|
79
71
|
- lib
|
80
72
|
required_ruby_version: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
81
74
|
requirements:
|
82
75
|
- - ! '>='
|
83
76
|
- !ruby/object:Gem::Version
|
84
77
|
version: '0'
|
78
|
+
segments:
|
79
|
+
- 0
|
80
|
+
hash: -1348543594741405456
|
85
81
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
82
|
+
none: false
|
86
83
|
requirements:
|
87
84
|
- - ! '>='
|
88
85
|
- !ruby/object:Gem::Version
|
89
86
|
version: '0'
|
87
|
+
segments:
|
88
|
+
- 0
|
89
|
+
hash: -1348543594741405456
|
90
90
|
requirements: []
|
91
91
|
rubyforge_project:
|
92
|
-
rubygems_version:
|
92
|
+
rubygems_version: 1.8.16
|
93
93
|
signing_key:
|
94
|
-
specification_version:
|
95
|
-
summary:
|
94
|
+
specification_version: 3
|
95
|
+
summary: calculating Normalized Compression Distance(NCD).
|
96
96
|
test_files:
|
97
97
|
- spec/ncd_spec.rb
|
98
98
|
- spec/spec_helper.rb
|
checksums.yaml
DELETED
@@ -1,15 +0,0 @@
|
|
1
|
-
---
|
2
|
-
!binary "U0hBMQ==":
|
3
|
-
metadata.gz: !binary |-
|
4
|
-
Zjg2OGRkZDUwNmMxOGJhMjY0NzFhOWI2MjQ4OTE3NGExMTc3YjY4Yg==
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
NmY4MDU0ZjNlMjE0NDQ4ZmUzNTE1OWUxYjM5Y2I2MWZkNjdmOWQ1Yg==
|
7
|
-
!binary "U0hBNTEy":
|
8
|
-
metadata.gz: !binary |-
|
9
|
-
ZDhlZWUyZjhmNzFjMjY3Mjk2MTY1NzQ0ZmE3YzBmMmJhMWRkMzY3YmNmYWJm
|
10
|
-
MjE1ZGYzZjZjNDhjN2I4ZTk5MmM3MDJhYzVmZWI1ZWVhZjZkOGNlMzdmZTNl
|
11
|
-
OTUwNTcwYzYzODhiYjE3OTI0NGM2Mzk5NjY1MjBjZGI4Y2ZkZDI=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
ZDM5MmQ0MWE1N2I5OTEyMTI4NjhjM2Y5NzZmNjBhODNmNmU3MTg3M2U4YzZm
|
14
|
-
OTlkZTI3NGEyNDk4NzFmZDc5NjNhZWU4MTZhNzZiY2I3YTExMTg5YjE4NGY4
|
15
|
-
NmUxMGJjNDdhMzVkYzMzY2E2MTNjYTM1MzZlYzQ0MTVjNDNjZmQ=
|