PocketMatrix forums

A read-only archive of the PocketMatrix forums (2001–2014). Posting and accounts are closed.

Matching similar strings...

Hi all,

I'm looking for a way to match a series of strings to some text the user selects, and to allow the match function to have a level of similarity when matching.

Basically, the user selects text, press "find similar" and the function should scan a long list of strings to find those that are "similar" the original one. The user could also select the level of similarity (0 to 100%) he wants the result to have.

(btw, user == programmer, not player ;) )

I've made my own function, but it's utter garbage and I just can't keep tweaking it.

Can anyone point me in a good direction? I've searched a bit on google, but all I came up with are discussion on very complex algorithms. I'm looking for some code really.

Thanks!

--Eric
efortier wrote:
Can anyone point me in a good direction? I've searched a bit on google, but all I came up with are discussion on very complex algorithms. I'm looking for some code really.

I cannot give you code (because that would belong to a former employer), but what might you get started is an approach based on n-grams:

Basically, you create a window of n characters and slide it over your strings. After computation of all n-character sequences created in this way, you do a simple set comparison.

I.e. if n is 2, then for "similar" you get

si, im, mi, il, la, ar

assume you want to compare to another string "simulator", i.e. you get

si, im, mu, ul, la, at, to, or

Now you simply compare the overlap between sets of 2-grams (relative count, absolute count). For example, you could say that you found 50% of the 2-grams of "similar" among the ones from "simulator".

You can make this arbitrarily complex by using statistics capturing the relative frequency and relevance of these n-grams.

Hope this gives you an idea...

- HM
A phonetic match would be reasonably trivial, if that would work for your case (i.e. <a href="http://www.creativyst.com/Doc/Articles/SoundEx1/SoundEx1.htm">soundex</a>).