fuzzy-string-match 0.9.6 → 0.9.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b354a1f27f7029336168498837d8437b0affd8bc
4
- data.tar.gz: b925921e5ef9e99fc21e72d256411769406de2ec
3
+ metadata.gz: e6c482cde7e2c3ed8adf5e868574d23505f6c11b
4
+ data.tar.gz: dba293a5c00ba813c05c41e3029b00de4213b917
5
5
  SHA512:
6
- metadata.gz: 4d926213cf459a40ce0f0c2eeaab879f6f962816486719e1a29f6b06ef03c32a5f47e788a4fc0f1f0e2ff6a13e45b090ed1ddface8aa988d04dce7e1a92380cb
7
- data.tar.gz: 593964ef2f4c325214ebc49c1f3db29667dbce5ec50d05dad2071f24e45f65a83cc753720372f3c0c495839bd7c90816daec803cdd2ace062866154f514b8d62
6
+ metadata.gz: 078f094e32f22a4a832cf424d93538613c570bb5bc7151f3689edebc0b7c8c8f4051c2897e2f244d7a0b0e5dbcf018c062dcd65f476d9e231a2311499ed77392
7
+ data.tar.gz: c27ff9107753139c648832c5ec4f06d701d128b7117b0ea1da42e770021a2946d1245e65f96a79ab2e9b7cf672c20a66113e57012a2b80e68e45388402ec70c4
data/README.md CHANGED
@@ -96,6 +96,12 @@
96
96
 
97
97
  ## ChangeLog
98
98
 
99
+ ### 0.9.7 / Oct 15, 2014
100
+
101
+ * Use rspec 3.1 syntax.
102
+ * Fixed: issue #12 `Using stack allocated memory`.
103
+ * Fixed: remove duplicated dependency of gem package.
104
+
99
105
  ### 0.9.6 / Dec 21, 2013
100
106
 
101
107
  * New feature: fuzzy-string-match falls back into pure ruby mode when c-compile fails.
data/Rakefile CHANGED
@@ -1,51 +1,19 @@
1
1
  #-*- mode: ruby; -*-
2
2
  #
3
3
  # Release Engineering
4
- # 1. edit the VERSION.yml file
5
- # 2. rake test
6
- # 3. rake gemspec && gem build fuzzy-string-match.gemspec
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 )
4
+ # 1. edit the "s.version = " line of fuzzy-string-match.gemspec
5
+ # 2. rake && rake build
6
+ # to generate pkg/fuzzy-string-match-x.x.x.gem
7
+ # 3. install fuzzy-string-match-x.x.x.gem to clean environment and test
8
+ # 4. rake release
9
+ # 5. 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
10
  #
12
11
  # for Development
13
12
  # rake test_dev
14
13
  # rake benchmark
15
14
 
16
15
  require 'rake'
17
- begin
18
- require 'jeweler2'
19
-
20
- Jeweler::Tasks.new do |gemspec|
21
- gemspec.name = "fuzzy-string-match"
22
- gemspec.summary = "fuzzy string matching library"
23
- gemspec.description = "calculate Jaro Winkler distance."
24
- gemspec.email = "kiyoka@sumibi.org"
25
- gemspec.license = 'Apache-2.0'
26
- gemspec.homepage = "http://github.com/kiyoka/fuzzy-string-match"
27
- gemspec.authors = ["Kiyoka Nishiyama"]
28
- gemspec.files = FileList['.gemtest',
29
- 'Rakefile',
30
- 'VERSION.yml',
31
- 'lib/fuzzystringmatch/inline/jarowinkler.rb',
32
- 'lib/fuzzystringmatch/inline.rb',
33
- 'lib/fuzzystringmatch/pure/jarowinkler.rb',
34
- 'lib/fuzzystringmatch/pure.rb',
35
- 'lib/fuzzystringmatch.rb',
36
- 'test/basic_native_spec.rb',
37
- 'test/basic_pure_spec.rb',
38
- 'test/mutibyte_spec.rb',
39
- 'LICENSE.txt',
40
- 'README.md'].to_a
41
- gemspec.add_development_dependency( "rspec" )
42
- gemspec.add_dependency( 'RubyInline', '>= 3.8.6')
43
- gemspec.required_ruby_version = '>= 1.9.1'
44
- end
45
-
46
- rescue LoadError
47
- puts "Jeweler not available. Install it with: sudo gem install jeweler"
48
- end
16
+ require 'bundler/gem_tasks'
49
17
 
50
18
  task :default => [:test] do
51
19
  end
@@ -22,8 +22,17 @@ module FuzzyStringMatch
22
22
  false
23
23
  end
24
24
 
25
+ def getDistance(s1,s2)
26
+ result = getDistanceInternal(s1,s2)
27
+ if result.nan?
28
+ raise NoMemoryError.new( "failed to allocate memory. string argument s1 or s2 is too large." )
29
+ end
30
+ return result
31
+ end
32
+
25
33
  inline do |builder|
26
34
  builder.include '<iostream>'
35
+ builder.include '<math.h>'
27
36
  builder.add_compile_flags %q(-x c++)
28
37
  builder.add_link_flags %q(-lstdc++)
29
38
  builder.c_raw 'int max( int a, int b ) { return ((a)>(b)?(a):(b)); }'
@@ -32,7 +41,7 @@ module FuzzyStringMatch
32
41
  builder.c '
33
42
 
34
43
 
35
- double getDistance( char *s1, char *s2 )
44
+ double getDistanceInternal( char *s1, char *s2 )
36
45
  {
37
46
  char *_max;
38
47
  char *_min;
@@ -48,12 +57,22 @@ double getDistance( char *s1, char *s2 )
48
57
  }
49
58
  int range = max( _max_length / 2 - 1, 0 );
50
59
 
51
- int indexes[_min_length];
60
+ int *indexes = NULL;
61
+ indexes = (int *)malloc(_min_length * sizeof(int));
62
+ if( NULL == indexes ) {
63
+ return nanl("");
64
+ }
65
+
66
+ int *flags = NULL;
67
+ flags = (int *)malloc(_max_length * sizeof(int));
68
+ if( NULL == flags ) {
69
+ free(indexes);
70
+ return nanl("");
71
+ }
72
+
52
73
  for( int i = 0 ; i < _min_length ; i++ ) {
53
74
  indexes[i] = -1;
54
75
  }
55
-
56
- int flags[_max_length];
57
76
  for( int i = 0 ; i < _max_length ; i++ ) {
58
77
  flags[i] = 0;
59
78
  }
@@ -70,8 +89,22 @@ double getDistance( char *s1, char *s2 )
70
89
  }
71
90
  }
72
91
 
73
- char ms1[matches];
74
- char ms2[matches];
92
+ char *ms1 = NULL;
93
+ ms1 = (char *)malloc(matches * sizeof(char));
94
+ if( NULL == ms1 ) {
95
+ free(indexes);
96
+ free(flags);
97
+ return nanl("");
98
+ }
99
+ char *ms2 = NULL;
100
+ ms2 = (char *)malloc(matches * sizeof(char));
101
+ if( NULL == ms2 ) {
102
+ free(indexes);
103
+ free(flags);
104
+ free(ms1);
105
+ return nanl("");
106
+ }
107
+
75
108
  int ms1_length = matches;
76
109
 
77
110
  for (int i = 0, si = 0; i < _min_length; i++) {
@@ -103,12 +136,21 @@ double getDistance( char *s1, char *s2 )
103
136
 
104
137
  double m = (double) matches;
105
138
  if (matches == 0) {
139
+ free(indexes);
140
+ free(flags);
141
+ free(ms1);
142
+ free(ms2);
106
143
  return 0.0;
107
144
  }
108
145
  int t = transpositions / 2;
109
146
  double j = ((m / strlen(s1) + m / strlen(s2) + (m - t) / m)) / 3;
110
147
  double jw = j < 0.7 ? j : j + double_min(0.1, 1.0 / _max_length) * prefix
111
148
  * (1 - j);
149
+
150
+ free(indexes);
151
+ free(flags);
152
+ free(ms1);
153
+ free(ms2);
112
154
  return jw;
113
155
  }'
114
156
  end
@@ -28,31 +28,22 @@ describe FuzzyStringMatch, "when some string distances (Native) are" do
28
28
  @jarow = FuzzyStringMatch::JaroWinkler.create( :native )
29
29
  end
30
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 == (RUBY_PLATFORM == "java")
31
+ expect( @jarow.getDistance( "henka", "henkan" )).to be_within(0.0001).of(0.9722)
32
+ expect( @jarow.getDistance( "al", "al" )).to be_within(0.0001).of(1.0)
33
+ expect( @jarow.getDistance( "martha", "marhta" )).to be_within(0.0001).of(0.9611)
34
+ expect( @jarow.getDistance( "jones", "johnson" )).to be_within(0.0001).of(0.8323)
35
+ expect( @jarow.getDistance( "abcvwxyz", "cabvwxyz" )).to be_within(0.0001).of(0.9583)
36
+ expect( @jarow.getDistance( "dwayne", "duane" )).to be_within(0.0001).of(0.8400)
37
+ expect( @jarow.getDistance( "dixon", "dicksonx" )).to be_within(0.0001).of(0.8133)
38
+ expect( @jarow.getDistance( "fvie", "ten" )).to be_within(0.0001).of(0.0)
39
+ expect( @jarow.getDistance("zac ephron", "zac efron" )).to be > ( @jarow.getDistance("zac ephron", "kai ephron" ))
40
+ expect( @jarow.getDistance("brittney spears", "britney spears" )).to be > ( @jarow.getDistance("brittney spears", "brittney startzman" ))
41
+ expect( @jarow.pure?( )).to be == (RUBY_PLATFORM == "java")
51
42
  end
52
43
  end
53
44
 
54
45
  describe FuzzyStringMatch, "when older factory method was called, (Native) are" do
55
46
  it "should" do
56
- lambda { FuzzyStringMatch::JaroWinkler.new.create( :native ) }.should raise_error(NoMethodError)
47
+ expect { FuzzyStringMatch::JaroWinkler.new.create( :native ) }.to raise_error(NoMethodError)
57
48
  end
58
49
  end
@@ -28,32 +28,23 @@ describe FuzzyStringMatch, "when some string distances (Pure) are" do
28
28
  @jarow = FuzzyStringMatch::JaroWinkler.create
29
29
  end
30
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
31
+ expect( @jarow.getDistance( "henka", "henkan" )).to be_within(0.0001).of(0.9722)
32
+ expect( @jarow.getDistance( "al", "al" )).to be_within(0.0001).of(1.0)
33
+ expect( @jarow.getDistance( "martha", "marhta" )).to be_within(0.0001).of(0.9611)
34
+ expect( @jarow.getDistance( "jones", "johnson" )).to be_within(0.0001).of(0.8323)
35
+ expect( @jarow.getDistance( "abcvwxyz", "cabvwxyz" )).to be_within(0.0001).of(0.9583)
36
+ expect( @jarow.getDistance( "dwayne", "duane" )).to be_within(0.0001).of(0.8400)
37
+ expect( @jarow.getDistance( "dixon", "dicksonx" )).to be_within(0.0001).of(0.8133)
38
+ expect( @jarow.getDistance( "fvie", "ten" )).to be_within(0.0001).of(0.0)
39
+ expect( @jarow.getDistance("zac ephron", "zac efron" )).to be > ( @jarow.getDistance("zac ephron", "kai ephron" ))
40
+ expect( @jarow.getDistance("brittney spears", "britney spears" )).to be > ( @jarow.getDistance("brittney spears", "brittney startzman" ))
41
+ expect( @jarow.pure?( )).to be true
51
42
  end
52
43
  end
53
44
 
54
45
  describe FuzzyStringMatch, "when older factory method was called, (Native) are" do
55
46
  it "should" do
56
- lambda { FuzzyStringMatch::JaroWinkler.new.create( :pure ) }.should raise_error(NoMethodError)
47
+ expect { FuzzyStringMatch::JaroWinkler.new.create( :pure ) }.to raise_error(NoMethodError)
57
48
  end
58
49
  end
59
50
 
@@ -28,31 +28,22 @@ describe FuzzyStringMatch, "when some UTF8 string distances (Pure) are" do
28
28
  @jarow = FuzzyStringMatch::JaroWinkler.create
29
29
  end
30
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
31
+ expect( @jarow.getDistance( "al", "al" )).to be_within(0.0001).of(1.0)
32
+ expect( @jarow.getDistance( "martha", "marhta" )).to be_within(0.0001).of(0.9611)
33
+ expect( @jarow.getDistance( "jones", "johnson" )).to be_within(0.0001).of(0.8323)
34
+ expect( @jarow.getDistance( "abcvwxyz", "cabvwxyz" )).to be_within(0.0001).of(0.9583)
35
+ expect( @jarow.getDistance( "dwayne", "duane" )).to be_within(0.0001).of(0.8400)
36
+ expect( @jarow.getDistance( "dixon", "dicksonx" )).to be_within(0.0001).of(0.8133)
37
+ expect( @jarow.getDistance( "fvie", "ten" )).to be_within(0.0001).of(0.0)
38
+ expect( @jarow.getDistance("zac ephron", "zac efron")).to be > ( @jarow.getDistance("zac ephron", "kai ephron" ))
39
+ expect( @jarow.getDistance("brittney spears", "britney spears")).to be > ( @jarow.getDistance("brittney spears", "brittney startzman" ))
40
+ expect( @jarow.getDistance( "スパゲティー", "スパゲッティー" )).to be_within(0.0001).of(0.9666)
41
+ expect( @jarow.getDistance( "スパゲティー", "スパゲティ" )).to be_within(0.0001).of(0.9722)
42
+ expect( @jarow.getDistance( "スティービー・ワンダー", "スピーディー・ワンダー" )).to be_within(0.0001).of(0.8561)
43
+ expect( @jarow.getDistance( "マイケル・ジャクソン", "ジャイケル・マクソン" )).to be_within(0.0001).of(0.8000)
44
+ expect( @jarow.getDistance( "まつもとゆきひろ", "まつもとひろゆき" )).to be_within(0.0001).of(0.9500)
45
+ expect( @jarow.getDistance( "クライエント", "クライアント" )).to be_within(0.0001).of(0.9222)
46
+ expect( @jarow.getDistance( "サーバー", "サーバ" )).to be_within(0.0001).of(0.9416)
47
+ expect( @jarow.pure?( )).to be true
57
48
  end
58
49
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fuzzy-string-match
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.9.6
4
+ version: 0.9.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kiyoka Nishiyama
@@ -14,56 +14,28 @@ dependencies:
14
14
  name: rspec
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - '>='
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 3.1.0
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - '>='
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 3.1.0
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: RubyInline
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: 3.8.6
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
39
- - !ruby/object:Gem::Version
40
- version: 3.8.6
41
- - !ruby/object:Gem::Dependency
42
- name: rspec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :development
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: RubyInline
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ">="
60
- - !ruby/object:Gem::Version
61
- version: 3.8.6
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - ">="
38
+ - - '>='
67
39
  - !ruby/object:Gem::Version
68
40
  version: 3.8.6
69
41
  description: calculate Jaro Winkler distance.
@@ -74,11 +46,10 @@ extra_rdoc_files:
74
46
  - LICENSE.txt
75
47
  - README.md
76
48
  files:
77
- - ".gemtest"
49
+ - .gemtest
78
50
  - LICENSE.txt
79
51
  - README.md
80
52
  - Rakefile
81
- - VERSION.yml
82
53
  - lib/fuzzystringmatch.rb
83
54
  - lib/fuzzystringmatch/inline.rb
84
55
  - lib/fuzzystringmatch/inline/jarowinkler.rb
@@ -97,12 +68,12 @@ require_paths:
97
68
  - lib
98
69
  required_ruby_version: !ruby/object:Gem::Requirement
99
70
  requirements:
100
- - - ">="
71
+ - - '>='
101
72
  - !ruby/object:Gem::Version
102
73
  version: 1.9.1
103
74
  required_rubygems_version: !ruby/object:Gem::Requirement
104
75
  requirements:
105
- - - ">="
76
+ - - '>='
106
77
  - !ruby/object:Gem::Version
107
78
  version: '0'
108
79
  requirements: []
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 0
3
- :minor: 9
4
- :patch: 6
5
-