Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. NLP with Ruby
  3. damerau-levenshtein

damerau-levenshtein

MITRubyv1.3.3

A Ruby gem for calculating edit distance between strings using Levenshtein, Damerau-Levenshtein, and Boehmer & Rees algorithms.

GitHubGitHub
151 stars19 forks0 contributors

What is damerau-levenshtein?

damerau-levenshtein is a Ruby library that implements edit distance algorithms for measuring similarity between strings or arrays. It calculates the minimum number of single-character edits (insertions, deletions, substitutions, and transpositions) required to change one sequence into another. The gem provides three algorithm variants: classic Levenshtein, Damerau-Levenshtein (which counts adjacent character swaps as one edit), and a modified version supporting block transpositions.

Target Audience

Ruby developers working on text processing, spell checking, fuzzy matching, bioinformatics, or any application requiring string similarity measurements. It's particularly useful for those needing fine-grained control over edit distance calculations.

Value Proposition

Unlike simpler string comparison methods, this gem offers multiple algorithm choices with configurable parameters like block size and distance thresholds. Its ability to generate detailed diffs and handle UTF-8 text makes it more versatile than basic implementations.

Overview

Calculates edit distance using Damerau-Levenshtein algorithm

Use Cases

Best For

  • Implementing fuzzy string matching in search functionality
  • Building spell checkers or autocorrect systems
  • Calculating similarity scores for DNA/protein sequences in bioinformatics
  • Generating detailed diffs between text versions
  • Data deduplication by identifying similar records
  • Natural language processing tasks requiring edit distance metrics

Not Ideal For

  • Applications requiring real-time, high-throughput string matching on massive datasets
  • Projects needing simple, one-line string similarity scores without configuration overhead
  • Teams working on platforms without easy access to C extensions or system dependencies like libgmp3-dev

Pros & Cons

Pros

Multiple Algorithm Variants

Supports Levenshtein, Damerau-Levenshtein, and Boehmer & Rees modifications, allowing precise control over edit distance calculations for different use cases, as demonstrated in the README with examples like block_size adjustments.

UTF-8 and Array Support

Handles international characters correctly (e.g., 'Sjöstedt' vs 'Sjostedt') and can compare arrays of integers, making it versatile for text and sequence analysis beyond simple strings.

Customizable Diff Output

Generates differences between strings with tag-based (<ins>, <del>, <subst>) or raw formats, enabling flexible integration with tools like Nokogiri for highlighting changes, as shown in the parsing example.

Performance Optimization

Includes a max_distance parameter to stop computation early, improving efficiency when only interested in small edit distances, which is documented in the API for reducing unnecessary calculations.

Cons

System Dependency Overhead

Requires installation of build-essential and libgmp3-dev via apt-get, which can complicate setup on non-Debian-based systems or environments without sudo access, adding friction for cross-platform deployment.

Limited Advanced Features

Focuses solely on edit distance without built-in support for common fuzzy matching techniques like n-grams or phonetic algorithms, which might necessitate additional libraries for broader text similarity tasks.

Performance Trade-offs

With O(N*M) time complexity, it can be slow for very long strings or high-volume comparisons, and while max_distance helps, it doesn't address fundamental scalability issues for large-scale applications.

Frequently Asked Questions

Quick Stats

Stars151
Forks19
Contributors0
Open Issues2
Last commit1 year ago
CreatedSince 2011

Tags

#algorithm#ruby-gem#text-processing#damerau-levenshtein#levenshtein#string-comparison#edit-distance

Built With

R
Ruby

Included in

NLP with Ruby1.1k
Auto-fetched 16 hours ago

Related Projects

tf-idf-similaritytf-idf-similarity

Ruby gem to calculate the similarity between texts using tf*idf

Stars783
Forks62
Last commit2 years ago
amatchamatch

Approximate String Matching library

Stars394
Forks38
Last commit1 month ago
levenshtein-ffilevenshtein-ffi

Fast string edit distance computation, using the Damerau-Levenshtein algorithm.

Stars151
Forks29
Last commit2 years ago
hotwaterhotwater

Fast Ruby FFI string edit distance algorithms

Stars80
Forks1
Last commit13 years ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub