dictionary

I抦 new to Java and I need some helpProblem:I have the user of the program enter in a word and I want to check that this word is in the English dictionary. Does anyone know a solution to this?Any help would be appreciated.
[257 byte] By [stephencushen] at [2007-9-27 20:39:24]
# 1
Do you have the dictionnary yet or do you have to make it yourself?If you have the dictionnary, how are the data sored?(xml, a text file with delimiters,...)You must give more information to get a good answer.
myavuzselim at 2007-7-7 1:53:26 > top of Java-index,Other Topics,Java Game Development...
# 2

I would do the next thing :

(I don't say that it's the best way. I'm not an experienced programmer too).

1. Make a program that reads from file(file1) all the words(with space, comma,... as delimiter) and stores them in an arraylist 'words'.

It would read from another dictionnary file(file2) all the words too (with | as delimiter) and stores the words in an arraylist 'dictionary'. (For the first time, dictionary would be empty.)

Then the program would add the words from 'words' to 'dictionary' in an alfabetically way.

Finally it stores the words in 'dictionary' to the file2 with | as delimiter).

2. Make another program that reads the words in file2 and stores them in an arraylist. Then ask the user a word and compare it with the words in the arraylist.

Adding new words in the dictionary would then be simple. Symply copy an English article from an html page, paste it to a text file and run program1.

But maybe you'll get better answers from more experienced programmers.

myavuzselim at 2007-7-7 1:53:26 > top of Java-index,Other Topics,Java Game Development...
# 3
Or use a hashtable. That would be a lot faster for lookup.m
wywiwyg at 2007-7-7 1:53:26 > top of Java-index,Other Topics,Java Game Development...
# 4

There are two general approaches.

1) As myavuzselim suggested, you can load your entire dictionary into data structures in memory, and do your lookups in-memory. The advantage of this approach is that it's very simple, and should be very quick. The disadvantage is that a large dictionary would take up a lot of memory.

The data structure and lookup algorithm you choose can have a significant impact on performance. If you have 10,000,000 elements, one algorithm might actually test all 10,000,000 elements, another might test 10 elements, and another might just between 1 and 3. If you are interested in this, you should pick up a good book on algorithms and data structures. But for a quick suggestion, I would suggest you take a look at java.util.HashSet.

2) You can keep your dictionary on disk, and do your lookups by searching through the file. This saves you from keeping the entire dictionary in memory, but the trade-off is that disk access is much, much slower than memory access. If the data on disk is structured well, it can be sufficiently fast. The discussion above concerning performance applies here as well, but the running time will be magnified by a few orders of magnitude.

Writing a good disk-based structure is a bit of work. Fortunately, you don't have to write one, as this is the purpose of database programs. Databases are designed for quick searching.

A database approach would require a little extra work in configuration. You would need to install the database software, (for example, MySQL) and get the appropriate JDBC driver which allows java to talk to your database (for MySQL, you can use mm.mysql-2.0.4-bin.jar). You should do some research (read books or search online) regarding:

SQL (a standard language for querying databases)

JDBC (Java APIs for talking to databases)

Good luck,

Jim

JN_ at 2007-7-7 1:53:26 > top of Java-index,Other Topics,Java Game Development...