Similarity texts

How to compare texts, sort by similarity or greatest commonality?

What you want is called the Levenshtein distance between words.

And how it works in app inventory? Does it compare texts does that?

AI2 does not have a native block for this.

It does, however, have the primitive block you can use if you want to code your own version of this, based on the easy sample programs at

While AI2 does not have a matrix a(i,j) primitive data type, you can simulate one using a dictionary with JOIN(i, ',', j) as a key.

Are you up to coding this?

Here's the AI2 blocks implementation of Levenshtein distance.
Thanks for a fun project.

(Corrected version)
Capture Designer Levenshtein_distance.aia (6.0 KB)

(procedure is draggable)

Why do you have such


and i have only such


The blue button on the JOIN block lets you add extra sockets.

Every block with sockets has a right click option to switch between external and internal sockets.

I chose internal sockets to show the structure of my dictionary keys better.

"Inline Inputs"
Thanks, it was so helpful, I've missed it for a long time ...

Does this (Levenshtein_distance.aia) that the text is treated as a list of characters that can be processed character by character (like in Phyton)?

I am not familiar with Python's character handling or list handling.

In the example I posted, I used the segment() text block to address individual characters within the given strings.

If you prefer to use list blocks instead of text blocks, you can split your input strings at '' (the empty text) to turn strings into lists of characters. Unfortunately, the resulting lists have an extra empty item at slot 1.

I find it easier to use the segment block, and avoid empty strings.

But if a segment picks up characters from the text, then it is possible to add them to the list with a "for each" loop ?

You can split the string on the empty string as mentioned by ABG and check the first value in the list. If it is empty, delete the first value. Whether the first element is empty depends on the android version, if I remember correctly.

Try it.