PDA

View Full Version : How to use a Dictionary in my Java app?


sdsdsd
07-22-2009, 02:31 AM
Hello, in my Java application, I need to search a long string for some given words which can be singular such as 'loan' or 'city'. However, if the string we are searching contains the plurals such as 'loans' or 'cities' then it should be also a match. Does anyone know any Dictionary library or algorithm that I can use in my program. Thank you.

Fou-Lu
07-22-2009, 03:15 AM
Depends on how flexible you want to be. If you're just looking for singular to plural, most of the time methinks you could use an OR and add an s to you're word (except where special rules apply). In a database query, you could use a LIKE '{singularWord}%' as you're criteria. Assuming that the field is indexed, searching should be relatively easy.

There is an algorithm called levenshtein that allows you to calculate distances between words (yes, it is a distance calculation, seems silly to me). It can be used to create the 'did you mean....' in you're search engines by comparing the submitted word and retreiving a list of 'like' words - ones that calculate to a similar value specified by you're program (ie: +/- 10 for example). I'd suspect it would be useful in this scenario as well since most plurals would calculate to be fairly close to the singular. Sadly I do not have experience in using these algorithms so I cannot tell you how close it would be.

I can tell you that unless you have a dictionary of you're own (either by creation or by using a pre-built one) this is memory intensive. But unless someone has a better idea, I'm thinking this is the best route; dictionaries are only valid if they contain every possible combination, and that I'd suspect would be difficult to find.

sdsdsd
07-27-2009, 08:26 PM
Thank you, but I have heard that there are a lot of Java APIs out there, such as WordNet.
Has anyone used this API? If so, what jar files doe I need to include in my project, and how do I get started. I am lost!!!!