-1

Is there a library in Java - that can do a spell check.

I have a ArrayList of Categories - which is a list of Words {Fox,Lion,Wolf,Snake}. This list can be very big.

The program will ask the user to input the "Animal": If the user makes a spelling mistake e.g. inserts "Fix" or "Loin"..

Is there a way to compare the input to the elements of the List and find the closest in similarity and use the corresponding element instead of the misspelled input for the rest of the program.

userDSSR
  • 627
  • 1
  • 8
  • 17

2 Answers2

3

You are probably looking for the Levenshtein Distance between two strings. The distance grows the more dissimilar the strings are.

Apache commons has an implementation: https://commons.apache.org/proper/commons-text/javadocs/api-release/org/apache/commons/text/similarity/LevenshteinDistance.html

Andreas
  • 4,937
  • 2
  • 25
  • 35
0

If it is just a list of animals, then you could write your own code to check if the word is part of the list, it's length, amount of matching characters etc..

Roman Svitukha
  • 1,302
  • 1
  • 12
  • 22