All Projects → ruby → Did_you_mean

ruby / Did_you_mean

Licence: mit
The gem that has been saving people from typos since 2014

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to Did you mean

Symspell
SymSpell: 1 million times faster spelling correction & fuzzy search through Symmetric Delete spelling correction algorithm
Stars: ✭ 1,976 (+10.64%)
Mutual labels:  spellcheck, spell-check, spelling, spelling-correction
SymSpellCppPy
Fast SymSpell written in c++ and exposes to python via pybind11
Stars: ✭ 28 (-98.43%)
Mutual labels:  spellcheck, spelling, spell-check, spelling-correction
spellchecker-wasm
SpellcheckerWasm is an extrememly fast spellchecker for WebAssembly based on SymSpell
Stars: ✭ 46 (-97.42%)
Mutual labels:  spellcheck, spelling, spell-check, spelling-correction
LinSpell
Fast approximate strings search & spelling correction
Stars: ✭ 52 (-97.09%)
Mutual labels:  spellcheck, spelling, spell-check, spelling-correction
spell
Spelling correction and string segmentation written in Go
Stars: ✭ 24 (-98.66%)
Mutual labels:  spellcheck, spelling, spell-check, spelling-correction
check-spelling
Spelling checker action
Stars: ✭ 139 (-92.22%)
Mutual labels:  spellcheck, spelling, spell-check
spacy hunspell
✏️ Hunspell extension for spaCy 2.0.
Stars: ✭ 94 (-94.74%)
Mutual labels:  spelling, spell-check, spelling-correction
WordSegmentationDP
Word Segmentation with Dynamic Programming
Stars: ✭ 18 (-98.99%)
Mutual labels:  spellcheck, spell-check, spelling-correction
ka GE.spell
ქართული ორთოგრაფიული ლექსიკონი - Georgian Spell Checking Dictionary
Stars: ✭ 24 (-98.66%)
Mutual labels:  spelling, spelling-checker, spelling-correction
Pylanguagetool
Python Library and CLI for the LanguageTool JSON API
Stars: ✭ 62 (-96.53%)
Mutual labels:  spellcheck, spell-check
Spelling
Tools for Spell Checking in R
Stars: ✭ 82 (-95.41%)
Mutual labels:  spellcheck, spell-check
Wecantspell.hunspell
A port of Hunspell v1 for .NET and .NET Standard
Stars: ✭ 61 (-96.58%)
Mutual labels:  spellcheck, spell-check
contextualSpellCheck
✔️Contextual word checker for better suggestions
Stars: ✭ 274 (-84.66%)
Mutual labels:  spellcheck, spelling-correction
yaspeller-ci
Fast spelling check for Travis CI
Stars: ✭ 60 (-96.64%)
Mutual labels:  spellcheck, spelling
ispell-lt
Lithuanian spellchecking dictionary
Stars: ✭ 26 (-98.54%)
Mutual labels:  spellcheck, spelling
Symspellpy
Python port of SymSpell
Stars: ✭ 420 (-76.48%)
Mutual labels:  spellcheck, spell-check
cyberdic
An auxiliary spellcheck dictionary that corresponds with the Bishop Fox Cybersecurity Style Guide
Stars: ✭ 63 (-96.47%)
Mutual labels:  spellcheck, spelling
Dictionaries
Hunspell dictionaries in UTF-8
Stars: ✭ 591 (-66.91%)
Mutual labels:  spellcheck, spell-check
neuspell
NeuSpell: A Neural Spelling Correction Toolkit
Stars: ✭ 524 (-70.66%)
Mutual labels:  spellcheck, spelling-correction
Symspellcompound
SymSpellCompound: compound aware automatic spelling correction
Stars: ✭ 61 (-96.58%)
Mutual labels:  spellcheck, spell-check

did_you_mean Gem Version Build status

Installation

Ruby 2.3 and later ships with this gem and it will automatically be required when a Ruby process starts up. No special setup is required.

Examples

NameError

Correcting a Misspelled Method Name

methosd
# => NameError: undefined local variable or method `methosd' for main:Object
#    Did you mean?  methods
#                   method

Correcting a Misspelled Class Name

OBject
# => NameError: uninitialized constant OBject
#    Did you mean?  Object

Suggesting an Instance Variable Name

@full_name = "Yuki Nishijima"
first_name, last_name = full_name.split(" ")
# => NameError: undefined local variable or method `full_name' for main:Object
#    Did you mean?  @full_name

Correcting a Class Variable Name

@@full_name = "Yuki Nishijima"
@@full_anme
# => NameError: uninitialized class variable @@full_anme in Object
#    Did you mean?  @@full_name

NoMethodError

full_name = "Yuki Nishijima"
full_name.starts_with?("Y")
# => NoMethodError: undefined method `starts_with?' for "Yuki Nishijima":String
#    Did you mean?  start_with?

KeyError

hash = {foo: 1, bar: 2, baz: 3}
hash.fetch(:fooo)
# => KeyError: key not found: :fooo
#    Did you mean?  :foo

LoadError

require 'net-http'
# => LoadError (cannot load such file -- net-http)
#    Did you mean?  net/http

NoMatchingPatternKeyError

hash = {foo: 1, bar: 2, baz: 3}
hash => {fooo:}
# => NoMatchingPatternKeyError: key not found: :fooo
#    Did you mean?  :foo

Using the DidYouMean::SpellChecker

If you need to programmatically find the closest matches to the user input, you could do so by re-using the DidYouMean::SpellChecker object.

spell_checker = DidYouMean::SpellChecker.new(dictionary: ['email', 'fail', 'eval'])

spell_checker.correct('meail') # => ['email']
spell_checker.correct('afil')  # => ['fail']

Disabling did_you_mean

Occasionally, you may want to disable the did_you_mean gem for e.g. debugging issues in the error object itself. You can disable it entirely by specifying --disable-did_you_mean option to the ruby command:

$ ruby --disable-did_you_mean -e "1.zeor?"
-e:1:in `<main>': undefined method `zeor?' for 1:Integer (NameError)

When you do not have direct access to the ruby command (e.g. rails console, irb), you could apply options using the RUBYOPT environment variable:

$ RUBYOPT='--disable-did_you_mean' irb
irb:0> 1.zeor?
# => NoMethodError (undefined method `zeor?' for 1:Integer)

Getting the original error message

Sometimes, you do not want to disable the gem entirely, but need to get the original error message without suggestions (e.g. testing). In this case, you could use the #original_message method on the error object:

no_method_error = begin
                    1.zeor?
                  rescue NoMethodError => error
                    error
                  end

no_method_error.message
# => NoMethodError (undefined method `zeor?' for 1:Integer)
#    Did you mean?  zero?

no_method_error.original_message
# => NoMethodError (undefined method `zeor?' for 1:Integer)

Benchmarking

Performance is very important as the did_you_mean gem attempts to find the closest matches on the fly right after an exception is thrown. You could use the following rake tasks to get insights into how the gem performs:

bundle exec rake benchmark:ips:jaro
bundle exec rake benchmark:ips:levenshtein
bundle exec rake benchmark:memory
bundle exec rake benchmark:memory:jaro
bundle exec rake benchmark:memory:levenshtein

Be sure to always use bundle exec otherwise it will activate the pre-installed version of the did_you_mean gem rather than using what's in the lib/.

You could also use the benchmark-driver gem to know how each Ruby performs differently.

bundle exec benchmark-driver benchmark/speed.yml --rbenv '2.6.0 --jit;2.6.0;2.5.3;truffleruby-1.0.0-rc10' --run-duration 30

Contributing

  1. Fork it (https://github.com/ruby/did_you_mean/fork)
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Make sure all tests pass (bundle exec rake)
  5. Push to the branch (git push origin my-new-feature)
  6. Create new Pull Request

License

Copyright (c) 2014-16 Yuki Nishijima. See MIT-LICENSE for further details.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].