synt 0.1.3 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.ruby-version +1 -0
- data/Gemfile +4 -4
- data/Gemfile.lock +25 -22
- data/lib/synt.rb +3 -3
- data/lib/synt/cli.rb +11 -8
- data/lib/synt/similar.rb +11 -10
- data/lib/synt/version.rb +1 -1
- data/spec/synt_spec.rb +14 -15
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 656ca89214a981b499724da4bfeaf43c2de085d4
|
4
|
+
data.tar.gz: 59fcdcb6c52321be7441cc3ddcc69dfb1c282dfd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bb0b5d506e958cd1801a98d853228b0975fcf6adf38fa6f11506285759b4763a7ecc1d74c2f9a5e76c547c2be10721946fdc8404070c663459e7377035d83a7e
|
7
|
+
data.tar.gz: 30477ea25ef2156e7bf43e5ec000a8ea7ac39758d97254900811c575926e22117d028c45dd70e79aa8b2b61c6ba00549a45e954667043cd5737b85780453e8bb
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.1.5
|
data/Gemfile
CHANGED
@@ -2,7 +2,7 @@ source 'https://rubygems.org'
|
|
2
2
|
|
3
3
|
gem 'slop', '3.6.0'
|
4
4
|
gem 'manowar', '0.0.1'
|
5
|
-
gem 'rspec', '3.
|
6
|
-
gem 'rubocop', '0.
|
7
|
-
gem 'simplecov', '0.9.
|
8
|
-
gem 'simplecov-lcov', require: false, group: :development
|
5
|
+
gem 'rspec', '3.1.0', require: false, group: :development
|
6
|
+
gem 'rubocop', '0.28.0', require: false, group: :development
|
7
|
+
gem 'simplecov', '0.9.1', require: false, group: :development
|
8
|
+
gem 'simplecov-lcov', '0.4.0', require: false, group: :development
|
data/Gemfile.lock
CHANGED
@@ -2,39 +2,42 @@ GEM
|
|
2
2
|
remote: https://rubygems.org/
|
3
3
|
specs:
|
4
4
|
ast (2.0.0)
|
5
|
+
astrolabe (1.3.0)
|
6
|
+
parser (>= 2.2.0.pre.3, < 3.0)
|
5
7
|
diff-lcs (1.2.5)
|
6
8
|
docile (1.1.5)
|
7
9
|
manowar (0.0.1)
|
8
10
|
multi_json (1.10.1)
|
9
|
-
parser (2.2.0.
|
11
|
+
parser (2.2.0.1)
|
10
12
|
ast (>= 1.1, < 3.0)
|
11
13
|
slop (~> 3.4, >= 3.4.5)
|
12
14
|
powerpack (0.0.9)
|
13
15
|
rainbow (2.0.0)
|
14
|
-
rspec (3.
|
15
|
-
rspec-core (~> 3.
|
16
|
-
rspec-expectations (~> 3.
|
17
|
-
rspec-mocks (~> 3.
|
18
|
-
rspec-core (3.
|
19
|
-
rspec-support (~> 3.
|
20
|
-
rspec-expectations (3.
|
16
|
+
rspec (3.1.0)
|
17
|
+
rspec-core (~> 3.1.0)
|
18
|
+
rspec-expectations (~> 3.1.0)
|
19
|
+
rspec-mocks (~> 3.1.0)
|
20
|
+
rspec-core (3.1.7)
|
21
|
+
rspec-support (~> 3.1.0)
|
22
|
+
rspec-expectations (3.1.2)
|
21
23
|
diff-lcs (>= 1.2.0, < 2.0)
|
22
|
-
rspec-support (~> 3.
|
23
|
-
rspec-mocks (3.
|
24
|
-
rspec-support (~> 3.
|
25
|
-
rspec-support (3.
|
26
|
-
rubocop (0.
|
27
|
-
|
24
|
+
rspec-support (~> 3.1.0)
|
25
|
+
rspec-mocks (3.1.3)
|
26
|
+
rspec-support (~> 3.1.0)
|
27
|
+
rspec-support (3.1.2)
|
28
|
+
rubocop (0.28.0)
|
29
|
+
astrolabe (~> 1.3)
|
30
|
+
parser (>= 2.2.0.pre.7, < 3.0)
|
28
31
|
powerpack (~> 0.0.6)
|
29
32
|
rainbow (>= 1.99.1, < 3.0)
|
30
33
|
ruby-progressbar (~> 1.4)
|
31
|
-
ruby-progressbar (1.
|
32
|
-
simplecov (0.9.
|
34
|
+
ruby-progressbar (1.7.1)
|
35
|
+
simplecov (0.9.1)
|
33
36
|
docile (~> 1.1.0)
|
34
|
-
multi_json
|
37
|
+
multi_json (~> 1.0)
|
35
38
|
simplecov-html (~> 0.8.0)
|
36
39
|
simplecov-html (0.8.0)
|
37
|
-
simplecov-lcov (0.
|
40
|
+
simplecov-lcov (0.4.0)
|
38
41
|
slop (3.6.0)
|
39
42
|
|
40
43
|
PLATFORMS
|
@@ -42,8 +45,8 @@ PLATFORMS
|
|
42
45
|
|
43
46
|
DEPENDENCIES
|
44
47
|
manowar (= 0.0.1)
|
45
|
-
rspec (= 3.
|
46
|
-
rubocop (= 0.
|
47
|
-
simplecov (= 0.9.
|
48
|
-
simplecov-lcov
|
48
|
+
rspec (= 3.1.0)
|
49
|
+
rubocop (= 0.28.0)
|
50
|
+
simplecov (= 0.9.1)
|
51
|
+
simplecov-lcov (= 0.4.0)
|
49
52
|
slop (= 3.6.0)
|
data/lib/synt.rb
CHANGED
@@ -9,10 +9,10 @@ module Synt
|
|
9
9
|
opts = CLI.parse
|
10
10
|
diff = Similar.compare opts
|
11
11
|
|
12
|
-
puts "Inputs are
|
12
|
+
puts "Inputs are #{diff}% similar."
|
13
13
|
|
14
|
-
if opts.threshold? && diff < opts[
|
15
|
-
puts "Similarity threshold of #{opts[
|
14
|
+
if opts.threshold? && diff < opts["min-threshold"].to_f
|
15
|
+
puts "Similarity threshold of #{opts["min-threshold"]}% hit."
|
16
16
|
exit 1
|
17
17
|
end
|
18
18
|
end
|
data/lib/synt/cli.rb
CHANGED
@@ -16,15 +16,18 @@ module Synt::CLI
|
|
16
16
|
API = proc {
|
17
17
|
banner 'Usage: synt.rb [options]'
|
18
18
|
|
19
|
-
on 'c=', 'compare=',
|
20
|
-
on 't=', 'to=',
|
21
|
-
on '
|
22
|
-
on '
|
23
|
-
|
24
|
-
|
25
|
-
|
19
|
+
on 'c=', 'compare=', 'File to compare to something.'
|
20
|
+
on 't=', 'to=', 'File to compare against.'
|
21
|
+
on 's', 'string-compare', 'Compare strings instead of files.'
|
22
|
+
on 'a=', 'algorithm=', 'Similarity algorithm
|
23
|
+
[default=jaccard,tanimoto].'
|
24
|
+
on 'n=', 'ngram=', 'Specify what ngrams are generated and used for
|
25
|
+
comparing token sequences.
|
26
|
+
[default=1,2,4..5,10,...,all]'
|
27
|
+
on 'm=', 'min-threshold=', 'Similarity threshold % (ex: -m 70)
|
28
|
+
to exit with error.'
|
26
29
|
|
27
|
-
on '-v', 'version',
|
30
|
+
on '-v', 'version', 'Print the version.' do
|
28
31
|
puts Synt::VERSION
|
29
32
|
exit 0
|
30
33
|
end
|
data/lib/synt/similar.rb
CHANGED
@@ -8,20 +8,13 @@ define 'Synt'
|
|
8
8
|
module Synt::Similar
|
9
9
|
extend self
|
10
10
|
|
11
|
-
def determine string_or_file
|
12
|
-
if File.exists? string_or_file
|
13
|
-
IO.read string_or_file
|
14
|
-
else
|
15
|
-
string_or_file || ''
|
16
|
-
end
|
17
|
-
end
|
18
|
-
|
19
11
|
def compare opts
|
20
12
|
error 'no compare propery provided' unless opts[:compare]
|
21
13
|
error 'no to propery provided' unless opts[:to]
|
22
14
|
|
23
|
-
|
24
|
-
|
15
|
+
# TODO: string-compare sucks to reference..
|
16
|
+
src = parse_data opts["string-compare"], opts[:compare]
|
17
|
+
cmp = parse_data opts["string-compare"], opts[:to]
|
25
18
|
algorithm = algorithms[(opts[:algorithm] || 'jaccard').to_sym]
|
26
19
|
n_start, n_end = ngram_range opts[:ngram]
|
27
20
|
src_t = normalize_ripper_tokens Synt::Parser.parse(src)
|
@@ -41,6 +34,14 @@ module Synt::Similar
|
|
41
34
|
{ jaccard: Jaccard, tanimoto: Tanimoto }
|
42
35
|
end
|
43
36
|
|
37
|
+
def parse_data is_string, value
|
38
|
+
if is_string
|
39
|
+
value
|
40
|
+
else
|
41
|
+
IO.read value
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
44
45
|
def generate_ngrams arr, start, nend
|
45
46
|
nend = arr.length unless nend
|
46
47
|
start = 1 unless start
|
data/lib/synt/version.rb
CHANGED
data/spec/synt_spec.rb
CHANGED
@@ -13,11 +13,12 @@ describe Synt::Similar do
|
|
13
13
|
let(:dissimilar_a_path) { 'spec/fixtures/compare-rb-dissimilar-a.rb' }
|
14
14
|
let(:dissimilar_b_path) { 'spec/fixtures/compare-rb-dissimilar-b.rb' }
|
15
15
|
|
16
|
+
# TODO: implement min-threshold behaviour
|
17
|
+
|
16
18
|
context 'cli' do
|
17
19
|
context 'comparing things' do
|
18
20
|
context 'that are Files' do
|
19
21
|
before do
|
20
|
-
allow(File).to receive(:exists?).and_return(true)
|
21
22
|
expect(IO).to receive(:read).and_return("42").twice
|
22
23
|
end
|
23
24
|
|
@@ -28,27 +29,29 @@ describe Synt::Similar do
|
|
28
29
|
|
29
30
|
context 'that are Strings' do
|
30
31
|
before do
|
31
|
-
allow(File).to receive(:exists?).and_return(false)
|
32
32
|
expect(IO).to_not receive(:read)
|
33
33
|
end
|
34
34
|
|
35
35
|
it 'should not read any files' do
|
36
|
-
subject.compare compare: "file/path.rb",
|
36
|
+
subject.compare compare: "file/path.rb",
|
37
|
+
to: "file/path2",
|
38
|
+
"string-compare" => true
|
37
39
|
end
|
38
40
|
end
|
39
41
|
end
|
40
42
|
end
|
41
43
|
|
42
44
|
context 'duplicate code comparison' do
|
43
|
-
let(:dupe) { file_to_s duplicate_path }
|
44
|
-
|
45
45
|
algorithms.each do |algorithm|
|
46
46
|
context "using the #{algorithm} algorithm" do
|
47
47
|
ngram_types.each do |ngram|
|
48
48
|
context "with an ngram of #{ngram}" do
|
49
49
|
it 'is 100%' do
|
50
|
-
sim = subject.compare compare:
|
51
|
-
|
50
|
+
sim = subject.compare compare: duplicate_path,
|
51
|
+
to: duplicate_path,
|
52
|
+
ngram: ngram,
|
53
|
+
algorithm: algorithm
|
54
|
+
|
52
55
|
expect(sim).to eq 100
|
53
56
|
end
|
54
57
|
end
|
@@ -58,13 +61,11 @@ describe Synt::Similar do
|
|
58
61
|
end
|
59
62
|
|
60
63
|
context 'similar code comparison' do
|
61
|
-
let(:sim_a) { file_to_s similar_a_path }
|
62
|
-
let(:sim_b) { file_to_s similar_b_path }
|
63
|
-
|
64
64
|
algorithms.each do |algorithm|
|
65
65
|
context "using the #{algorithm} algorithm" do
|
66
66
|
it 'is ~81%' do
|
67
|
-
sim = subject.compare compare:
|
67
|
+
sim = subject.compare compare: similar_a_path,
|
68
|
+
to: similar_b_path,
|
68
69
|
algorithm: algorithm
|
69
70
|
expect(80..82).to cover(sim)
|
70
71
|
end
|
@@ -73,13 +74,11 @@ describe Synt::Similar do
|
|
73
74
|
end
|
74
75
|
|
75
76
|
context 'dissimilar code comparison' do
|
76
|
-
let(:dissim_a) { file_to_s dissimilar_a_path }
|
77
|
-
let(:dissim_b) { file_to_s dissimilar_b_path }
|
78
|
-
|
79
77
|
algorithms.each do |algorithm|
|
80
78
|
context "using the #{algorithm} algorithm" do
|
81
79
|
it 'is ~22%' do
|
82
|
-
sim = subject.compare compare:
|
80
|
+
sim = subject.compare compare: dissimilar_a_path,
|
81
|
+
to: dissimilar_b_path,
|
83
82
|
algorithm: algorithm
|
84
83
|
expect(21..23).to cover(sim)
|
85
84
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: synt
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brent Lintner
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2015-01-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: manowar
|
@@ -61,6 +61,7 @@ extensions: []
|
|
61
61
|
extra_rdoc_files: []
|
62
62
|
files:
|
63
63
|
- ".rubocop.yml"
|
64
|
+
- ".ruby-version"
|
64
65
|
- Gemfile
|
65
66
|
- Gemfile.lock
|
66
67
|
- bin/lint
|
@@ -103,7 +104,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
103
104
|
version: '0'
|
104
105
|
requirements: []
|
105
106
|
rubyforge_project:
|
106
|
-
rubygems_version: 2.
|
107
|
+
rubygems_version: 2.4.3
|
107
108
|
signing_key:
|
108
109
|
specification_version: 4
|
109
110
|
summary: Similar code analysis.
|