did_you_mean 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +0 -12
- data/.travis.yml +5 -0
- data/CHANGELOG.md +80 -20
- data/Gemfile +1 -1
- data/LICENSE.txt +1 -1
- data/README.md +70 -43
- data/Rakefile +6 -1
- data/benchmark/memory_usage.rb +5 -5
- data/did_you_mean.gemspec +2 -2
- data/evaluation/calculator.rb +18 -19
- data/evaluation/dictionary_generator.rb +4 -3
- data/lib/did_you_mean/extra_features/ivar_name_correction.rb +2 -2
- data/lib/did_you_mean/spell_checkable.rb +3 -2
- data/lib/did_you_mean/spell_checkers/method_name_checker.rb +0 -1
- data/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb +1 -1
- data/lib/did_you_mean/version.rb +1 -1
- data/test/core_ext/name_error_extension_test.rb +9 -7
- data/test/correctable/variable_name_test.rb +6 -2
- data/test/spell_checker_test.rb +6 -1
- data/test/verbose_formatter_test.rb +3 -4
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b69ea3a675f27d9da3419e086c21bd5930f16f90
|
4
|
+
data.tar.gz: 56d723b6a3ab08a92e07412bc0efa2051920626f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1aaf379cad209d36b9df5ed695a42a97bde164cb52619b6c47f1a2c1163ee3ebe1d040c906a46ba89cb3f6e78570f994cf357c08bb87044f7a46aadfbac70810
|
7
|
+
data.tar.gz: 374348aefc081447d3e27f86feb1628ce6914140931e35738e3b230e66e077d245591671dc6c787798c8f4a06edad083051f92e4babfd882e386e051044006d3
|
data/.gitignore
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
.bundle
|
4
4
|
.config
|
5
5
|
.yardoc
|
6
|
-
.DS_Store
|
7
6
|
Gemfile.lock
|
8
|
-
gemfiles/*.lock
|
9
7
|
InstalledFiles
|
10
8
|
_yardoc
|
11
9
|
coverage
|
@@ -13,19 +11,9 @@ doc/
|
|
13
11
|
lib/bundler/man
|
14
12
|
pkg
|
15
13
|
rdoc
|
16
|
-
spec/reports
|
17
14
|
test/tmp
|
18
15
|
test/version_tmp
|
19
16
|
tmp
|
20
17
|
log
|
21
|
-
|
22
18
|
evaluation/dictionary.yml
|
23
19
|
benchmark/results
|
24
|
-
|
25
|
-
ext/**/*.o
|
26
|
-
ext/**/*.so
|
27
|
-
ext/**/Makefile
|
28
|
-
|
29
|
-
lib/**/*.so
|
30
|
-
|
31
|
-
.travis.yml.osx
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
@@ -1,8 +1,65 @@
|
|
1
|
+
## [v1.0.0](https://github.com/yuki24/did_you_mean/tree/v1.0.0)
|
2
|
+
|
3
|
+
_<sup>released on 2015-12-25 05:13:04 UTC</sup>_
|
4
|
+
|
5
|
+
#### Features
|
6
|
+
|
7
|
+
- Introduced a [verbose formatter](https://github.com/yuki24/did_you_mean#verbose-formatter)
|
8
|
+
- Introduced an easy way to enabling [extra features](https://github.com/yuki24/did_you_mean#extra-features)
|
9
|
+
|
10
|
+
#### Bug Fixes
|
11
|
+
|
12
|
+
- Fixed a bug where the Jaro-Winkler implementation returns the wrong distance when 2 identical strings are given
|
13
|
+
|
14
|
+
#### Internal Changes
|
15
|
+
|
16
|
+
- Slightly changed the spell checking algorithm. Take a look at [<tt>e2f5b24</tt>](https://github.com/yuki24/did_you_mean/commit/e2f5b2437f967565e4830eab6077f73ae166e0a7) for more details. fixes [#60](https://github.com/yuki24/did_you_mean/issues/60)
|
17
|
+
|
18
|
+
## [v1.0.0.rc1](https://github.com/yuki24/did_you_mean/tree/v1.0.0.rc1)
|
19
|
+
|
20
|
+
_<sup>released on 2015-12-25 05:02:25 UTC</sup>_
|
21
|
+
|
22
|
+
#### Internal Chagens
|
23
|
+
|
24
|
+
- No longer uses `TracePoint` API by default. fixes [#55](https://github.com/yuki24/did_you_mean/issues/55) and [#56](https://github.com/yuki24/did_you_mean/issues/56)
|
25
|
+
|
26
|
+
## [v1.0.0.beta3](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta3)
|
27
|
+
|
28
|
+
_<sup>released on 2015-12-25 04:56:13 UTC</sup>_
|
29
|
+
|
30
|
+
#### Internal Changes
|
31
|
+
|
32
|
+
- Enable the `frozen-string-literal` pragma rather than calling `.freeze` everywhere
|
33
|
+
- Use the `NameError#receiver` method in `DidYouMean:: ClassNameChecker` to know the namespace where the constant call is made
|
34
|
+
- Refactored the `SpellCheckerTest`
|
35
|
+
|
36
|
+
## [v1.0.0.beta2](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta2)
|
37
|
+
|
38
|
+
_<sup>released on 2015-12-25 04:50:36 UTC</sup>_
|
39
|
+
|
40
|
+
#### Bug Fixes
|
41
|
+
|
42
|
+
- Fixed a bug where the gem doesn't install properly on Ruby 2.3.0dev
|
43
|
+
|
44
|
+
## [v1.0.0.beta1](https://github.com/yuki24/did_you_mean/tree/v1.0.0.beta1)
|
45
|
+
|
46
|
+
_<sup>released on 2015-12-25 05:27:53 UTC</sup>_
|
47
|
+
|
48
|
+
#### Breaking Changes
|
49
|
+
|
50
|
+
- Dropped support for MRIs older than 2.3, JRuby and Rubinus
|
51
|
+
|
52
|
+
#### Internal Changes
|
53
|
+
|
54
|
+
- The C extension has been removed since the `NameError#receiver` method has become part of the MRI 2.3
|
55
|
+
- The interception gem has been removed from the dependencies
|
56
|
+
- Removed code that was needed to support multiple Ruby implementations
|
57
|
+
|
1
58
|
## [v0.10.0](https://github.com/yuki24/did_you_mean/tree/v0.10.0)
|
2
59
|
|
3
60
|
_<sup>released on 2015-08-21 06:44:11 UTC</sup>_
|
4
61
|
|
5
|
-
####
|
62
|
+
#### Features
|
6
63
|
|
7
64
|
- Now it corrects an instance variable name if the ivar name is mistyped and `NoMethodError` is raised:
|
8
65
|
|
@@ -35,9 +92,12 @@ _<sup>released on 2015-05-14 03:04:47 UTC</sup>_
|
|
35
92
|
|
36
93
|
_<sup>released on 2015-05-13 03:48:19 UTC</sup>_
|
37
94
|
|
38
|
-
####
|
95
|
+
#### Features
|
96
|
+
|
97
|
+
- Order word suggestions based on Levenshtein distance ( [@tleish](https://github.com/tleish), [#31](https://github.com/yuki24/did_you_mean/pull/31))
|
98
|
+
|
99
|
+
#### Internal Changes
|
39
100
|
|
40
|
-
- Order word corrections based on Levenshtein distance ( [@tleish](https://github.com/tleish), [#31](https://github.com/yuki24/did_you_mean/pull/31 "Order word corrections based on Levenshtein.distance."))
|
41
101
|
- Reduce memory allocation by about 40%
|
42
102
|
- Speed up Levenshtein distance calculation by about 40%
|
43
103
|
- The Java extension has been replaced with a pure JRuby implementation
|
@@ -80,7 +140,7 @@ _<sup>released on 2014-11-19 20:00:00 UTC</sup>_
|
|
80
140
|
|
81
141
|
#### Bug Fixes
|
82
142
|
|
83
|
-
- Fixed a bug where no
|
143
|
+
- Fixed a bug where no suggestions will be made on JRuby
|
84
144
|
|
85
145
|
## [v0.9.3](https://github.com/yuki24/did_you_mean/tree/v0.9.3)
|
86
146
|
|
@@ -115,7 +175,7 @@ _<sup>released on 2014-11-16 18:54:24 UTC</sup>_
|
|
115
175
|
|
116
176
|
_<sup>released on 2014-11-09 01:26:31 UTC</sup>_
|
117
177
|
|
118
|
-
####
|
178
|
+
#### Features
|
119
179
|
|
120
180
|
- did\_you\_mean now suggests instance variable names if `@` is missing ( [#12](https://github.com/yuki24/did_you_mean/issues/12 "Suggest instance- and class-vars"), [<tt>39d1e2b</tt>](https://github.com/yuki24/did_you_mean/commit/39d1e2bd66d6ff8acbc4dd5da922fc7e5fcefb20))
|
121
181
|
|
@@ -139,7 +199,7 @@ _<sup>released on 2014-10-27 02:03:13 UTC</sup>_
|
|
139
199
|
|
140
200
|
**This version has been yanked from rubygems.org as it has a serious bug with Ruby 2.1.3 and 2.1.4 installed on Max OS X. Please upgrade to 0.9.4 or higher as soon as possible.**
|
141
201
|
|
142
|
-
####
|
202
|
+
#### Features
|
143
203
|
|
144
204
|
- JRuby support!
|
145
205
|
|
@@ -155,7 +215,7 @@ _<sup>released on 2014-09-26 03:37:18 UTC</sup>_
|
|
155
215
|
|
156
216
|
**This version has been yanked from rubygems.org as it has a serious bug with Ruby 2.1.3 and 2.1.4 installed on Max OS X. Please upgrade to 0.9.4 or higher as soon as possible.**
|
157
217
|
|
158
|
-
####
|
218
|
+
#### Features
|
159
219
|
|
160
220
|
- Added support for Ruby 2.1.3, 2.2.0-preview1 and ruby-head
|
161
221
|
- Added support for ActiveRecord 4.2.0.beta1
|
@@ -163,7 +223,7 @@ _<sup>released on 2014-09-26 03:37:18 UTC</sup>_
|
|
163
223
|
- Removed `text` gem dependency
|
164
224
|
- Better output on pry and Rspec
|
165
225
|
|
166
|
-
####
|
226
|
+
#### Internal Changes
|
167
227
|
|
168
228
|
- A lot of internal refactoring
|
169
229
|
|
@@ -171,11 +231,11 @@ _<sup>released on 2014-09-26 03:37:18 UTC</sup>_
|
|
171
231
|
|
172
232
|
_<sup>released on 2014-05-18 00:23:24 UTC</sup>_
|
173
233
|
|
174
|
-
**This version has been yanked from rubygems.org as it has a serious bug with Ruby 2.1.3 and 2.1.4 installed on Max OS X. Please upgrade to 0.9.
|
234
|
+
**This version has been yanked from rubygems.org as it has a serious bug with Ruby 2.1.3 and 2.1.4 installed on Max OS X. Please upgrade to 0.9.4 or higher as soon as possible.**
|
175
235
|
|
176
|
-
####
|
236
|
+
#### Features
|
177
237
|
|
178
|
-
- Added basic support for constants. Now you'll see class name
|
238
|
+
- Added basic support for constants. Now you'll see class name suggestions when you misspelled a class names/module names:
|
179
239
|
|
180
240
|
```ruby
|
181
241
|
> Ocject
|
@@ -193,7 +253,7 @@ _<sup>released on 2014-05-18 00:23:24 UTC</sup>_
|
|
193
253
|
|
194
254
|
_<sup>released on 2014-05-10 17:59:54 UTC</sup>_
|
195
255
|
|
196
|
-
####
|
256
|
+
#### Features
|
197
257
|
|
198
258
|
- Added support for Ruby 2.1.2
|
199
259
|
|
@@ -201,7 +261,7 @@ _<sup>released on 2014-05-10 17:59:54 UTC</sup>_
|
|
201
261
|
|
202
262
|
_<sup>released on 2014-04-20 02:10:31 UTC</sup>_
|
203
263
|
|
204
|
-
####
|
264
|
+
#### Features
|
205
265
|
|
206
266
|
- did\_you\_mean now suggests a similar attribute name when you misspelled it.
|
207
267
|
|
@@ -221,16 +281,16 @@ User.new(flrst_name: "wrong flrst name")
|
|
221
281
|
|
222
282
|
_<sup>released on 2014-03-20 23:16:20 UTC</sup>_
|
223
283
|
|
224
|
-
####
|
284
|
+
#### Features
|
225
285
|
|
226
286
|
- Changed output for readability.
|
227
|
-
-
|
287
|
+
- Made the spell checking algorithm slight better to find the correct method.
|
228
288
|
|
229
289
|
## [v0.3.0](https://github.com/yuki24/did_you_mean/tree/v0.3.0)
|
230
290
|
|
231
291
|
_<sup>released on 2014-03-20 23:13:13 UTC</sup>_
|
232
292
|
|
233
|
-
####
|
293
|
+
#### Features
|
234
294
|
|
235
295
|
- Added support for Ruby 2.1.1 and 2.2.0(head).
|
236
296
|
|
@@ -238,13 +298,13 @@ _<sup>released on 2014-03-20 23:13:13 UTC</sup>_
|
|
238
298
|
|
239
299
|
_<sup>released on 2014-03-20 23:12:13 UTC</sup>_
|
240
300
|
|
241
|
-
####
|
301
|
+
#### Features
|
242
302
|
|
243
|
-
-
|
303
|
+
- did\_you\_mean no longer makes Ruby slow.
|
244
304
|
|
245
|
-
####
|
305
|
+
#### Breaking Changes
|
246
306
|
|
247
|
-
-
|
307
|
+
- dropped support for JRuby and Rubbinious.
|
248
308
|
|
249
309
|
## [v0.1.0: First Release](https://github.com/yuki24/did_you_mean/tree/v0.1.0)
|
250
310
|
|
data/Gemfile
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,10 +1,8 @@
|
|
1
1
|
# did_you_mean [![Gem Version](https://badge.fury.io/rb/did_you_mean.svg)](https://rubygems.org/gems/did_you_mean) [![Build Status](https://travis-ci.org/yuki24/did_you_mean.svg?branch=master)](https://travis-ci.org/yuki24/did_you_mean)
|
2
2
|
|
3
|
-
'Did you mean?' experience in Ruby. No, Really.
|
4
|
-
|
5
3
|
## Installation
|
6
4
|
|
7
|
-
|
5
|
+
Ruby 2.3 ships with this gem and it will automatically be `require`d when a Ruby process starts up. No special setup is required.
|
8
6
|
|
9
7
|
## Examples
|
10
8
|
|
@@ -13,73 +11,102 @@ This gem will automatically be activated when a Ruby process starts up. No speci
|
|
13
11
|
#### Correcting a Misspelled Method Name
|
14
12
|
|
15
13
|
```ruby
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
"#{f1rst_name} #{last_name}" # f1rst_name ???
|
21
|
-
end
|
22
|
-
end
|
23
|
-
|
24
|
-
user.to_s
|
25
|
-
# => NameError: undefined local variable or method `f1rst_name' for #<User:0x0000000928fad8>
|
26
|
-
#
|
27
|
-
# Did you mean? #first_name
|
28
|
-
#
|
14
|
+
methosd
|
15
|
+
# => NameError: undefined local variable or method `methosd' for main:Object
|
16
|
+
# Did you mean? methods
|
17
|
+
# method
|
29
18
|
```
|
30
19
|
|
31
20
|
#### Correcting a Misspelled Class Name
|
32
21
|
|
33
22
|
```ruby
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
38
|
-
end
|
39
|
-
|
40
|
-
Book::TableofContents # TableofContents ???
|
41
|
-
# => NameError: uninitialized constant Book::TableofContents
|
42
|
-
#
|
43
|
-
# Did you mean? Book::TableOfContents
|
44
|
-
#
|
23
|
+
OBject
|
24
|
+
# => NameError: uninitialized constant OBject
|
25
|
+
# Did you mean? Object
|
45
26
|
```
|
46
27
|
|
47
|
-
#### Suggesting an
|
28
|
+
#### Suggesting an Instance Variable Name
|
48
29
|
|
49
30
|
```ruby
|
50
31
|
@full_name = "Yuki Nishijima"
|
51
32
|
first_name, last_name = full_name.split(" ")
|
52
33
|
# => NameError: undefined local variable or method `full_name' for main:Object
|
53
|
-
#
|
54
|
-
|
55
|
-
|
34
|
+
# Did you mean? @full_name
|
35
|
+
```
|
36
|
+
|
37
|
+
#### Correcting a Class Variable Name
|
38
|
+
|
39
|
+
```ruby
|
40
|
+
@@full_name = "Yuki Nishijima"
|
41
|
+
@@full_anme
|
42
|
+
# => NameError: uninitialized class variable @@full_anme in Object
|
43
|
+
# Did you mean? @@full_name
|
56
44
|
```
|
57
45
|
|
58
46
|
### NoMethodError
|
59
47
|
|
60
48
|
```ruby
|
61
|
-
|
62
|
-
|
63
|
-
# => NoMethodError: undefined method `
|
64
|
-
#
|
65
|
-
# Did you mean? #with_indifferent_access
|
66
|
-
#
|
49
|
+
full_name = "Yuki Nishijima"
|
50
|
+
full_name.starts_with?("Y")
|
51
|
+
# => NoMethodError: undefined method `starts_with?' for "Yuki Nishijima":String
|
52
|
+
# Did you mean? start_with?
|
67
53
|
```
|
68
54
|
|
69
|
-
##
|
55
|
+
## Extra Features
|
70
56
|
|
71
|
-
|
57
|
+
Aside from the basic features above, the `did_you_mean` gem comes with 2 extra features. They can be enabled by calling `require 'did_you_mean/extra_features'`.
|
72
58
|
|
73
|
-
|
59
|
+
**Keep in mind that these extra features should never be enabled in production as they impact Ruby's performance and uses an unstable Ruby API.**
|
60
|
+
|
61
|
+
### Correcting an Instance Variable When It's Incorrectly Typed
|
62
|
+
|
63
|
+
```ruby
|
64
|
+
require 'did_you_mean/extra_features'
|
65
|
+
|
66
|
+
@full_name = "Yuki Nishijima"
|
67
|
+
@full_anme.split(" ")
|
68
|
+
# => NoMethodError: undefined method `split' for nil:NilClass
|
69
|
+
# Did you mean? @full_name
|
70
|
+
```
|
71
|
+
|
72
|
+
### Displaying a Warning When `initialize` is Incorrectly Typed
|
73
|
+
```ruby
|
74
|
+
require 'did_you_mean/extra_features'
|
75
|
+
|
76
|
+
class Person
|
77
|
+
def intialize
|
78
|
+
...
|
79
|
+
end
|
80
|
+
end
|
81
|
+
# => warning: intialize might be misspelled, perhaps you meant initialize?
|
82
|
+
```
|
83
|
+
|
84
|
+
## Verbose Formatter
|
85
|
+
|
86
|
+
This verbose formatter changes the error message format to take more lines/spaces so it'll be slightly easier to read the suggestions. This formatter can totally be used in any environment including production.
|
87
|
+
|
88
|
+
```ruby
|
89
|
+
OBject
|
90
|
+
# => NameError: uninitialized constant OBject
|
91
|
+
# Did you mean? Object
|
92
|
+
|
93
|
+
require 'did_you_mean/verbose_formatter'
|
94
|
+
OBject
|
95
|
+
# => NameError: uninitialized constant OBject
|
96
|
+
#
|
97
|
+
# Did you mean? Object
|
98
|
+
#
|
99
|
+
```
|
74
100
|
|
75
101
|
## Contributing
|
76
102
|
|
77
103
|
1. Fork it (http://github.com/yuki24/did_you_mean/fork)
|
78
104
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
79
105
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
80
|
-
4.
|
81
|
-
5.
|
106
|
+
4. Make sure all tests pass (`bundle exec rake`)
|
107
|
+
5. Push to the branch (`git push origin my-new-feature`)
|
108
|
+
6. Create new Pull Request
|
82
109
|
|
83
110
|
## License
|
84
111
|
|
85
|
-
Copyright (c)
|
112
|
+
Copyright (c) 2014-16 Yuki Nishijima. See MIT-LICENSE for further details.
|
data/Rakefile
CHANGED
@@ -28,7 +28,12 @@ Rake::TestTask.new("test:extra_features") do |task|
|
|
28
28
|
task.ruby_opts << "-rdid_you_mean/extra_features"
|
29
29
|
end
|
30
30
|
|
31
|
-
|
31
|
+
if RUBY_ENGINE != 'jruby'
|
32
|
+
task default: %i(test test:verbose_formatter test:extra_features)
|
33
|
+
else
|
34
|
+
task default: %i(test test:verbose_formatter)
|
35
|
+
end
|
36
|
+
|
32
37
|
|
33
38
|
namespace :test do
|
34
39
|
namespace :accuracy do
|
data/benchmark/memory_usage.rb
CHANGED
@@ -7,14 +7,14 @@ require 'did_you_mean'
|
|
7
7
|
# error = (self.fooo rescue $!)
|
8
8
|
# executable = -> { error.to_s }
|
9
9
|
|
10
|
-
class
|
10
|
+
class SpellChecker
|
11
11
|
include DidYouMean::SpellCheckable
|
12
12
|
|
13
13
|
def initialize(words)
|
14
14
|
@words = words
|
15
15
|
end
|
16
16
|
|
17
|
-
def
|
17
|
+
def correct(input)
|
18
18
|
@corrections, @input = nil, input
|
19
19
|
corrections
|
20
20
|
end
|
@@ -22,12 +22,12 @@ class DidYouMean::WordCollection
|
|
22
22
|
def candidates
|
23
23
|
{ @input => @words }
|
24
24
|
end
|
25
|
-
end
|
25
|
+
end
|
26
26
|
|
27
27
|
METHODS = ''.methods
|
28
28
|
INPUT = 'start_with?'
|
29
|
-
collection =
|
30
|
-
executable = proc { collection.
|
29
|
+
collection = SpellChecker.new(METHODS)
|
30
|
+
executable = proc { collection.correct(INPUT) }
|
31
31
|
|
32
32
|
GC.disable
|
33
33
|
MemoryProfiler.report { 100.times(&executable) }.pretty_print
|
data/did_you_mean.gemspec
CHANGED
@@ -18,9 +18,9 @@ Gem::Specification.new do |spec|
|
|
18
18
|
spec.test_files = spec.files.grep(%r{^(test)/})
|
19
19
|
spec.require_paths = ["lib"]
|
20
20
|
|
21
|
-
spec.required_ruby_version = '>= 2.3.
|
21
|
+
spec.required_ruby_version = '>= 2.3.0'
|
22
22
|
|
23
|
-
spec.add_development_dependency "bundler", "~> 1.
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.10"
|
24
24
|
spec.add_development_dependency "rake"
|
25
25
|
spec.add_development_dependency "minitest"
|
26
26
|
end
|
data/evaluation/calculator.rb
CHANGED
@@ -26,7 +26,6 @@ puts "\n"
|
|
26
26
|
report "loading program" do
|
27
27
|
require 'yaml'
|
28
28
|
require 'set'
|
29
|
-
require 'did_you_mean'
|
30
29
|
|
31
30
|
begin
|
32
31
|
require 'jaro_winkler'
|
@@ -39,14 +38,14 @@ report "loading program" do
|
|
39
38
|
rescue LoadError, NameError
|
40
39
|
end
|
41
40
|
|
42
|
-
class
|
41
|
+
class SpellChecker
|
43
42
|
include DidYouMean::SpellCheckable
|
44
43
|
|
45
44
|
def initialize(words)
|
46
45
|
@words = words
|
47
46
|
end
|
48
47
|
|
49
|
-
def
|
48
|
+
def correct(input)
|
50
49
|
@corrections, @input = nil, input
|
51
50
|
corrections
|
52
51
|
end
|
@@ -55,9 +54,8 @@ report "loading program" do
|
|
55
54
|
{ @input => @words }
|
56
55
|
end
|
57
56
|
|
58
|
-
private
|
59
|
-
|
60
|
-
end if !defined?(DidYouMean::WordCollection)
|
57
|
+
private def normalize(str); str; end
|
58
|
+
end
|
61
59
|
end
|
62
60
|
|
63
61
|
report "loading dictionary" do
|
@@ -68,7 +66,7 @@ report "loading dictionary" do
|
|
68
66
|
end
|
69
67
|
|
70
68
|
report "loading corrent/incorrect words" do
|
71
|
-
|
69
|
+
SPELL_CHECKER = SpellChecker.new(DICTIONARY)
|
72
70
|
INCORRECT_WORDS = YAML.load(open("evaluation/incorrect_words.yaml").read)
|
73
71
|
end
|
74
72
|
|
@@ -77,44 +75,45 @@ correct_count = 0
|
|
77
75
|
words_not_corrected = []
|
78
76
|
filename = "log/words_not_corrected_#{Time.now.to_i}.yml"
|
79
77
|
|
80
|
-
puts
|
78
|
+
puts <<-MSG
|
79
|
+
|
81
80
|
Total number of test data: #{INCORRECT_WORDS.size}
|
82
81
|
did_you_mean version: #{DidYouMean::VERSION}
|
83
82
|
|
84
|
-
|
83
|
+
MSG
|
85
84
|
|
86
85
|
report "calculating accuracy" do
|
87
|
-
|
88
|
-
|
89
|
-
if DICTIONARY.include?(correct)
|
86
|
+
INCORRECT_WORDS.each_with_index do |(expected, user_input), index|
|
87
|
+
if DICTIONARY.include?(expected)
|
90
88
|
total_count += 1
|
91
89
|
|
92
|
-
corrections =
|
93
|
-
if corrections.first ==
|
90
|
+
corrections = SPELL_CHECKER.correct(user_input)
|
91
|
+
if corrections.first == expected
|
94
92
|
correct_count += 1
|
95
93
|
else
|
96
94
|
words_not_corrected << {
|
97
|
-
|
98
|
-
'
|
95
|
+
'input' => user_input,
|
96
|
+
'expected' => expected,
|
97
|
+
'actual' => corrections
|
99
98
|
}
|
100
99
|
end
|
101
100
|
end
|
102
101
|
|
103
|
-
index += 1
|
104
102
|
puts "processed #{index} items" if index % 100 == 0
|
105
103
|
end
|
106
104
|
|
107
105
|
puts "\n"
|
108
106
|
end
|
109
107
|
|
110
|
-
puts
|
108
|
+
puts <<-MSG
|
109
|
+
|
111
110
|
Evaulation result
|
112
111
|
|
113
112
|
Total count : #{total_count}
|
114
113
|
Correct count: #{correct_count}
|
115
114
|
Accuracy : #{correct_count.to_f / total_count}
|
116
115
|
|
117
|
-
|
116
|
+
MSG
|
118
117
|
|
119
118
|
Dir.mkdir('log') unless File.exist?('log')
|
120
119
|
File.open(filename, 'w') do |file|
|
@@ -5,12 +5,11 @@ require 'json'
|
|
5
5
|
per_page = 500
|
6
6
|
base_url = "https://simple.wiktionary.org/w/api.php?action=query&aplimit=#{per_page}&list=allpages&format=json"
|
7
7
|
filename = "evaluation/dictionary.yml"
|
8
|
-
count = nil
|
9
8
|
apfrom = ""
|
10
9
|
num = 0
|
11
10
|
titles = []
|
12
11
|
|
13
|
-
|
12
|
+
loop do
|
14
13
|
url = base_url + "&apfrom=#{apfrom}"
|
15
14
|
|
16
15
|
puts "downloading page %2d: #{url}" % num
|
@@ -22,7 +21,9 @@ begin
|
|
22
21
|
|
23
22
|
titles += json["query"]["allpages"].map {|hash| hash["title"] }
|
24
23
|
num += 1
|
25
|
-
|
24
|
+
|
25
|
+
break if count != per_page
|
26
|
+
end
|
26
27
|
|
27
28
|
require 'yaml'
|
28
29
|
|
@@ -1,6 +1,6 @@
|
|
1
1
|
module DidYouMean
|
2
2
|
module ExtraFeatures
|
3
|
-
module
|
3
|
+
module IvarNameCorrection
|
4
4
|
REPLS = {
|
5
5
|
"(irb)" => -> { Readline::HISTORY.to_a.last }
|
6
6
|
}
|
@@ -38,6 +38,6 @@ module DidYouMean
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
SPELL_CHECKERS['NoMethodError'].prepend(
|
41
|
+
SPELL_CHECKERS['NoMethodError'].prepend(IvarNameCorrection)
|
42
42
|
end
|
43
43
|
end
|
@@ -11,8 +11,9 @@ module DidYouMean
|
|
11
11
|
threshold = input.length > 3 ? 0.834 : 0.77
|
12
12
|
|
13
13
|
seed = candidates.select {|candidate| JaroWinkler.distance(normalize(candidate), input) >= threshold }
|
14
|
-
|
15
|
-
|
14
|
+
seed.reject! {|candidate| input == candidate.to_s }
|
15
|
+
seed.sort_by! {|candidate| JaroWinkler.distance(candidate.to_s, input) }
|
16
|
+
seed.reverse!
|
16
17
|
|
17
18
|
# Correct mistypes
|
18
19
|
threshold = (input.length * 0.25).ceil
|
@@ -7,7 +7,7 @@ module DidYouMean
|
|
7
7
|
|
8
8
|
def initialize(exception)
|
9
9
|
@name = exception.name.to_s.tr("@", "")
|
10
|
-
@lvar_names = exception.local_variables
|
10
|
+
@lvar_names = RUBY_ENGINE == 'jruby' ? [] : exception.local_variables
|
11
11
|
receiver = exception.receiver
|
12
12
|
|
13
13
|
@method_names = receiver.methods + receiver.private_methods
|
data/lib/did_you_mean/version.rb
CHANGED
@@ -5,7 +5,7 @@ class NameErrorExtensionTest < Minitest::Test
|
|
5
5
|
|
6
6
|
class TestSpellChecker
|
7
7
|
def initialize(*); end
|
8
|
-
def corrections; ["
|
8
|
+
def corrections; ["does_exist"]; end
|
9
9
|
end
|
10
10
|
|
11
11
|
def setup
|
@@ -18,13 +18,14 @@ class NameErrorExtensionTest < Minitest::Test
|
|
18
18
|
SPELL_CHECKERS['NameError'] = @org
|
19
19
|
end
|
20
20
|
|
21
|
-
def test_message_provides_original_message
|
22
|
-
assert_match "undefined local variable or method", @error.to_s
|
23
|
-
end
|
24
|
-
|
25
21
|
def test_message
|
26
|
-
|
27
|
-
|
22
|
+
message = <<~MESSAGE.chomp
|
23
|
+
undefined local variable or method `doesnt_exist' for #{method(:to_s).super_method.call}
|
24
|
+
Did you mean? does_exist
|
25
|
+
MESSAGE
|
26
|
+
|
27
|
+
assert_equal message, @error.to_s
|
28
|
+
assert_equal message, @error.message
|
28
29
|
end
|
29
30
|
|
30
31
|
def test_to_s_does_not_make_disruptive_changes_to_error_message
|
@@ -32,6 +33,7 @@ class NameErrorExtensionTest < Minitest::Test
|
|
32
33
|
raise NameError, "uninitialized constant Object"
|
33
34
|
end
|
34
35
|
|
36
|
+
error.to_s
|
35
37
|
assert_equal 1, error.to_s.scan("Did you mean?").count
|
36
38
|
end
|
37
39
|
end
|
@@ -53,8 +53,12 @@ class VariableNameTest < Minitest::Test
|
|
53
53
|
person = person = nil
|
54
54
|
error = (eprson rescue $!) # Do not use @assert_raises here as it changes a scope.
|
55
55
|
|
56
|
-
|
57
|
-
|
56
|
+
if RUBY_ENGINE != 'jruby'
|
57
|
+
assert_correction :person, error.corrections
|
58
|
+
assert_match "Did you mean? person", error.to_s
|
59
|
+
else
|
60
|
+
assert_empty error.corrections
|
61
|
+
end
|
58
62
|
end
|
59
63
|
|
60
64
|
def test_corrections_include_instance_variable_name
|
data/test/spell_checker_test.rb
CHANGED
@@ -55,7 +55,6 @@ class SpellCheckerTest < Minitest::Test
|
|
55
55
|
|
56
56
|
def test_spell_checker_sorts_results_by_simiarity
|
57
57
|
expected = %w(
|
58
|
-
name123456
|
59
58
|
name12345
|
60
59
|
name1234
|
61
60
|
name123
|
@@ -72,6 +71,12 @@ class SpellCheckerTest < Minitest::Test
|
|
72
71
|
assert_equal expected, actual
|
73
72
|
end
|
74
73
|
|
74
|
+
def test_spell_checker_excludes_input_from_dictionary
|
75
|
+
assert_empty SpellChecker.new('input', ['input']).corrections
|
76
|
+
assert_empty SpellChecker.new('input', [:input]).corrections
|
77
|
+
assert_empty SpellChecker.new(:input, ['input']).corrections
|
78
|
+
end
|
79
|
+
|
75
80
|
private
|
76
81
|
|
77
82
|
def assert_spell(expected, input: , dictionary: )
|
@@ -2,15 +2,14 @@ require 'test_helper'
|
|
2
2
|
|
3
3
|
class VerboseFormatterTest < Minitest::Test
|
4
4
|
def setup
|
5
|
-
|
6
|
-
@error = assert_raises(NameError){ doesnt_exist }
|
5
|
+
@error = assert_raises(NameError){ self.inspectt }
|
7
6
|
end
|
8
7
|
|
9
8
|
def test_message
|
10
9
|
assert_equal <<~MESSAGE.chomp, @error.message
|
11
|
-
undefined
|
10
|
+
undefined method `inspectt' for #{method(:to_s).super_method.call}
|
12
11
|
|
13
|
-
Did you mean?
|
12
|
+
Did you mean? inspect
|
14
13
|
|
15
14
|
MESSAGE
|
16
15
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: did_you_mean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Yuki Nishijima
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2016-05-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -16,14 +16,14 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '1.
|
19
|
+
version: '1.10'
|
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: '1.
|
26
|
+
version: '1.10'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
@@ -75,7 +75,6 @@ files:
|
|
75
75
|
- did_you_mean.gemspec
|
76
76
|
- doc/CHANGELOG.md.erb
|
77
77
|
- doc/changelog_generator.rb
|
78
|
-
- doc/did_you_mean_example.png
|
79
78
|
- evaluation/calculator.rb
|
80
79
|
- evaluation/dictionary_generator.rb
|
81
80
|
- evaluation/incorrect_words.yaml
|
@@ -118,7 +117,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
117
|
requirements:
|
119
118
|
- - ">="
|
120
119
|
- !ruby/object:Gem::Version
|
121
|
-
version: 2.3.
|
120
|
+
version: 2.3.0
|
122
121
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
122
|
requirements:
|
124
123
|
- - ">="
|