string_score 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +28 -0
- data/README.mdown +42 -0
- data/lib/string_score.rb +3 -2
- data/lib/string_score/version.rb +1 -1
- data/spec/string_score_spec.rb +1 -7
- metadata +18 -1
data/LICENSE
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
Original JS Implementation: https://github.com/joshaven/string_score (MIT)
|
2
|
+
|
3
|
+
Copyright (C) 2009-2011 Joshaven Potter
|
4
|
+
Copyright (C) 2010-2011 Yesudeep Mangalapill
|
5
|
+
|
6
|
+
This Ruby Implementation:
|
7
|
+
|
8
|
+
Copyright (c) 2011 Jim Lindley http://jimlindley.com/
|
9
|
+
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
11
|
+
a copy of this software and associated documentation files (the
|
12
|
+
"Software"), to deal in the Software without restriction, including
|
13
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
14
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
15
|
+
permit persons to whom the Software is furnished to do so, subject to
|
16
|
+
the following conditions:
|
17
|
+
|
18
|
+
The above copyright notice and this permission notice shall be
|
19
|
+
included in all copies or substantial portions of the Software.
|
20
|
+
|
21
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
22
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
23
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
24
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
25
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
26
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
27
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
28
|
+
jlindley@Amp:~/Projects/string_score[master*]$ st
|
data/README.mdown
CHANGED
@@ -3,3 +3,45 @@ String Score (Ruby)
|
|
3
3
|
|
4
4
|
Port of https://github.com/joshaven/string_score from js to ruby.
|
5
5
|
|
6
|
+
It provides scores between 0 (no match) and 1 (exact match) for a comparison
|
7
|
+
string to the base string.
|
8
|
+
|
9
|
+
|
10
|
+
Compatibility
|
11
|
+
---
|
12
|
+
|
13
|
+
Tested under Ruby 1.9.2 and Ruby 1.8.7.
|
14
|
+
|
15
|
+
Usage
|
16
|
+
---
|
17
|
+
|
18
|
+
gem install string_score
|
19
|
+
|
20
|
+
scorer = StringScore.new("string to test against")
|
21
|
+
scorer.score("string to test")
|
22
|
+
|
23
|
+
Or, include it into String for a convenience method:
|
24
|
+
|
25
|
+
|
26
|
+
String.send(:include, StringScore)
|
27
|
+
|
28
|
+
# and then
|
29
|
+
|
30
|
+
"Hello World".score("hello")
|
31
|
+
"Hello World".score("Whirl", 0.5) # or for fuzzy
|
32
|
+
|
33
|
+
Copyright
|
34
|
+
---
|
35
|
+
|
36
|
+
MIT License, see LICENSE file.
|
37
|
+
|
38
|
+
Credits
|
39
|
+
---
|
40
|
+
|
41
|
+
Closely ported from the JS version, using roughly the same algorithm and
|
42
|
+
the same test suite for implementation.
|
43
|
+
|
44
|
+
JS Original Version at: https://github.com/joshaven/string_score
|
45
|
+
Copyright (C) 2009-2011 Joshaven Potter
|
46
|
+
Copyright (C) 2010-2011 Yesudeep Mangalapilly
|
47
|
+
|
data/lib/string_score.rb
CHANGED
@@ -78,7 +78,7 @@ module StringScore
|
|
78
78
|
|
79
79
|
end
|
80
80
|
|
81
|
-
if string
|
81
|
+
if string.slice(current_index, 1) == c
|
82
82
|
character_score = 0.2 # exact case match
|
83
83
|
else
|
84
84
|
character_score = 0.1 # character but not case match
|
@@ -93,7 +93,8 @@ module StringScore
|
|
93
93
|
end
|
94
94
|
|
95
95
|
# acronym bonus
|
96
|
-
|
96
|
+
previous_index = over_all_index - 1
|
97
|
+
if base_string.slice(previous_index, 1) == ' '
|
97
98
|
character_score += 0.8
|
98
99
|
end
|
99
100
|
|
data/lib/string_score/version.rb
CHANGED
data/spec/string_score_spec.rb
CHANGED
@@ -14,12 +14,6 @@ RSpec::Matchers.define :be_less_than do |expected|
|
|
14
14
|
end
|
15
15
|
end
|
16
16
|
|
17
|
-
RSpec::Matchers.define :be_about do |expected|
|
18
|
-
match do |actual|
|
19
|
-
expected.to_f.round(5) == actual.to_f.round(5) # to 3 decimal points
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
17
|
describe StringScore do
|
24
18
|
|
25
19
|
subject { StringScore.new('Hello World') }
|
@@ -98,7 +92,7 @@ describe StringScore do
|
|
98
92
|
|
99
93
|
it "gives start of string bonuses" do
|
100
94
|
"Mary Large".score('mar').should be_greater_than("Large Mary".score('mar'))
|
101
|
-
"Silly Mary Large".score('mar').should
|
95
|
+
"Silly Mary Large".score('mar').should == "Silly Large Mary".score('mar')
|
102
96
|
end
|
103
97
|
|
104
98
|
|
metadata
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: string_score
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 23
|
4
5
|
prerelease:
|
5
|
-
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 0
|
10
|
+
version: 1.0.0
|
6
11
|
platform: ruby
|
7
12
|
authors:
|
8
13
|
- Jim Lindley
|
@@ -21,6 +26,11 @@ dependencies:
|
|
21
26
|
requirements:
|
22
27
|
- - ~>
|
23
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 27
|
30
|
+
segments:
|
31
|
+
- 2
|
32
|
+
- 5
|
33
|
+
- 0
|
24
34
|
version: 2.5.0
|
25
35
|
type: :development
|
26
36
|
version_requirements: *id001
|
@@ -36,6 +46,7 @@ extra_rdoc_files: []
|
|
36
46
|
files:
|
37
47
|
- .gitignore
|
38
48
|
- Gemfile
|
49
|
+
- LICENSE
|
39
50
|
- README.mdown
|
40
51
|
- Rakefile
|
41
52
|
- lib/string_score.rb
|
@@ -56,12 +67,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
56
67
|
requirements:
|
57
68
|
- - ">="
|
58
69
|
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
59
73
|
version: "0"
|
60
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
61
75
|
none: false
|
62
76
|
requirements:
|
63
77
|
- - ">="
|
64
78
|
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
65
82
|
version: "0"
|
66
83
|
requirements: []
|
67
84
|
|