SimilaritySairo 0.0.1
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.
- checksums.yaml +7 -0
- data/lib/similarity.rb +34 -0
- metadata +44 -0
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA256:
|
|
3
|
+
metadata.gz: '087f5c121fe10b302f33f05ce9c8a8ff612aaef531e3bbcaa5d27de3f497d4ff'
|
|
4
|
+
data.tar.gz: 819cce4bec1f25b384347989ace15ef6667adc06a14f968401ca7043f1e4dcfe
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 05130cc3480e6dba4946bb025e2c387291419380a52a0c4aad1f8f642b0bcae124fa5664fbc560f612298b3a200d577438e019c618a3ba8faf390e0607d7eb97
|
|
7
|
+
data.tar.gz: 1e79dc692f01e3ca664554938930c9fce29736880ea3833fb1f9a691d9fbe682402ad077e42c8ef93960f24fcae61780b0df035ed5e3f23d83842f99cb16f36e
|
data/lib/similarity.rb
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
class Similarity
|
|
2
|
+
def self.calculate_distance(source, comparison)
|
|
3
|
+
raise "This method cannot compare to NilClass" if comparison.nil?
|
|
4
|
+
n = source.length
|
|
5
|
+
m = comparison.length
|
|
6
|
+
max = n/2
|
|
7
|
+
|
|
8
|
+
# Returns either word's length if one of them is empty
|
|
9
|
+
return m if 0 == n
|
|
10
|
+
return n if 0 == m
|
|
11
|
+
|
|
12
|
+
# Checks if both words are equal and returns 0
|
|
13
|
+
return 0 if source.eql? comparison
|
|
14
|
+
|
|
15
|
+
d = (0..m).to_a
|
|
16
|
+
x = nil
|
|
17
|
+
source.each_char.with_index do |char1, i|
|
|
18
|
+
e = i+1
|
|
19
|
+
comparison.each_char.with_index do |char2, j|
|
|
20
|
+
cost = (char1 == char2) ? 0 : 1
|
|
21
|
+
x =
|
|
22
|
+
[
|
|
23
|
+
d[j+1] + 1, # insertion
|
|
24
|
+
e + 1, # deletion
|
|
25
|
+
d[j] + cost # substitution
|
|
26
|
+
].min
|
|
27
|
+
d[j] = e
|
|
28
|
+
e = x
|
|
29
|
+
end
|
|
30
|
+
d[m] = x
|
|
31
|
+
end
|
|
32
|
+
return x
|
|
33
|
+
end
|
|
34
|
+
end
|
metadata
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
|
+
name: SimilaritySairo
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
version: 0.0.1
|
|
5
|
+
platform: ruby
|
|
6
|
+
authors:
|
|
7
|
+
- Sairo Guanipa
|
|
8
|
+
autorequire:
|
|
9
|
+
bindir: bin
|
|
10
|
+
cert_chain: []
|
|
11
|
+
date: 2021-03-08 00:00:00.000000000 Z
|
|
12
|
+
dependencies: []
|
|
13
|
+
description: A similarity gem
|
|
14
|
+
email: sairo.guanipa@bairesdev.com
|
|
15
|
+
executables: []
|
|
16
|
+
extensions: []
|
|
17
|
+
extra_rdoc_files: []
|
|
18
|
+
files:
|
|
19
|
+
- lib/similarity.rb
|
|
20
|
+
homepage: https://rubygems.org/gems/similarity
|
|
21
|
+
licenses:
|
|
22
|
+
- MIT
|
|
23
|
+
metadata: {}
|
|
24
|
+
post_install_message:
|
|
25
|
+
rdoc_options: []
|
|
26
|
+
require_paths:
|
|
27
|
+
- lib
|
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
29
|
+
requirements:
|
|
30
|
+
- - ">="
|
|
31
|
+
- !ruby/object:Gem::Version
|
|
32
|
+
version: '0'
|
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
34
|
+
requirements:
|
|
35
|
+
- - ">="
|
|
36
|
+
- !ruby/object:Gem::Version
|
|
37
|
+
version: '0'
|
|
38
|
+
requirements: []
|
|
39
|
+
rubygems_version: 3.2.3
|
|
40
|
+
signing_key:
|
|
41
|
+
specification_version: 4
|
|
42
|
+
summary: Compares two strings and returns the amount of modifications between the
|
|
43
|
+
two
|
|
44
|
+
test_files: []
|