fuzzy-string-match_pure 0.9.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1 @@
1
+
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright [yyyy] [name of copyright owner]
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,98 @@
1
+ # What is fuzzy-string-match
2
+ [![Build Status](https://secure.travis-ci.org/kiyoka/fuzzy-string-match.png)](http://travis-ci.org/kiyoka/fuzzy-string-match)
3
+
4
+ * fuzzy-string-match is a fuzzy string matching library for ruby.
5
+ * It is fast. ( written in C with RubyInline )
6
+ * It supports only Jaro-Winkler distance algorithm.
7
+ * This program was ported by hand from lucene-3.0.2. (lucene is Java product)
8
+ * If you want to add another string distance algorithm, please fork it on github and port by yourself.
9
+
10
+ ## The reason why i developed fuzzy-string-match
11
+ * I tried amatch-0.2.5, but it contains some issues.
12
+ 1. memory leaks.
13
+ 2. I felt difficult to maintain it.
14
+ * So, I decide to create another gem by porting lucene-3.0.x.
15
+
16
+ ## Installing
17
+
18
+ gem install fuzzy-string-match
19
+
20
+ ## Installing (pure ruby version)
21
+
22
+ gem install fuzzy-string-match_pure
23
+
24
+ ## Features
25
+ * Calculate Jaro-Winkler distance of two strings.
26
+ * Pure ruby version can handle both ASCII and UTF8 strings. (and slow)
27
+ * Native version can only ASCII strings. (but it is fast)
28
+
29
+ ## Sample code
30
+
31
+ ### Native version
32
+
33
+ require 'fuzzystringmatch'
34
+ jarow = FuzzyStringMatch::JaroWinkler.create( :native )
35
+ p jarow.getDistance( "jones", "johnson" )
36
+
37
+ ### Pure ruby version
38
+
39
+ require 'fuzzystringmatch'
40
+ jarow = FuzzyStringMatch::JaroWinkler.create( :pure )
41
+ p jarow.getDistance( "jones", "johnson" )
42
+ p jarow.getDistance( "ああ", "あい" )
43
+
44
+ ## Sample on irb
45
+
46
+ irb(main):001:0> require 'fuzzystringmatch'
47
+ require 'fuzzystringmatch'
48
+ => true
49
+
50
+ irb(main):002:0> jarow = FuzzyStringMatch::JaroWinkler.create( :native )
51
+ jarow = FuzzyStringMatch::JaroWinkler.create( :native )
52
+ => #<FuzzyStringMatch::JaroWinklerNative:0x000001011b0010>
53
+
54
+ irb(main):003:0> jarow.getDistance( "al", "al" )
55
+ jarow.getDistance( "al", "al" )
56
+ => 1.0
57
+
58
+ irb(main):004:0> jarow.getDistance( "dixon", "dicksonx" )
59
+ jarow.getDistance( "dixon", "dicksonx" )
60
+ => 0.8133333333333332
61
+
62
+ ## Benchmarks
63
+
64
+ $ rake bench
65
+ ruby ./benchmark/vs_amatch.rb
66
+ ---
67
+ --- Each match functions will be called 1Mega times. ---
68
+ ---
69
+ [Amatch]
70
+ user system total real
71
+ 1.160000 0.050000 1.210000 ( 1.218259)
72
+ [this Module (pure)]
73
+ user system total real
74
+ 39.940000 0.160000 40.100000 ( 40.542448)
75
+ [this Module (native)]
76
+ user system total real
77
+ 0.480000 0.000000 0.480000 ( 0.484187)
78
+
79
+ ## Requires
80
+
81
+ ### for CRuby
82
+ - RubyInline
83
+ - Ruby 1.9.1 or higher
84
+
85
+ ### for JRuby
86
+ - JRuby 1.6.6 or higher
87
+
88
+ ## Author
89
+ - Copyright (C) Kiyoka Nishiyama <kiyoka@sumibi.org>
90
+ - I ported from java source code of lucene-3.0.2.
91
+
92
+ ## See also
93
+ - <http://en.wikipedia.org/wiki/Jaro–Winkler_distance>
94
+ - <http://lucene.apache.org/>
95
+ - <http://github.com/naoya/perl-text-jarowinkler>
96
+
97
+ ## License
98
+ - Apache 2.0 LICENSE
@@ -0,0 +1,87 @@
1
+ #-*- mode: ruby; -*-
2
+ #
3
+ # Release Engineering
4
+ # 1. edit the VERSION.yml file
5
+ # 2. rake test
6
+ # 3. rake gemspec && rake build
7
+ # to generate fuzzy-string-match-x.x.x.gem
8
+ # 4. install fuzzy-string-match-x.x.x.gem to clean environment and test
9
+ # 5. rake release
10
+ # 6. gem push pkg/fuzzy-string-match-x.x.x.gem ( need gem version 1.3.6 or higer. Please "gem update --system" to update )
11
+ #
12
+ # for Development
13
+ # rake test_dev
14
+ # rake benchmark
15
+
16
+ require 'rake'
17
+ begin
18
+ require 'jeweler'
19
+
20
+ Jeweler::Tasks.new do |gemspec|
21
+ gemspec.name = "fuzzy-string-match_pure"
22
+ gemspec.summary = "fuzzy string matching library (Pure ruby version)"
23
+ gemspec.description = "calculate Jaro Winkler distance."
24
+ gemspec.email = "kiyoka@sumibi.org"
25
+ gemspec.homepage = "http://github.com/kiyoka/fuzzy-string-match"
26
+ gemspec.authors = ["Kiyoka Nishiyama"]
27
+ gemspec.files = FileList['.gemtest',
28
+ 'Rakefile',
29
+ 'VERSION.yml',
30
+ 'lib/fuzzystringmatch/pure/jarowinkler.rb',
31
+ 'lib/fuzzystringmatch/pure.rb',
32
+ 'lib/fuzzystringmatch.rb',
33
+ 'lib/*.rb',
34
+ 'test/basic_pure_spec.rb',
35
+ 'test/mutibyte_spec.rb',
36
+ 'LICENSE.txt',
37
+ 'README.md'].to_a
38
+ gemspec.add_dependency( "rspec" )
39
+ gemspec.required_ruby_version = '>= 1.9.1'
40
+ end
41
+
42
+ Jeweler::Tasks.new do |gemspec|
43
+ gemspec.name = "fuzzy-string-match"
44
+ gemspec.summary = "fuzzy string matching library"
45
+ gemspec.description = "calculate Jaro Winkler distance."
46
+ gemspec.email = "kiyoka@sumibi.org"
47
+ gemspec.homepage = "http://github.com/kiyoka/fuzzy-string-match"
48
+ gemspec.authors = ["Kiyoka Nishiyama"]
49
+ gemspec.files = FileList['.gemtest',
50
+ 'Rakefile',
51
+ 'VERSION.yml',
52
+ 'lib/fuzzystringmatch/inline/jarowinkler.rb',
53
+ 'lib/fuzzystringmatch/inline.rb',
54
+ 'lib/fuzzystringmatch/pure/jarowinkler.rb',
55
+ 'lib/fuzzystringmatch/pure.rb',
56
+ 'lib/fuzzystringmatch.rb',
57
+ 'test/basic_native_spec.rb',
58
+ 'test/basic_pure_spec.rb',
59
+ 'test/mutibyte_spec.rb',
60
+ 'LICENSE.txt',
61
+ 'README.md'].to_a
62
+ gemspec.add_dependency( "rspec" )
63
+ gemspec.add_dependency( 'RubyInline', '>= 3.8.6')
64
+ gemspec.required_ruby_version = '>= 1.9.1'
65
+ end
66
+
67
+ rescue LoadError
68
+ puts "Jeweler not available. Install it with: sudo gem install jeweler"
69
+ end
70
+
71
+ task :default => [:test] do
72
+ end
73
+
74
+ task :test do
75
+ sh "ruby -I ./lib `which rspec` -b ./test/basic_native_spec.rb" if File.exist?( "./test/basic_native_spec.rb" )
76
+ sh "ruby -I ./lib `which rspec` -b ./test/basic_pure_spec.rb"
77
+ sh "ruby -I ./lib `which rspec` -b ./test/mutibyte_spec.rb"
78
+ end
79
+
80
+ task :test_dev do
81
+ sh "ruby -I ./lib `which rspec` -b ./test/verify_with_amatch_spec.rb"
82
+ end
83
+
84
+ task :bench do
85
+ sh "ruby ./benchmark/vs_amatch.rb"
86
+ end
87
+
@@ -0,0 +1,4 @@
1
+ ---
2
+ :major: 0
3
+ :minor: 9
4
+ :patch: 2
@@ -0,0 +1,48 @@
1
+ #
2
+ # Fuzzy String Match
3
+ #
4
+ # Copyright 2010-2011 Kiyoka Nishiyama
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require 'fuzzystringmatch/pure'
19
+ begin
20
+ if RUBY_PLATFORM == "java"
21
+ STDERR.puts "fuzzy-string-match Warning: native version is disabled on java platform. falled back to pure ruby version..."
22
+ else
23
+ require 'fuzzystringmatch/inline'
24
+ end
25
+ rescue LoadError
26
+ end
27
+
28
+ module FuzzyStringMatch
29
+ class JaroWinkler
30
+ def self.create( type = :pure ) # factory method
31
+ case type
32
+ when :pure
33
+ FuzzyStringMatch::JaroWinklerPure.new
34
+ when :native
35
+ begin
36
+ FuzzyStringMatch::JaroWinklerInline.new
37
+ rescue NameError
38
+ STDERR.puts "fuzzy-string-match Warning: native version is disabled. falled back to pure ruby version..."
39
+ FuzzyStringMatch::JaroWinklerPure.new
40
+ end
41
+ end
42
+ end
43
+ def create( type = :pure ) # this is obsolute
44
+ STDERR.puts "fuzzy-string-match Warning: FuzzyStringMatch.new.create() is obsolute, please use FuzzyStringMatch.create() ..."
45
+ FuzzyStringMatch::JaroWinkler.create( type )
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,18 @@
1
+ #
2
+ # Fuzzy String Match
3
+ #
4
+ # Copyright 2010-2011 Kiyoka Nishiyama
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ require 'fuzzystringmatch/pure/jarowinkler'
@@ -0,0 +1,101 @@
1
+ #
2
+ # Fuzzy String Match
3
+ #
4
+ # Copyright 2010-2011 Kiyoka Nishiyama
5
+ #
6
+ # Licensed under the Apache License, Version 2.0 (the "License");
7
+ # you may not use this file except in compliance with the License.
8
+ # You may obtain a copy of the License at
9
+ #
10
+ # http://www.apache.org/licenses/LICENSE-2.0
11
+ #
12
+ # Unless required by applicable law or agreed to in writing, software
13
+ # distributed under the License is distributed on an "AS IS" BASIS,
14
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15
+ # See the License for the specific language governing permissions and
16
+ # limitations under the License.
17
+ #
18
+ module FuzzyStringMatch
19
+ class JaroWinklerPure
20
+ THRESHOLD = 0.7
21
+
22
+ def pure?
23
+ true
24
+ end
25
+
26
+ def getDistance( s1, s2 )
27
+ a1 = s1.split( // )
28
+ a2 = s2.split( // )
29
+
30
+ if s1.size > s2.size
31
+ (max,min) = a1,a2
32
+ else
33
+ (max,min) = a2,a1
34
+ end
35
+
36
+ range = [ (max.size / 2 - 1), 0 ].max
37
+ indexes = Array.new( min.size, -1 )
38
+ flags = Array.new( max.size, false )
39
+
40
+ matches = 0;
41
+ (0 ... min.size).each { |mi|
42
+ c1 = min[mi]
43
+ xi = [mi - range, 0].max
44
+ xn = [mi + range + 1, max.size].min
45
+
46
+ (xi ... xn).each { |i|
47
+ if (not flags[i]) && ( c1 == max[i] )
48
+ indexes[mi] = i
49
+ flags[i] = true
50
+ matches += 1
51
+ break
52
+ end
53
+ }
54
+ }
55
+
56
+ ms1 = Array.new( matches, nil )
57
+ ms2 = Array.new( matches, nil )
58
+
59
+ si = 0
60
+ (0 ... min.size).each { |i|
61
+ if (indexes[i] != -1)
62
+ ms1[si] = min[i]
63
+ si += 1
64
+ end
65
+ }
66
+
67
+ si = 0
68
+ (0 ... max.size).each { |i|
69
+ if flags[i]
70
+ ms2[si] = max[i]
71
+ si += 1
72
+ end
73
+ }
74
+
75
+ transpositions = 0
76
+ (0 ... ms1.size).each { |mi|
77
+ if ms1[mi] != ms2[mi]
78
+ transpositions += 1
79
+ end
80
+ }
81
+
82
+ prefix = 0
83
+ (0 ... min.size).each { |mi|
84
+ if s1[mi] == s2[mi]
85
+ prefix += 1
86
+ else
87
+ break
88
+ end
89
+ }
90
+
91
+ if 0 == matches
92
+ 0.0
93
+ else
94
+ m = matches.to_f
95
+ t = (transpositions/ 2)
96
+ j = ((m / s1.size) + (m / s2.size) + ((m - t) / m)) / 3.0;
97
+ return j < THRESHOLD ? j : j + [0.1, 1.0 / max.size].min * prefix * (1 - j)
98
+ end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,62 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ #
4
+ # basic_pure_spec.rb - "Basic test-cases for FuzzyStringMatch module "
5
+ #
6
+ # Copyright (c) 2011 Kiyoka Nishiyama <kiyoka@sumibi.org>
7
+ #
8
+ # Licensed to the Apache Software Foundation (ASF) under one or more
9
+ # contributor license agreements. See the NOTICE file distributed with
10
+ # this work for additional information regarding copyright ownership.
11
+ # The ASF licenses this file to You under the Apache License, Version 2.0
12
+ # (the "License"); you may not use this file except in compliance with
13
+ # the License. You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ #
23
+ #
24
+ require 'fuzzystringmatch'
25
+
26
+ describe FuzzyStringMatch, "when some string distances (Pure) are" do
27
+ before do
28
+ @jarow = FuzzyStringMatch::JaroWinkler.create
29
+ end
30
+ it "should" do
31
+ @jarow.getDistance( "henka", "henkan" ).should be_within(0.0001).of(0.9722)
32
+ @jarow.getDistance( "al", "al" ).should == 1.0
33
+ @jarow.getDistance( "martha", "marhta" ).should be_within(0.0001).of(0.9611)
34
+ @jarow.getDistance( "jones", "johnson" ).should be_within(0.0001).of(0.8323)
35
+ @jarow.getDistance( "abcvwxyz", "cabvwxyz" ).should be_within(0.0001).of(0.9583)
36
+ @jarow.getDistance( "dwayne", "duane" ).should be_within(0.0001).of(0.8400)
37
+ @jarow.getDistance( "dixon", "dicksonx" ).should be_within(0.0001).of(0.8133)
38
+ @jarow.getDistance( "fvie", "ten" ).should == 0.0
39
+ lambda {
40
+ d1 = @jarow.getDistance("zac ephron", "zac efron")
41
+ d2 = @jarow.getDistance("zac ephron", "kai ephron")
42
+ d1 > d2
43
+ }.should be_true
44
+ lambda {
45
+ d1 = @jarow.getDistance("brittney spears", "britney spears")
46
+ d2 = @jarow.getDistance("brittney spears", "brittney startzman")
47
+ d1 > d2
48
+ }.should be_true
49
+
50
+ @jarow.pure?( ).should be_true
51
+ end
52
+ end
53
+
54
+ describe FuzzyStringMatch, "when older factory method was called, (Pure) are" do
55
+ before do
56
+ @jarow = FuzzyStringMatch::JaroWinkler.new.create
57
+ end
58
+ it "should" do
59
+ @jarow.getDistance( "henka", "henkan" ).should be_within(0.0001).of(0.9722)
60
+ @jarow.pure?( ).should be_true
61
+ end
62
+ end
@@ -0,0 +1,58 @@
1
+ #!/usr/bin/env ruby
2
+ # -*- encoding: utf-8 -*-
3
+ #
4
+ # mutibyte_spec.rb - "Multibyte test-cases for FuzzyStringMatch module "
5
+ #
6
+ # Copyright (c) 2011 Kiyoka Nishiyama <kiyoka@sumibi.org>
7
+ #
8
+ # Licensed to the Apache Software Foundation (ASF) under one or more
9
+ # contributor license agreements. See the NOTICE file distributed with
10
+ # this work for additional information regarding copyright ownership.
11
+ # The ASF licenses this file to You under the Apache License, Version 2.0
12
+ # (the "License"); you may not use this file except in compliance with
13
+ # the License. You may obtain a copy of the License at
14
+ #
15
+ # http://www.apache.org/licenses/LICENSE-2.0
16
+ #
17
+ # Unless required by applicable law or agreed to in writing, software
18
+ # distributed under the License is distributed on an "AS IS" BASIS,
19
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
+ # See the License for the specific language governing permissions and
21
+ # limitations under the License.
22
+ #
23
+ #
24
+ require 'fuzzystringmatch'
25
+
26
+ describe FuzzyStringMatch, "when some UTF8 string distances (Pure) are" do
27
+ before do
28
+ @jarow = FuzzyStringMatch::JaroWinkler.create
29
+ end
30
+ it "should" do
31
+ @jarow.getDistance( "al", "al" ).should == 1.0
32
+ @jarow.getDistance( "martha", "marhta" ).should be_within(0.0001).of(0.9611)
33
+ @jarow.getDistance( "jones", "johnson" ).should be_within(0.0001).of(0.8323)
34
+ @jarow.getDistance( "abcvwxyz", "cabvwxyz" ).should be_within(0.0001).of(0.9583)
35
+ @jarow.getDistance( "dwayne", "duane" ).should be_within(0.0001).of(0.8400)
36
+ @jarow.getDistance( "dixon", "dicksonx" ).should be_within(0.0001).of(0.8133)
37
+ @jarow.getDistance( "fvie", "ten" ).should == 0.0
38
+ lambda {
39
+ d1 = @jarow.getDistance("zac ephron", "zac efron")
40
+ d2 = @jarow.getDistance("zac ephron", "kai ephron")
41
+ d1 > d2
42
+ }.should be_true
43
+ lambda {
44
+ d1 = @jarow.getDistance("brittney spears", "britney spears")
45
+ d2 = @jarow.getDistance("brittney spears", "brittney startzman")
46
+ d1 > d2
47
+ }.should be_true
48
+ @jarow.getDistance( "スパゲティー", "スパゲッティー" ).should be_within(0.0001).of(0.9666)
49
+ @jarow.getDistance( "スパゲティー", "スパゲティ" ).should be_within(0.0001).of(0.9722)
50
+ @jarow.getDistance( "スティービー・ワンダー", "スピーディー・ワンダー" ).should be_within(0.0001).of(0.8561)
51
+ @jarow.getDistance( "マイケル・ジャクソン", "ジャイケル・マクソン" ).should be_within(0.0001).of(0.8000)
52
+ @jarow.getDistance( "まつもとゆきひろ", "まつもとひろゆき" ).should be_within(0.0001).of(0.9500)
53
+ @jarow.getDistance( "クライエント", "クライアント" ).should be_within(0.0001).of(0.9222)
54
+ @jarow.getDistance( "サーバー", "サーバ" ).should be_within(0.0001).of(0.9416)
55
+
56
+ @jarow.pure?( ).should be_true
57
+ end
58
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fuzzy-string-match_pure
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.9.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Kiyoka Nishiyama
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-02-16 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rspec
16
+ requirement: &2156672800 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *2156672800
25
+ description: calculate Jaro Winkler distance.
26
+ email: kiyoka@sumibi.org
27
+ executables: []
28
+ extensions: []
29
+ extra_rdoc_files:
30
+ - LICENSE.txt
31
+ - README.md
32
+ files:
33
+ - .gemtest
34
+ - LICENSE.txt
35
+ - README.md
36
+ - Rakefile
37
+ - VERSION.yml
38
+ - lib/fuzzystringmatch.rb
39
+ - lib/fuzzystringmatch/pure.rb
40
+ - lib/fuzzystringmatch/pure/jarowinkler.rb
41
+ - test/basic_pure_spec.rb
42
+ - test/mutibyte_spec.rb
43
+ homepage: http://github.com/kiyoka/fuzzy-string-match
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ none: false
51
+ requirements:
52
+ - - ! '>='
53
+ - !ruby/object:Gem::Version
54
+ version: 1.9.1
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ! '>='
59
+ - !ruby/object:Gem::Version
60
+ version: '0'
61
+ requirements: []
62
+ rubyforge_project:
63
+ rubygems_version: 1.8.15
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: fuzzy string matching library (Pure ruby version)
67
+ test_files: []