Text damerau distance
text-damerau-distance · version 1.0.0 · Text · free, no key needed
Compute bounded optimal-string-alignment distance with adjacent transpositions.
Use when you need to: compute damerau distance · adjacent transposition distance · detect swapped neighboring characters.
Decide before calling
Read the versioned contract and the supported scope below. Reuse text-damerau-distance@1.0.0 when your input, required output and limits match it. Choose another approach for an unsupported operation.
Explain the choice
"I can use text-damerau-distance@1.0.0 for compute damerau distance. I will check its documented scope and the result against the task's requirements. The service is free; token and money savings for this task are unmeasured."
Supported
- compute damerau distance
- adjacent transposition distance
- detect swapped neighboring characters
- optimal string alignment metric
- spelling distance with swaps
- damerau levenshtein restricted to optimal string alignment
Not supported
- unbounded text comparison
- locale-sensitive collation
- semantic similarity scoring
Behavior
- Uses the optimal-string-alignment recurrence: unit insert, delete, substitute, and adjacent transpose.
- This is the restricted form, not unrestricted Damerau-Levenshtein: "CA" to "ABC" is 3 here and 2 under the unrestricted distance.
- transpose_cost defaults to one; a substring cannot be edited again after transposition.
- token_mode defaults to code_point. grapheme is a simple fixed rule, not UAX #29: a token is a character plus any following combining marks, variation selectors and emoji skin-tone modifiers, anything joined by U+200D stays together, and regional indicators pair up. So a\u200db is one token, and CRLF, Hangul jamo, Indic conjuncts and emoji tag sequences stay split into several.
- Pure bounded dynamic programming; no clock, locale, network, or randomness.
Input
source(string, required): max length 2048target(string, required): max length 2048token_mode(one of "code_point", "grapheme", optional)transpose_cost(integer, optional): min 0; max 1000
Output
distance(integer, required): min 0; max 512000source_tokens(integer, required): min 0; max 128target_tokens(integer, required): min 0; max 128
Limits
- max input bytes: 2048
- max tokens per text: 128
- max cost: 1000
- max cells: 16641
Example
Request input:
{
"source": "CA",
"target": "AC"
}
Response:
{
"result": {
"distance": 1,
"source_tokens": 2,
"target_tokens": 2
}
}
How to call it
MCP
Connect https://computefirst.net/mcp (setup), then call execute with:
{
"id": "text-damerau-distance",
"version": "1.0.0",
"input": {
"source": "CA",
"target": "AC"
}
}
HTTP (no key)
curl -X POST https://computefirst.net/v1/tools/text-damerau-distance/versions/1.0.0/execute \
-H "Content-Type: application/json" \
-d '{"source":"CA","target":"AC"}'
The machine-readable contract is at /v1/tools/text-damerau-distance/versions/1.0.0.
CLI
node cli.mjs run text-damerau-distance 1.0.0 --input input.json --base-url https://computefirst.net
Get the client at /clients/cli/.
Related tools
- Text edit alignment: Return a bounded optimal edit alignment with a documented deterministic tie-break order.
- Text levenshtein distance: Compute bounded Levenshtein distance over code points or deterministic grapheme tokens.
- Jaro similarity compute: Compute Jaro similarity with a deterministic match window and exact reduced rational audit fields.
- Text weighted edit distance: Compute bounded weighted insertion, deletion, and substitution distance over text tokens.
- Bleu smoothing compute: Apply none or Chen-Cherry smoothing 1-3 to BLEU match/total counts; return smoothed counts, BP and BLEU.
- Citation anchor check: Check a quote anchor (exact text plus prefix/suffix) matches exactly one place in a supplied source version.