sentino 0.1.0 → 0.2.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.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/lib/sentino/pattern.rb +54 -0
- data/lib/sentino.rb +1 -0
- data/sentino.gemspec +68 -0
- data/test/test_sentino.rb +17 -1
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f201f48f4b522c8ff4686c0a5450dcf8586e3d8
|
4
|
+
data.tar.gz: b1f59dd4d9a35600a127c79f7c45dc31c02ea480
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2be893ed10a18d19ce449b5d68fcd02fae74b1a8637e96df5090a743c093c907d943c3cf0ad19fe65441a1276af635ac82eca1a687df11f53476352f0d6f7c6e
|
7
|
+
data.tar.gz: dfc68b4dd6f1d1cc7c7c0e6cd73ec06d3aef6248a64e5790e8f32b0c25af34b0fa10f61bb0636adc3843262ad0dc95361a52fed54e5151dc30dc84b67b5d6462
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.2.0
|
@@ -0,0 +1,54 @@
|
|
1
|
+
module Sentino
|
2
|
+
class Pattern
|
3
|
+
def initialize(reference)
|
4
|
+
@reference = prepare_string(reference)
|
5
|
+
end
|
6
|
+
|
7
|
+
def match(string)
|
8
|
+
check(string)
|
9
|
+
end
|
10
|
+
|
11
|
+
|
12
|
+
private
|
13
|
+
def prepare_string(string)
|
14
|
+
words = string.split(" ").map{|s| s.downcase}
|
15
|
+
matchings = []
|
16
|
+
for word in words
|
17
|
+
matchings += create_matchings(word) if word.length > 3
|
18
|
+
end
|
19
|
+
matchings
|
20
|
+
end
|
21
|
+
|
22
|
+
def create_matchings(word, start=0, word_length=4)
|
23
|
+
list = []
|
24
|
+
max_length = word.length
|
25
|
+
return list if max_length < 4
|
26
|
+
if word_length == max_length
|
27
|
+
return [word]
|
28
|
+
elsif word_length + start < max_length
|
29
|
+
list << word[start..word_length-1+start]
|
30
|
+
list+=create_matchings(word, start+1, word_length)
|
31
|
+
elsif word_length + start == max_length
|
32
|
+
list << word[start..word_length-1+start]
|
33
|
+
list+=create_matchings(word, 0, word_length+1)
|
34
|
+
end
|
35
|
+
return list
|
36
|
+
end
|
37
|
+
|
38
|
+
def check(string)
|
39
|
+
counts = []
|
40
|
+
for mathcer in @reference
|
41
|
+
counts << count_matchings(string, mathcer)
|
42
|
+
end
|
43
|
+
puts counts
|
44
|
+
total_length = counts.map{|x| x == 0 ? 1 : x}.reduce(:+)
|
45
|
+
matching_length = counts.reduce(:+)
|
46
|
+
matching_length.to_f/total_length.to_f
|
47
|
+
end
|
48
|
+
|
49
|
+
def count_matchings(string, substring)
|
50
|
+
string.scan(/(?=#{substring})/).count
|
51
|
+
end
|
52
|
+
|
53
|
+
end
|
54
|
+
end
|
data/lib/sentino.rb
CHANGED
data/sentino.gemspec
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
# stub: sentino 0.2.0 ruby lib
|
6
|
+
|
7
|
+
Gem::Specification.new do |s|
|
8
|
+
s.name = "sentino"
|
9
|
+
s.version = "0.2.0"
|
10
|
+
|
11
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
12
|
+
s.require_paths = ["lib"]
|
13
|
+
s.authors = ["Ferhat Ziba"]
|
14
|
+
s.date = "2016-06-10"
|
15
|
+
s.description = "Compare and give as result a matching result between 0 and 1"
|
16
|
+
s.email = "fero.ziba@gmail.com"
|
17
|
+
s.extra_rdoc_files = [
|
18
|
+
"LICENSE.txt",
|
19
|
+
"README.rdoc"
|
20
|
+
]
|
21
|
+
s.files = [
|
22
|
+
".document",
|
23
|
+
"Gemfile",
|
24
|
+
"Gemfile.lock",
|
25
|
+
"LICENSE.txt",
|
26
|
+
"README.rdoc",
|
27
|
+
"Rakefile",
|
28
|
+
"VERSION",
|
29
|
+
"lib/sentino.rb",
|
30
|
+
"lib/sentino/pattern.rb",
|
31
|
+
"lib/sentino/word.rb",
|
32
|
+
"sentino.gemspec",
|
33
|
+
"test/helper.rb",
|
34
|
+
"test/test_sentino.rb"
|
35
|
+
]
|
36
|
+
s.homepage = "http://github.com/fero46/sentino"
|
37
|
+
s.licenses = ["MIT"]
|
38
|
+
s.rubygems_version = "2.4.8"
|
39
|
+
s.summary = "Compare Strings by word"
|
40
|
+
|
41
|
+
if s.respond_to? :specification_version then
|
42
|
+
s.specification_version = 4
|
43
|
+
|
44
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
45
|
+
s.add_development_dependency(%q<shoulda>, [">= 0"])
|
46
|
+
s.add_development_dependency(%q<rdoc>, ["~> 3.12"])
|
47
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0"])
|
48
|
+
s.add_development_dependency(%q<jeweler>, ["~> 2.0.1"])
|
49
|
+
s.add_development_dependency(%q<simplecov>, [">= 0"])
|
50
|
+
s.add_development_dependency(%q<test-unit>, [">= 0"])
|
51
|
+
else
|
52
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
53
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
54
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
55
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
56
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
57
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
58
|
+
end
|
59
|
+
else
|
60
|
+
s.add_dependency(%q<shoulda>, [">= 0"])
|
61
|
+
s.add_dependency(%q<rdoc>, ["~> 3.12"])
|
62
|
+
s.add_dependency(%q<bundler>, ["~> 1.0"])
|
63
|
+
s.add_dependency(%q<jeweler>, ["~> 2.0.1"])
|
64
|
+
s.add_dependency(%q<simplecov>, [">= 0"])
|
65
|
+
s.add_dependency(%q<test-unit>, [">= 0"])
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
data/test/test_sentino.rb
CHANGED
@@ -9,12 +9,28 @@ class TestSentino < Test::Unit::TestCase
|
|
9
9
|
assert_equal 1.0, sentino.match(target_1)
|
10
10
|
end
|
11
11
|
|
12
|
-
should "should give 75 % identical Words" do
|
12
|
+
should "should give 75 % identical Words" do
|
13
13
|
reference = "Der erste String Test"
|
14
14
|
target_1 = reference.gsub("erste", "zweite")
|
15
15
|
sentino = Sentino::Word.new(reference)
|
16
16
|
assert_equal 0.75, sentino.match(target_1)
|
17
|
+
end
|
18
|
+
|
19
|
+
should "give a higher value for baby then for tee" do
|
20
|
+
reference = "Babyprodukte / Babynahrung / Kekse & Tee / Babynahrung ab 4. Monat"
|
21
|
+
tee = "Getränke Kaffee & Tee Tee Grüner & weißer Tee Weißer Tee"
|
22
|
+
baby = "Baby Babynahrung Kindersnacks Babykekse"
|
23
|
+
sentino = Sentino::Pattern.new(reference)
|
24
|
+
assert_true sentino.match(tee) < sentino.match(baby)
|
25
|
+
end
|
17
26
|
|
27
|
+
should "give a higher value for suger then for obst" do
|
28
|
+
reference = "Nahrungsmittel / Zucker & Süßstoff / Süßstoff / Süßstoff"
|
29
|
+
obst = "Obst & Gemüse Gemüse Zwiebeln & Knoblauch Zwiebeln"
|
30
|
+
suger = "Lebensmittel Mehl Stärke & Co. Zucker & Süße Süßstoff"
|
31
|
+
sentino = Sentino::Pattern.new(reference)
|
32
|
+
assert_true sentino.match(obst) < sentino.match(suger)
|
18
33
|
end
|
19
34
|
|
35
|
+
|
20
36
|
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.
|
4
|
+
version: 0.2.0
|
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-
|
11
|
+
date: 2016-06-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: shoulda
|
@@ -110,7 +110,9 @@ files:
|
|
110
110
|
- Rakefile
|
111
111
|
- VERSION
|
112
112
|
- lib/sentino.rb
|
113
|
+
- lib/sentino/pattern.rb
|
113
114
|
- lib/sentino/word.rb
|
115
|
+
- sentino.gemspec
|
114
116
|
- test/helper.rb
|
115
117
|
- test/test_sentino.rb
|
116
118
|
homepage: http://github.com/fero46/sentino
|
@@ -133,7 +135,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
133
135
|
version: '0'
|
134
136
|
requirements: []
|
135
137
|
rubyforge_project:
|
136
|
-
rubygems_version: 2.4.
|
138
|
+
rubygems_version: 2.4.8
|
137
139
|
signing_key:
|
138
140
|
specification_version: 4
|
139
141
|
summary: Compare Strings by word
|