Word similarity
FreeLogicHow alike two words are, from 0 to 1, e.g. to suggest "did you mean…?".
The edit distance (Levenshtein) is a nested loop over two strings, which is short in code and long as a graph, so it is a Custom Code node. The rest stays a graph: similarity is 1 − distance / longer length.
Exported code calls deps.code.levenshtein({ a, b }); implement it in your app, for example in TypeScript:
levenshtein: async ({ a, b }) => {
let prev = Array.from({ length: b.length + 1 }, (_, j) => j);
for (let i = 1; i <= a.length; i++) {
const cur = [i];
for (let j = 1; j <= b.length; j++) cur[j] = Math.min(prev[j] + 1, cur[j - 1] + 1, prev[j - 1] + (a[i - 1] === b[j - 1] ? 0 : 1));
prev = cur;
}
return prev[b.length];
}In Python, rapidfuzz.distance.Levenshtein.distance(a, b) gives the same number; in C#, Fastenshtein's Levenshtein.Distance(a, b); in Java, Apache Commons Text's LevenshteinDistance.getDefaultInstance().apply(a, b).
Shows: Custom Code, Maximum, Divide.
Add it to your logic, then add a Call Function step in any logic and pick Word similarity. It belongs to no system, so every system can use it. Or download the TypeScript and call it from your own code.
Arrow keys: next or previous step in flow order. Alt with arrows: nearest step in that direction. Enter: open. Shift F10: more actions.
| Passed | Example | Input | Output |
|---|
