String Fuzzy Comparison Function Macro (v11.0.3)

I was needing a macro that returned a "percent similar" value when comparing two strings. This macro achieves that goal.

The reason I needed it was that I have created a "Flash Cards" macro that shows the user images and asks the user to state what the image contains. I wanted the user to be able to be "slightly wrong" and still be judged as being correct. For example, if the user spoke the words "Bahamas" but the correct answer was "The Bahamas", (a more correct name for it) this function would still return a value of 85%, and I could use that information to judge that the user actually gave the correct answer.

There might be ways to trim down this macro a little bit. But it works.

I'm planning to upload my Flash Cards macro, but I'm still adding features.

String Fuzzy Comparison Function Macro (v11.0.3)

String Fuzzy Comparison Function.kmmacros (9.6 KB)

1 Like

This is a solved problem. My advice, use python

Choose your method of matching, then just throw the two strings at it, and the returning value will be the 'confidence' level

1 Like

and without needing to install an appropriate version of a Python interpreter, you could also obtain a Levenshtein distance value for two given strings from a Keyboard Maestro subroutine, defined in terms of an Execute JavaScript for Automation action.

See, for example:

Levenshtein distance – JavaScript – Rosetta Code

See: How similar are two strings ? Levenshtein edit distance - Macro Library - Keyboard Maestro Discourse


It would be great to have one or more examples of that in the macro library forum :innocent:.