Best string matching algorithm for Java?

I want to implement an algorithm in Java to find the closest similar lines.

I have station_names in mysql database - 23 ST, 233 ST, 21 ST, 14 St Times Sq, 24 ST

and if the user enters a search string, such as the 23rd station , then I must return 23 ST and 233 ST , or if the user enters Times Square, then the result should be 14 St Times Sq .

I found many algorithms on the Internet, but I'm confused about what to use.

Could you offer me the best algorithm that can be implemented in Java?

Thank you in advance

+4
source share
2 answers

To answer your question, there is generally no better algorithm, only one that works best in your particular case.

You want to define one or more indicators to measure the differences between the input and the rows that you have in the database, and then sort the results by the result (see String indicator ).

The problem is that the closest line is not always the closest address. This is why I said that you should define your own indicator.

+2
source

There are many possible ways to do this. For example, you can say that 21 ST closer to 23rd station than 233 ST . You must decide what you want and find an approach that will suit him best.

You may probably need several approaches and then evaluate the results. This is what I would do.

You can test another approach by providing a large set of trial data and finding out which approach (or combination) gives you the maximum success rate.

+1
source

All Articles