Project

spell

0.0
Repository is archived
No commit activity in last 3 years
No release in over 3 years
Spell checker written in pure Ruby, implementing a simple bigram comparison algorithm. Spell has no external dependencies (including aspell or ispell).
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
 Dependencies

Development

~> 1.10
~> 10.0
>= 0
 Project Readme

Spell

Spell checker written in pure Ruby, implementing a simple bigram comparison algorithm. Spell has no external dependencies (including aspell or ispell).

Installation

Add this line to your application's Gemfile:

gem 'spell'

And then execute:

$ bundle

Or install it yourself as:

$ gem install spell

Usage

The spell initializer can take one or two arguments.

If you do not care about using the word usage, you can simply write:

word_list = ["alpha", "beta"]
spell = Spell::Spell.new(word_list)
spell.best_match('alphabet')  #=> "alpha"

If you want to include word usage in the best match calculation, you must provide a hash where the keys are the words and the values are the corresponding word counts.

The default for the word usage weight (internally termed "alpha") is 0.3. This value should be in the range 0.0-1.0, where 0.0 means the word usage does not affect the output, whereas 1.0 means the most used word is always returned.

If you want to accept the default weight, you can simply write:

word_list = { "alpha" => 2, "beta" => 20 }
spell = Spell::Spell.new(word_list)
spell.best_match('alphabet')  #=> "alpha"

Or, if you'd rather specify a custom word usage weight, you can specify it like this:

word_list = { "alpha" => 2, "beta" => 20 }
spell = Spell::Spell.new(word_list, 0.5)
spell.best_match('alphabet')  #=> "beta"

Other than the best_match method, shown above, there is also a compare method, which returns the how similar two words are, based on shared, order-consistent bigrams compared to the maximum number of bigrams of the two words.

word_list = ["alpha", "beta"]
spell = Spell::Spell.new(word_list)
spell.compare('alpha', 'alphabet')  #=> 0.5714285714285714 (4 / 7)

Development

After checking out the repo, run bin/setup to install dependencies. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/J3RN/spellrb. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.

License

The gem is available as open source under the terms of the MIT License.