{"id":37099756,"url":"https://github.com/f1monkey/spellchecker","last_synced_at":"2026-01-14T12:10:02.752Z","repository":{"id":63758229,"uuid":"562327031","full_name":"f1monkey/spellchecker","owner":"f1monkey","description":"Yet another spellchecker written in go","archived":false,"fork":false,"pushed_at":"2025-12-18T21:50:25.000Z","size":2494,"stargazers_count":16,"open_issues_count":0,"forks_count":5,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-12-21T22:32:28.621Z","etag":null,"topics":["fuzzy","fuzzy-search","go","golang","spell-check","spelling-correction"],"latest_commit_sha":null,"homepage":"","language":"Go","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/f1monkey.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2022-11-06T01:30:00.000Z","updated_at":"2025-12-18T21:49:24.000Z","dependencies_parsed_at":"2024-02-09T12:09:48.590Z","dependency_job_id":"863e9275-e365-4bba-84eb-1a02a91cc6df","html_url":"https://github.com/f1monkey/spellchecker","commit_stats":{"total_commits":38,"total_committers":1,"mean_commits":38.0,"dds":0.0,"last_synced_commit":"32907aa80cc3633625b2045fc13cc21467390606"},"previous_names":["cyradin/spellchecker"],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/f1monkey/spellchecker","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f1monkey%2Fspellchecker","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f1monkey%2Fspellchecker/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f1monkey%2Fspellchecker/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f1monkey%2Fspellchecker/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/f1monkey","download_url":"https://codeload.github.com/f1monkey/spellchecker/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/f1monkey%2Fspellchecker/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28419546,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-14T10:47:48.104Z","status":"ssl_error","status_checked_at":"2026-01-14T10:46:19.031Z","response_time":107,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["fuzzy","fuzzy-search","go","golang","spell-check","spelling-correction"],"created_at":"2026-01-14T12:10:02.071Z","updated_at":"2026-01-14T12:10:02.751Z","avatar_url":"https://github.com/f1monkey.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Spellchecker\n\n[![Go Reference](https://pkg.go.dev/badge/github.com/f1monkey/spellchecker.svg)](https://pkg.go.dev/github.com/f1monkey/spellchecker/v3)\n[![CI](https://github.com/f1monkey/spellchecker/actions/workflows/test.yaml/badge.svg)](https://github.com/f1monkey/spellchecker/actions/workflows/test.yaml)\n\nYet another spellchecker written in go.\n\n- [Spellchecker](#spellchecker)\n\t- [Features:](#features)\n\t- [Installation](#installation)\n\t- [Usage](#usage)\n\t- [Benchmarks](#benchmarks)\n\t\t- [Test set 1:](#test-set-1)\n\t\t- [Test set 2:](#test-set-2)\n\n## Features:\n- very compact database: ~1 MB for 30,000 unique words\n- average time to fix a single word: ~35 µs\n- achieves about 70–74% accuracy on Peter Norvig’s test sets (see [benchmarks](#benchmarks))\n- no built-in dictionary — you can provide any custom words, and the spellchecker will only know them\n\n## Installation\n\n```\ngo get -v github.com/f1monkey/spellchecker/v3\n```\n\n## Usage\n\n\n### Quick start\n\n1. Initialize the spellchecker. You need to pass an alphabet: a set of allowed characters that will be used for indexing and primary word checks. (All other characters will be ignored for these operations.)\n\n```go\n\t// Create a new instance\n\tsc, err := spellchecker.New(\n\t\t\"abcdefghijklmnopqrstuvwxyz1234567890\", // allowed symbols, other symbols will be ignored\n\t)\n```\n\n2. Add some words to the dictionary:\n\t1. from any `io.Reader`:\n\t```go\n\t\tin, _ := os.Open(\"data/sample.txt\")\n\t\tsc.AddFrom(in)\n\t```\n\t2. Or add words manually:\n\t```go\n\t\tsc.AddMany([]string{\"lock\", \"stock\", \"and\", \"two\", \"smoking\"})\n\t\tsc.Add(\"barrels\")\n\t```\n\n3. Use the spellchecker:\n\t1. Check if a word is correct:\n\t```go\n\t\tresult := sc.IsCorrect(\"stock\")\n\t\tfmt.Println(result) // true\n\t```\n\t2. Suggest corrections:\n\t```go\n\t\t// Find up to 10 suggestions for a word\n\t\tmatches := sc.Suggest(nil, \"rang\", 10)\n\t\tfmt.Println(matches) // [range, orange]\n\t```\n### Options\n\n### Options\n\nThe spellchecker supports customizable options for both searching/suggesting corrections and adding words to the dictionary.\n\n#### Search/Suggestion Options\n\nThese options are passed to the `Suggest` method (or to `SuggestWith...` helpers).\n\n- **`SuggestWithMaxErrors(maxErrors int)`**  \n  Sets the maximum allowed edit distance (in \"bits\") between the input word and dictionary candidates.  \n  - Deletion: 1 bit (e.g., \"proble\" → \"problem\")  \n  - Insertion: 1 bit (e.g., \"problemm\" → \"problem\")  \n  - Substitution: 2 bits (e.g., \"problam\" → \"problem\")  \n  - Transposition: 0 bits (e.g., \"problme\" → \"problem\")  \n\n  Default: `2`.\n  Increasing this value beyond 2 is not recommended as it can significantly degrade performance.\n\n- **`SuggestWithFilterFunc(f FilterFunc)`**  \n  Replaces the default scoring/filtering function with a custom one.  \n  The function receives:\n  - `src`: runes of the input word\n  - `candidate`: runes of the dictionary word\n  - `count`: frequency count of the candidate in the dictionary\n\n  It must return:\n  - a `float64` score (higher = better suggestion)\n  - a `bool` indicating whether the candidate should be kept\n\n  The default filter uses Levenshtein distance (with costs: insert/delete=1, substitute=1, transpose=1), filters out candidates exceeding `maxErrors`, and boosts score based on word frequency and shared prefix/suffix length.\n\nExample usage:\n```go\nmatches := sc.Suggest(\n\t\"rang\",\n\t10,\n\tspellchecker.SuggestWithMaxErrors(1),\n\tspellchecker.SuggestWithFilterFunc(myCustomFilter),\n)\n```\n\n#### Add Options\nThese options are passed to `Add`, `AddMany`, or `AddFrom`.\n\n- **`AddWithWeight(weight uint)`**\n  Sets the frequency weight for added word(s). Higher weight increases the chance that the word will appear higher in suggestion results.\n  Default: 1.\n- **`AddWithSplitter(splitter bufio.SplitFunc)`**\n  Customizes how AddFrom(reader) splits the input stream into words.\n\n  The default splitter:\n    - Uses bufio.ScanWords as base\n    - Converts to lowercase\n    - Keeps only sequences matching [-\\pL]+ (letters and hyphens)\n\nExample:\n```go\nsc.AddFrom(\n\tfile,\n\tspellchecker.AddWithWeight(10),          // these words are very common\n\tspellchecker.AddWithSplitter(customSplitter),\n)\n\nsc.AddMany([]string{\"hello\", \"world\"},\n\tspellchecker.AddWithWeight(5),\n)\n```\n\n### Save/load\n\n```go\n\tsc, err := spellchecker.New(\"abc\")\n\n\t// Save data to any io.Writer\n\tout, err := os.Create(\"data/out.bin\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tsc.Save(out)\n\n\t// Load data back from io.Reader\n\tin, err = os.Open(\"data/out.bin\")\n\tif err != nil {\n\t\tpanic(err)\n\t}\n\tsc, err = spellchecker.Load(in)\n\tif err != nil {\n\t\tpanic(err)\n\t}\n```\n\n## Benchmarks\n\nTests are based on data from [Peter Norvig's article about spelling correction](http://norvig.com/spell-correct.html)\n\n#### [Test set 1](http://norvig.com/spell-testset1.txt):\n\n```\nRunning tool: /usr/bin/go test -benchmem -run=^$ -bench ^Benchmark_Norvig1$ github.com/f1monkey/spellchecker -count=1\n\ngoos: linux\ngoarch: amd64\npkg: github.com/f1monkey/spellchecker\ncpu: 13th Gen Intel(R) Core(TM) i9-13980HX\nBenchmark_Norvig1-32    \t     357\t   3305052 ns/op\t        74.44 success_percent\t       201.0 success_words\t       270.0 total_words\t  768899 B/op\t   13302 allocs/op\nPASS\nok  \tgithub.com/f1monkey/spellchecker\t3.801s\n```\n\n#### [Test set 2](http://norvig.com/spell-testset2.txt):\n\n```\nRunning tool: /usr/bin/go test -benchmem -run=^$ -bench ^Benchmark_Norvig2$ github.com/f1monkey/spellchecker -count=1\n\ngoos: linux\ngoarch: amd64\npkg: github.com/f1monkey/spellchecker\ncpu: 13th Gen Intel(R) Core(TM) i9-13980HX\nBenchmark_Norvig2-32    \t     236\t   5257185 ns/op\t        71.25 success_percent\t       285.0 success_words\t       400.0 total_words\t 1201260 B/op\t   19346 allocs/op\nPASS\nok  \tgithub.com/f1monkey/spellchecker\t4.350s\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff1monkey%2Fspellchecker","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ff1monkey%2Fspellchecker","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ff1monkey%2Fspellchecker/lists"}