sentino 0.2.2 → 0.2.3
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 +4 -4
- data/VERSION +1 -1
- data/lib/sentino.rb +1 -0
- data/lib/sentino/distance.rb +42 -0
- data/sentino.gemspec +4 -3
- data/test/test_sentino.rb +18 -2
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 32363c1bd50a1d05e9c81fdd95798293d1973bbe
|
4
|
+
data.tar.gz: ee7775161584252f0ca7f17353753c84cfa1bd78
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 11896ba754f167d242b7183fb3ac584bcd3f2ab17a031b5feacccf2bcec3ae8149c847be63c701f4b9810756a7f3d357ade88d395b40fa049ecb626afbdb1588
|
7
|
+
data.tar.gz: 88690c03c07c7c76357db1db193740161e8d5904a287420a5866e5bb2a6613db5d3ba78c6d9ac4f7b9c366613adbacbd8041b75033d2855f7f6632adef1519da
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.2.
|
1
|
+
0.2.3
|
data/lib/sentino.rb
CHANGED
@@ -0,0 +1,42 @@
|
|
1
|
+
module Sentino
|
2
|
+
class Distance
|
3
|
+
|
4
|
+
def initialize(reference)
|
5
|
+
@reference = reference
|
6
|
+
end
|
7
|
+
|
8
|
+
def match(string)
|
9
|
+
check(string)
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def check(string)
|
15
|
+
result = levenshtein(@reference, string)
|
16
|
+
return result
|
17
|
+
end
|
18
|
+
|
19
|
+
|
20
|
+
def levenshtein(first, second)
|
21
|
+
matrix = [(0..first.length).to_a]
|
22
|
+
(1..second.length).each do |j|
|
23
|
+
matrix << [j] + [0] * (first.length)
|
24
|
+
end
|
25
|
+
|
26
|
+
(1..second.length).each do |i|
|
27
|
+
(1..first.length).each do |j|
|
28
|
+
if first[j-1] == second[i-1]
|
29
|
+
matrix[i][j] = matrix[i-1][j-1]
|
30
|
+
else
|
31
|
+
matrix[i][j] = [
|
32
|
+
matrix[i-1][j],
|
33
|
+
matrix[i][j-1],
|
34
|
+
matrix[i-1][j-1],
|
35
|
+
].min + 1
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
39
|
+
return matrix.last.last
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
data/sentino.gemspec
CHANGED
@@ -2,16 +2,16 @@
|
|
2
2
|
# DO NOT EDIT THIS FILE DIRECTLY
|
3
3
|
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
4
|
# -*- encoding: utf-8 -*-
|
5
|
-
# stub: sentino 0.2.
|
5
|
+
# stub: sentino 0.2.3 ruby lib
|
6
6
|
|
7
7
|
Gem::Specification.new do |s|
|
8
8
|
s.name = "sentino"
|
9
|
-
s.version = "0.2.
|
9
|
+
s.version = "0.2.3"
|
10
10
|
|
11
11
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
12
|
s.require_paths = ["lib"]
|
13
13
|
s.authors = ["Ferhat Ziba"]
|
14
|
-
s.date = "2016-06-
|
14
|
+
s.date = "2016-06-28"
|
15
15
|
s.description = "Compare and give as result a matching result between 0 and 1"
|
16
16
|
s.email = "fero.ziba@gmail.com"
|
17
17
|
s.extra_rdoc_files = [
|
@@ -27,6 +27,7 @@ Gem::Specification.new do |s|
|
|
27
27
|
"Rakefile",
|
28
28
|
"VERSION",
|
29
29
|
"lib/sentino.rb",
|
30
|
+
"lib/sentino/distance.rb",
|
30
31
|
"lib/sentino/pattern.rb",
|
31
32
|
"lib/sentino/word.rb",
|
32
33
|
"sentino.gemspec",
|
data/test/test_sentino.rb
CHANGED
@@ -33,12 +33,28 @@ class TestSentino < Test::Unit::TestCase
|
|
33
33
|
end
|
34
34
|
|
35
35
|
should "give a higher value for roggen then for mohn" do
|
36
|
-
reference = "Brot, Cerealien & Backwaren > Mehl, Getreide & Backzutaten > Getreide >
|
37
|
-
mohn = "
|
36
|
+
reference = "Brot, Cerealien & Backwaren > Mehl, Getreide & Backzutaten > Getreide > Pseudogetreide > Quinoa"
|
37
|
+
mohn = "Baby Babynahrung Beikost Obst & Getreide"
|
38
38
|
roggen = "Lebensmittel Mehl Stärke & Co. Mehl & Getreide Roggenmehl"
|
39
39
|
sentino = Sentino::Pattern.new(reference)
|
40
40
|
assert_true sentino.match(mohn) < sentino.match(roggen)
|
41
41
|
end
|
42
42
|
|
43
|
+
should "give 1 for carrot and carrrot" do
|
44
|
+
reference = "carrot"
|
45
|
+
test_string = "carrrot"
|
46
|
+
sentino = Sentino::Distance.new(reference)
|
47
|
+
assert_equal 1, sentino.match(test_string)
|
48
|
+
|
49
|
+
end
|
50
|
+
|
51
|
+
should "give a smaller distance for roggen then for mohn" do
|
52
|
+
reference = "Brot, Cerealien & Backwaren > Mehl, Getreide & Backzutaten > Getreide > Pseudogetreide > Quinoa"
|
53
|
+
baby = "Baby Babynahrung Beikost Obst & Getreide"
|
54
|
+
roggen = "Lebensmittel Mehl Stärke & Co. Mehl & Getreide Roggenmehl"
|
55
|
+
sentino = Sentino::Distance.new(reference)
|
56
|
+
assert_true sentino.match(baby) > sentino.match(roggen)
|
57
|
+
end
|
58
|
+
|
43
59
|
|
44
60
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: sentino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ferhat Ziba
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-06-
|
11
|
+
date: 2016-06-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -110,6 +110,7 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- VERSION
|
112
112
|
- lib/sentino.rb
|
113
|
+
- lib/sentino/distance.rb
|
113
114
|
- lib/sentino/pattern.rb
|
114
115
|
- lib/sentino/word.rb
|
115
116
|
- sentino.gemspec
|