I have a program where I give it a noun and it checks in its database with a table of nouns, to see if that noun is there. That works find for singular nouns. eg. User types, 'What is a tree?' program searches 'tree'.
But for 'What are trees? '
The program will search for 'trees', however the database only stores nouns in singular form, so it will not be found. I was thinking about taking off the last s before I do the search. eg.
if ((searchnoun.charAt(searchnoun.length-1))=== 's')
{ searchnoun = searchnoun.(take off last s);}
however that will not work for nouns that are not plurals that end in 's' such as: Megalosaurus, Stegosaurus, Jesus, mass, bass, physics and quite a lot of others..
I could make a list of words ending in s that are not plurals and search if it is in that list first, if it is do not cut the last 's' off, otherwise do..
And I would do a similar thing for words ending in 'es' unless they are in the list of non-plural words that end in 'es'.
Is there a better way of doing this?
The only way is by creating a database of rules and words, it won't be perfect. Here's one you can use if you're using PHP. http://www.kavoir.com/2011/04/php-class-converting-plural-to-singular-or-vice-versa-in-english.html It's part of a framework but you could extract the information from there even if you're not using PHP.
Unfortunately it's too much code to post here, you'll have to follow the link