{"id":24169658,"url":"https://github.com/universal-automata/liblevenshtein-coffeescript","last_synced_at":"2025-08-27T09:41:05.919Z","repository":{"id":15516009,"uuid":"18250297","full_name":"universal-automata/liblevenshtein-coffeescript","owner":"universal-automata","description":"Various utilities regarding Levenshtein transducers. (CoffeeScript / JavaScript / Node.js)","archived":false,"fork":false,"pushed_at":"2016-06-20T01:59:12.000Z","size":33,"stargazers_count":12,"open_issues_count":4,"forks_count":7,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-08-09T09:52:51.661Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"CoffeeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":"udacity/frontend-nanodegree-mobile-portfolio","license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/universal-automata.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2014-03-29T20:38:12.000Z","updated_at":"2024-01-17T22:06:14.000Z","dependencies_parsed_at":"2022-09-16T04:53:29.392Z","dependency_job_id":null,"html_url":"https://github.com/universal-automata/liblevenshtein-coffeescript","commit_stats":null,"previous_names":["dylon/liblevenshtein-coffeescript"],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/universal-automata/liblevenshtein-coffeescript","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/universal-automata%2Fliblevenshtein-coffeescript","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/universal-automata%2Fliblevenshtein-coffeescript/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/universal-automata%2Fliblevenshtein-coffeescript/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/universal-automata%2Fliblevenshtein-coffeescript/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/universal-automata","download_url":"https://codeload.github.com/universal-automata/liblevenshtein-coffeescript/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/universal-automata%2Fliblevenshtein-coffeescript/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272315479,"owners_count":24912575,"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-08-27T02:00:09.397Z","response_time":76,"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":"2025-01-12T23:13:54.941Z","updated_at":"2025-08-27T09:41:05.883Z","avatar_url":"https://github.com/universal-automata.png","language":"CoffeeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# liblevenshtein\n\n## CoffeeScript / JavaScript / Node.js\n\n### A library for generating Finite State Transducers based on Levenshtein Automata.\n\n[![npm version][npm-version-badge]][npm-repo]\n[![Build Status][travis-ci-badge]][travis-ci]\n[![Join the chat at https://gitter.im/universal-automata/liblevenshtein-coffeescript][gitter-badge]][gitter-channel]\n\nLevenshtein transducers accept a query term and return all terms in a\ndictionary that are within n spelling errors away from it. They constitute a\nhighly-efficient (space _and_ time) class of spelling correctors that work very\nwell when you do not require context while making suggestions.  Forget about\nperforming a linear scan over your dictionary to find all terms that are\nsufficiently-close to the user's query, using a quadratic implementation of the\n[Levenshtein distance](https://en.wikipedia.org/wiki/Levenshtein_distance) or\n[Damerau-Levenshtein\ndistance](https://en.wikipedia.org/wiki/Damerau%E2%80%93Levenshtein_distance),\nthese babies find _all_ the terms from your dictionary in linear time _on the\nlength of the query term_ (not on the size of the dictionary, on the length of\nthe query term).\n\nIf you need context, then take the candidates generated by the transducer as a\nstarting place, and plug them into whatever model you're using for context (such\nas by selecting the sequence of terms that have the greatest probability of\nappearing together).\n\nFor a quick demonstration, please visit the [Github Page,\nhere](http://universal-automata.github.io/liblevenshtein/).\n\nThe library is currently written in Java, CoffeeScript, and JavaScript, but I\nwill be porting it to other languages, soon.  If you have a specific language\nyou would like to see it in, or package-management system you would like it\ndeployed to, let me know.\n\n### Basic Usage:\n\n#### Node.js\n\nInstall the module via `npm`:\n\n```\n% npm install liblevenshtein\ninfo trying registry request attempt 1 at 12:59:16\nhttp GET https://registry.npmjs.org/liblevenshtein\nhttp 304 https://registry.npmjs.org/liblevenshtein\nliblevenshtein@2.0.4 node_modules/liblevenshtein\n```\n\nThen, you may `require` it to do whatever you need:\n\n```javascript\nvar levenshtein = require('liblevenshtein');\n\n// Assume \"completion_list\" is a list of terms you want to match against in\n// fuzzy queries.\nvar builder = new levenshtein.Builder()\n  .dictionary(completion_list, false)  // generate spelling candidates from unsorted completion_list\n  .algorithm(\"transposition\")          // use Levenshtein distance extended with transposition\n  .sort_candidates(true)               // sort the spelling candidates before returning them\n  .case_insensitive_sort(true)         // ignore character-casing while sorting terms\n  .include_distance(false)             // just return the ordered terms (drop the distances)\n  .maximum_candidates(10);             // only want the top-10 candidates\n\n// Maximum number of spelling errors we will allow the spelling candidates to\n// have, with regard to the query term.\nvar MAX_EDIT_DISTANCE = 2;\n\nvar transducer = builder.build();\n\n// Assume \"term\" corresponds to some query term. Once invoking\n// transducer.transduce(term, MAX_EDIT_DISTANCE), candidates will contain a list\n// of all spelling candidates from the completion list that are within\n// MAX_EDIT_DISTANCE units of error from the query term.\nvar candidates = transducer.transduce(term, MAX_EDIT_DISTANCE);\n```\n\n#### In the Browser\n\nTo use the library on your website, reference the desired file from the\n`\u003chead/\u003e` of your document, like so:\n\n```html\n\u003c!DOCTYPE html\u003e\n\u003chtml\u003e\n  \u003chead\u003e\n    \u003c!-- stuff ... --\u003e\n    \u003cscript type=\"text/javascript\"\n      src=\"http://universal-automata.github.com/liblevenshtein/javascripts/2.0.4/levenshtein-transducer.min.js\"\u003e\n    \u003c/script\u003e\n    \u003c!-- more stuff ... --\u003e\n  \u003c/head\u003e\n  \u003cbody\u003e\n    \u003c!-- yet another fancy document ... --\u003e\n  \u003c/body\u003e\n\u003c/html\u003e\n```\n\nOnce the script loads, you should construct a transducer via the [Builder\nApi](http://universal-automata.github.io/liblevenshtein/docs/coffeescript/builder.html):\n\n```javascript\n$(function ($) {\n  \"use strict\";\n\n  // Maximum number of spelling errors we will allow the spelling candidates to\n  // have, with regard to the query term.\n  var MAX_EDIT_DISTANCE = 2;\n\n  var completion_list = getCompletionList(); // fictitious method\n\n  var builder = new levenshtein.Builder()\n    .dictionary(completion_list, false)  // generate spelling candidates from unsorted completion_list\n    .algorithm(\"transposition\")          // use Levenshtein distance extended with transposition\n    .sort_candidates(true)               // sort the spelling candidates before returning them\n    .case_insensitive_sort(true)         // ignore character-casing while sorting terms\n    .include_distance(false)             // just return the ordered terms (drop the distances)\n    .maximum_candidates(10);             // only want the top-10 candidates\n\n  var transducer = builder.build();\n\n  var $queryTerm = $('#query-term-input-field');\n  $queryTerm.keyup(function (event) {\n    var candidates, term = $.trim($queryTerm.val());\n\n    if (term) {\n      candidates = transducer.transduce(term, MAX_EDIT_DISTANCE);\n      printAutoComplete(candidates); // print the list of completions\n    } else {\n      clearAutoComplete(); // user has cleared the search box\n    }\n\n    return true;\n  });\n});\n```\n\nThis will give the user autocompletion hints as he types in the search box.\n\n### Reference\n\nThis library is based largely on the work of [Stoyan\nMihov](http://www.lml.bas.bg/~stoyan/), [Klaus\nSchulz](http://www.cis.uni-muenchen.de/people/schulz.html), and Petar Nikolaev Mitankin: \"[Fast\nString Correction with\nLevenshtein-Automata](http://citeseerx.ist.psu.edu/viewdoc/summary?doi=10.1.1.16.652\n\"Klaus Schulz and Stoyan Mihov (2002)\")\".  For more details, please see the\n[wiki](https://github.com/universal-automata/liblevenshtein/wiki).\n\n[travis-ci-badge]: https://travis-ci.org/universal-automata/liblevenshtein-coffeescript.svg?branch=master\n[travis-ci]: https://travis-ci.org/universal-automata/liblevenshtein-coffeescript\n[npm-version-badge]: https://badge.fury.io/js/liblevenshtein.svg\n[npm-repo]: https://www.npmjs.com/package/liblevenshtein\n[gitter-badge]: https://badges.gitter.im/universal-automata/liblevenshtein-coffeescript.svg\n[gitter-channel]: https://gitter.im/universal-automata/liblevenshtein-coffeescript?utm_source=badge\u0026utm_medium=badge\u0026utm_campaign=pr-badge\u0026utm_content=badge\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funiversal-automata%2Fliblevenshtein-coffeescript","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Funiversal-automata%2Fliblevenshtein-coffeescript","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Funiversal-automata%2Fliblevenshtein-coffeescript/lists"}