{"id":13858587,"url":"https://github.com/phstc/spelling-corrector","last_synced_at":"2025-07-30T09:08:16.645Z","repository":{"id":7476736,"uuid":"8824902","full_name":"phstc/spelling-corrector","owner":"phstc","description":"It's a Ruby implementation of Norvig Spelling Corrector plus Levenshtein distance fallback.","archived":false,"fork":false,"pushed_at":"2013-03-26T14:27:00.000Z","size":3952,"stargazers_count":7,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-05-12T16:54:12.435Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/phstc.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-03-16T20:21:21.000Z","updated_at":"2024-10-25T16:48:33.000Z","dependencies_parsed_at":"2022-09-01T01:40:47.484Z","dependency_job_id":null,"html_url":"https://github.com/phstc/spelling-corrector","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/phstc/spelling-corrector","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fspelling-corrector","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fspelling-corrector/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fspelling-corrector/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fspelling-corrector/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phstc","download_url":"https://codeload.github.com/phstc/spelling-corrector/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phstc%2Fspelling-corrector/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267843005,"owners_count":24153135,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-07-30T02:00:09.044Z","response_time":70,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-08-05T03:02:14.172Z","updated_at":"2025-07-30T09:08:16.624Z","avatar_url":"https://github.com/phstc.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# Spelling Corrector\n\nIt's a Ruby implementation of [Norvig Spelling Corrector](http://norvig.com/spell-correct.html) plus [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance) fallback.\n\nIf Norvig algorithm doesn't find the correction, this implementation will look for the first occurrence (distance \u003c= 8) of a similar word using Levenshtein distance.\n\n```ruby\nknown([word]) || known(edits1(word)) || known_edits2(word) || levenshtein(word) || [\"NO SUGGESTION\"]\n```\n\nLevenshtein costs: ins=2, del=2 and sub=1.\n\n## The Algorithm\n\nFirstly, I recommend to read the [Norvig explanation](http://norvig.com/spell-correct.html) and [Levenshtein distance](http://en.wikipedia.org/wiki/Levenshtein_distance) then have a look at the tests (specs directory), they show how each method work, it helps the understading of the algorithm.\n\nMost of the `SpellingCorrector` methods, should be private, I left them as public only to document (explain) them with tests.\n\n## How to use it\n\n```ruby\nrequire \"lib/spelling_corrector\"\n\ncorrector = SpellingCorrector.new\ncorrector.correct \"cen\" =\u003e \"can\"\n\ncorrector.correct \"unknownword\" =\u003e \"NO SUGGESTION\"\n```\n\n### Persisted Spelling Corrector\n\nThe `PersistedSpellingCorrector` and `PersistedWordCollection` are implementions using MongoDB (encapsulating the non-persisted implementations) to persisted the corrections and trained word collection.\n\n\n## Examples\n\nIn the `examples` directory, there are two examples, one using refinements and another with [Sinatra](http://www.sinatrarb.com/) to expose Spelling Corrector as an API.\n\n### Refinements\n\nIf you are using Ruby 2.0.0 we can use refine your string classes using the Spelling Corrector.\n\n```ruby\n# examples/refinement_spelling_corrector.rb\n\nusing StringSpellingCorrectorRefinement\n\nputs \"cen\".correct\n```\n\n### webapp\n\nThe webapp example is deployed at Heroku, you can easily test it via `curl` or directly in the browser (shame on you).\n\n```bash\ncurl spelling-corrector.herokuapp.com/correct/cen\n=\u003e can\n```\n\nSince it uses PersistedSpellingCorrector, to run it locally, you will need a MongoDB connection.\n\n## License\nThis code is licensed under:\n\nMIT License GPL\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphstc%2Fspelling-corrector","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphstc%2Fspelling-corrector","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphstc%2Fspelling-corrector/lists"}