piapia123
en

String Distance

Text

Everything runs locally in your browser — nothing is uploaded

Input
Drop a file here to load its contents
Output

How similar two strings are depends on which question you are asking — hence five algorithms here, and they are five questions, not five phrasings: · Levenshtein — how many edits turn one into the other, allowing insert, delete and substitute. · Damerau — the same, but an adjacent swap counts as one step. `teh` → `the` is 2 by edit distance and 1 by Damerau, and swapped neighbours are the most common typo there is. · Hamming — substitutions only, and the two must be the same length. This is the DNA and bit-error-rate measure. · Jaro-Winkler — a 0–1 similarity rather than a distance, with a bonus for a shared prefix. It comes from name matching. · Longest common subsequence — not required to be contiguous; the basis of text diff. ⚠️ Why the result also gives a character-by-character alignment: a distance of 3 is not actionable. You need to know where, so the Levenshtein path marks every position as a match, substitution, insertion or deletion. ⚠️ One trap with similarity: here it is computed as `1 − distance ÷ longer length`, which is a convention, not the definition. Jaro-Winkler defines similarity its own way, so the two disagree on the same input — do not compare them directly. Input convention: A on the first line, B on the second. Everything runs in your browser.

Features

  • Edit distance, with a character-by-character alignment and a list of what changed (which substitutions, insertions and deletions)
  • Damerau-Levenshtein: an adjacent swap is one step, so `teh` → `the` is 1 rather than 2
  • Hamming distance: ⚠️ when the lengths differ it says so instead of inventing a number, because the measure is not defined there
  • Jaro and Jaro-Winkler similarity (0–1), prefix capped at 4 characters and the bonus applied only above the original paper’s 0.7 threshold
  • Longest common subsequence: gives the length and the subsequence itself
  • ⚠️ The similarity row carries a note that it is a convention, so it is not compared against Jaro-Winkler
  • CJK characters are padded to two columns so the alignment does not drift
  • ⚠️ A string over 5,000 characters is reported rather than computed — the matrix would hang the tab, and a frozen result helps nobody
  • Case sensitivity is optional, and normalising only affects the comparison, never the strings shown back

How to use

  1. Put A on the first line and B on the second
  2. Pick the algorithm — they answer different questions
  3. The edit-distance path gives a character alignment you can work from

FAQ

Why five algorithms instead of one similarity number?
Because they answer different questions, and offering one would mislead. `teh` and `the` differ by 2 under edit distance and by 1 under Damerau — which is right depends on whether you are counting keystrokes or changed letters. Hamming allows substitutions only and requires equal lengths, which is the DNA and bit-error case. Jaro-Winkler returns a similarity rather than a distance and leans towards “the same name if it starts the same”. Pick the wrong one and the number still looks like a number, but it no longer answers your question.
Why does the similarity need a note saying it is a convention?
Because a distance has an exact definition (how many edits) while a similarity does not — there are several ways to fold a distance into 0–1. This one is `1 − distance ÷ longer length`. Jaro-Winkler defines its own, so the two legitimately disagree on the same input. Without saying so, people compare the two numbers and conclude one of them is broken.
Why give no number for Hamming when the lengths differ?
Because it is not defined. Hamming distance is “at how many positions do two equal-length sequences differ”, and with unequal lengths that question does not exist. A number could be manufactured (truncate to the shorter, say), but it would answer nothing while looking authoritative. So the tool says so instead.
Why refuse very long inputs?
Because these algorithms all build an n × m matrix. Twenty thousand characters on each side is four hundred million cells — it exhausts memory and then hangs the tab. String comparison is for short text anyway: typos, names, single-line identifiers. Pasting two long documents here usually means the wrong tool, so past 5,000 characters the tool says so rather than freezing.
Why two lines for the input?
Because one text box holds one string. The second could live in an option field, but comparing strings is a process of trying things, and having to leave the input area on every change is painful. The cost is that a string cannot contain a newline — a deliberate trade: the algorithms handle multi-line strings perfectly well, but “character number N” stops being pointable in the interface.

Related tools