0

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?

Lindsay W
  • 43
  • 7
  • I think there are too many "rules" in the English language to have a central way of doing this. Maybe I'm wrong... – Ian Jan 08 '13 at 06:26
  • @Ian, you're not wrong, it probably won't be perfect, but if you look at the link on my answer, you'll see it covers most cases. – Ruan Mendes Jan 08 '13 at 06:30

1 Answers1

1

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

Ruan Mendes
  • 90,375
  • 31
  • 153
  • 217
  • Thanks for that. The function Inflector::singularize looks like it would do the job. I pass the variable to a php file so I may be able to do it from there. That function looks like it covered all the rules, which I left out in my question. – Lindsay W Jan 08 '13 at 06:34