I have to lookup for a word "age" and similar word in a text file.
I have following sentence :
String.contains always return true in each case. My requirement is to pass the first five sentence and it return false in last case.
I will solve this problem by writing some code which contains a bunch of string " age ", " age." , "ages", "aged", " age," etc..
Is there any better way to solve this problem.
If you use regex, you have to put all the possiblities.
string.matches("(?i).*\\bage[ds]?\\b.*");
A naive solution (expensive) would be the following:
The edit distance of two string is the number of edits (additions, deletions and replacements) that are required to make one string equal to the other. You can find an implementation of edit distance in the simmetrics library, or maybe elsewhere, too.
Another option could be to stem the words at step 2 and use contains with the stemming of the word age (also expensive).
If you already know all the acceptable answers (or at least their pattern), go for Avinash Raj's answer.
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