# String Similarity Calculator

> Compares two strings with the Levenshtein edit distance and similarity, Jaro and Jaro–Winkler similarity, the bigram Sørensen–Dice coefficient, the Hamming distance (equal lengths only) and the longest common subsequence length.

- Calculator id: `string-similarity` · Category: Developer & IT (`developer`) · Tool name: `calculate_string_similarity`
- Canonical page: https://tttkmbb.com/developer/string-similarity · This document: https://tttkmbb.com/developer/string-similarity.md · JSON definition: https://tttkmbb.com/developer/string-similarity.json

## Purpose

Compares two strings with the Levenshtein edit distance and similarity, Jaro and Jaro–Winkler similarity, the bigram Sørensen–Dice coefficient, the Hamming distance (equal lengths only) and the longest common subsequence length.

**Use when:** You need a fuzzy-match score for names, deduplication, spell-check suggestions or typo tolerance, or want to compare several similarity metrics on the same pair.

**Do not use when:** You need semantic similarity (embeddings), phonetic matching (Soundex/Metaphone) or strings longer than 2,000 characters.

## Input

| Parameter | Type | Unit | Required | Description |
| --- | --- | --- | --- | --- |
| `text_a` | string |  | required | First string to compare. |
| `text_b` | string |  | required | Second string to compare. |
| `case_sensitive` | boolean |  | optional, default false | When false (default) both strings are lower-cased before comparison. |

## Output

| Field | Type | Unit | Description |
| --- | --- | --- | --- |
| `levenshtein_distance` | integer |  | Minimum number of single-character insertions, deletions or substitutions to turn text_a into text_b. |
| `levenshtein_similarity` | number |  | 1 − distance / max(length_a, length_b), from 0 to 1. |
| `jaro` | number |  | Jaro similarity based on matching characters within a window and transpositions. |
| `jaro_winkler` | number |  | Jaro boosted for a common prefix of up to 4 characters with scaling factor 0.1. |
| `dice_coefficient` | number |  | 2 × shared bigrams / (bigrams_a + bigrams_b), counting repeated bigrams. |
| `hamming_distance` | integer |  | Number of positions with different characters; only defined for strings of equal length (omitted otherwise). |
| `longest_common_subsequence` | integer |  | Length of the longest sequence of characters appearing in both strings in the same order (not necessarily contiguous). |
| `length_a` | integer |  | Code points in text_a. |
| `length_b` | integer |  | Code points in text_b. |

## Formula

`Levenshtein: dynamic programming over insert/delete/substitute cost 1; Jaro = (m/|a| + m/|b| + (m − t)/m) / 3 with m matches within floor(max(|a|,|b|)/2) − 1 and t = transpositions/2; Jaro–Winkler = jaro + ℓ·0.1·(1 − jaro), ℓ = common prefix length ≤ 4; Dice = 2·|bigrams_a ∩ bigrams_b| / (|bigrams_a| + |bigrams_b|)`

Strings are compared by Unicode code point (no normalisation; é as one code point and e + combining accent differ). The Winkler boost is applied for every Jaro value (no 0.7 threshold), matching the Wikipedia definition.

## Data Sources

- Levenshtein distance (Wikipedia) — https://en.wikipedia.org/wiki/Levenshtein_distance (reference, retrieved 2026-09-24)
- Jaro–Winkler distance (Wikipedia) — https://en.wikipedia.org/wiki/Jaro%E2%80%93Winkler_distance (reference, retrieved 2026-09-24)
- Sørensen–Dice coefficient (Wikipedia) — https://en.wikipedia.org/wiki/S%C3%B8rensen%E2%80%93Dice_coefficient (reference, retrieved 2026-09-24)

Data freshness: `static`. Deterministic formula with fixed constants; results never go stale. Inputs supplied by the caller determine the output.

## API

- `GET https://tttkmbb.com/api/v1/calculate/string-similarity?text_a=…&text_b=…`
- `POST https://tttkmbb.com/api/v1/calculate/string-similarity` with JSON body `{"inputs": {…}}`
- Response: unified envelope (`success`, `request`, `result.values`, `result.units`, `sources`, `freshness`, `timestamp`, `next_actions`, `links`); see https://tttkmbb.com/docs/response-format.md
- Schema: https://tttkmbb.com/api/v1/calculators/string-similarity · OpenAPI operationId `calculate_string_similarity` in https://tttkmbb.com/openapi.json
- Authentication: none. Rate limit: fair use, see https://tttkmbb.com/docs/rate-limits.md.

## MCP

- Server: `https://tttkmbb.com/mcp` (Streamable HTTP, JSON-RPC 2.0, no auth)
- Tool:  `run_calculator` with `{"calculator_id": "string-similarity", "inputs": {…}}`

## Example

- kitten vs sitting: inputs `{"text_a":"kitten","text_b":"sitting"}` → `{"levenshtein_distance":3,"levenshtein_similarity":0.5714,"jaro":0.746,"jaro_winkler":0.746,"dice_coefficient":0.3636,"longest_common_subsequence":4}`
- MARTHA vs MARHTA (Winkler's example): inputs `{"text_a":"MARTHA","text_b":"MARHTA","case_sensitive":true}` → `{"jaro":0.9444,"jaro_winkler":0.9611,"levenshtein_distance":2,"hamming_distance":2,"longest_common_subsequence":5}`

```
GET https://tttkmbb.com/api/v1/calculate/string-similarity?text_a=kitten&text_b=sitting
```

## Limitations

You need semantic similarity (embeddings), phonetic matching (Soundex/Metaphone) or strings longer than 2,000 characters. Strings are compared by Unicode code point (no normalisation; é as one code point and e + combining accent differ). The Winkler boost is applied for every Jaro value (no 0.7 threshold), matching the Wikipedia definition. All values are computed from the formula above; no measurement or live data is involved.

## FAQ

**Which metric should I use?**

Levenshtein for typos and edit-based matching, Jaro–Winkler for short names where the beginning matters, Dice for word-level similarity that tolerates reordering; a Jaro–Winkler above about 0.9 usually indicates the same name.

**Why is Hamming distance missing?**

It only exists for strings of equal length; for kitten (6) and sitting (7) it is undefined, so the output is omitted.

**Are the metrics symmetric?**

Yes, all reported metrics give the same value when text_a and text_b are swapped.

## Related

- [Text Hash Calculator](https://tttkmbb.com/developer/text-hash.md) — Exact-match fingerprints instead of fuzzy scores.
- [Percentage Calculator](https://tttkmbb.com/math/percentage.md) — Express a 0–1 similarity score as a percentage.
