-1

trying to match a word with some hard coded values, let's say i have this word

'revenue' but 'revenues'

should also be a match.same way like this

 'liability' > 'liabilities' .

what would be the approach we should take here, thanks in advance.

I have tried using my own algorithm but it is very difficult maintain word library and its respective plural or singular.

krsna
  • 41
  • 6

2 Answers2

3

If you don't want to maintain full dictionary, then you might try to implement some general rules plus dictionary of exceptions from those rules. But these are all quick and hacky solutions. Depending on how good must it be, different approaches would also be available like machine learning and maybe some language services available on clouds like AWS or Azure...

Tomasz
  • 988
  • 1
  • 9
  • 23
2

You might want to look at PorterStemmer of lucene. The idea is to compare the stems of both the words instead of comparing singulars and plurals. You can read more about it here.

Here is the maven dependency and below is an example:

PorterStemmer stemmer = new PorterStemmer();
stemmer.setCurrent("liability");
stemmer.stem();
System.out.println(stemmer.getCurrent());

stemmer.setCurrent("liabilities");
stemmer.stem();
System.out.println(stemmer.getCurrent());

The above returns same stems for both the words.

Darshan Mehta
  • 30,102
  • 11
  • 68
  • 102
  • Decent answer but unfortunately, it seems to turn "liabilities" to "liabil" rather than "liability" – Ali May 18 '19 at 07:58