2

I am using java 8 and I am trying to implement an algorithm to try to find the correct name in a list or else, the closest name.

For example :

**Name**  
Smith Johnson Williams Brown

**Lists of names**
Johnson 
Johnson Williams Brown
Smith Johnson Brown Williams
Smith Johnson
Smith Williams Brown Johnson

In this case, the algorithm must return "Smith Johnson Brown Williams" because of the order of the strings.

Of course if we add "Smith Johnson Williams Brown" to the list of names, it will return only this name, but if it's not present, we have to return the closest name regarding the order.

Can any one help on this please?

Thank you.

help me code
  • 149
  • 2
  • 13
  • 1
    I think you should first make an effort to implement the algorithm yourself, and if you are having any issues in you code you can ask the query here. – Digsb Oct 28 '21 at 09:42
  • https://stackoverflow.com/questions/327513/fuzzy-string-search-library-in-java – JonR85 Oct 28 '21 at 09:54

1 Answers1

1

Levenshtein algorithm allows you to compare the similarity between two strings, returning an integer. Levenshtein counts the number of edits (insertions, deletions, or substitutions) needed to convert one string to the other.

Another algorithm which can be usefull is Jaro-Winkler algorithm.

More details : Difference between Jaro-Winkler and Levenshtein distance?

You can also find some implementations of these algorithms on internet in java.

Florian S.
  • 280
  • 2
  • 5