I want to implement an algorithm in Java to find the nearest similar Strings.
I have station_names in mysql database like - 23 ST, 233 ST, 21 ST, 14 St Times Sq, 24 ST
and if user enters a search string like 23rd station then I should return 23 ST and 233 ST or if user enters like Times Square then result should be 14 St Times Sq.
I found many algorithms on internet but I m confused to which one to use.
Can you please suggest me the best algorithm that can I implement in Java?
Thanks in advance
To answer your question, there is no best algorithm in general, only the one that works best in your specific case.
You will want to define one or more metrics to measure differences between the input and the strings you have in the DB and then sort the results by score (see String metric).
The problem is that the most similar string is not always the closest address. That's why I said you have to define your own metric.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With