Java-Gaming.org    
Featured games (79)
games approved by the League of Dukes
Games in Showcase (475)
Games in Android Showcase (106)
games submitted by our members
Games in WIP (530)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
 
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Spell checker dictionary for a game  (Read 1546 times)
0 Members and 1 Guest are viewing this topic.
Offline trvcic

Senior Newbie





« Posted 2012-12-12 03:42:12 »

I'm making the board game boggle, and have finished almost all the code portion. However, the one thing I am lacking is a a dictionary to see if a string is actually a word. Basically, i want to make a method that, given a string, will iterate through a text file and see if it is there. I have tried spell checkers like jazzy, and they are not what I want. If anyone would help me with this, that would be awesome.

while(true) { be awesome; }
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #1 - Posted 2012-12-12 03:49:59 »

1  
2  
3  
4  
5  
6  
7  
8  
9  
10  
11  
12  
13  
14  
15  
16  
17  
public boolean isWord(String word)
{
   //JAVA == 7
  BufferedReader reader = new BufferedReader(new InputStreamReader(Files.newInputStream(Paths.get("path/to/file.txt"), StandardOpenOption.READ)));

   //JAVA <= 6
  BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream("path/to/file.txt")));

   String line;

   while((line = in.readLine()) != null)
   {
      if(word == line)
         return true;
   }
   return false;
}


EDIT:

Changed method. Before it was loading all the words into an arraylist for storage in RAM instead of just checking the file for the word.

Offline davedes
« Reply #2 - Posted 2012-12-12 04:08:00 »

Seems inefficient to open and traverse through each character in a huge dictionary file, looking for line breaks, and then again to see if the word matches. Also, don't use '==' to compare strings; instead use equals() or for this purpose equalsIgnoreCase().

Using a hash map is probably better; word lists are not incredibly massive in filesize anyways and since you're working on a word game you'll probably need to spellcheck a lot.

Also check out this for ideas on "corrections":
http://norvig.com/spell-correct.html

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline HeroesGraveDev

JGO Kernel


Medals: 238
Projects: 11
Exp: 2 years


┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻


« Reply #3 - Posted 2012-12-12 04:10:57 »

Seems inefficient to open and traverse through a huge dictionary file for each word.

Some other suggestions:
- Compile all unique words (ignore case), run through the file once checking each word, update your text field with errors.
- You could also store the words in a hash map in memory; most word lists are only a couple mb. This would be a lot more efficient and probably worth thinking about since you're working on a word game (presumably lots of spell checks).

Also check out this for ideas on "corrections":
http://norvig.com/spell-correct.html

Yes, but think of the memory it would take up if you loaded ALL the words into RAM. Shocked
I just gave the code he asked for. He can decide what to do in the end. Pointing
(if that comment was for the OP, and not me, never mind  Smiley)

@OP:

I recommend you do some culling on the words, because in boggle, not all words are possible, so take out all the ones that aren't neccessary, and see how many are left.

Whether you load them into RAM or go through a file, is up to you.
If you hit performance issues, rethink your design.

Offline trvcic

Senior Newbie





« Reply #4 - Posted 2012-12-12 04:19:27 »

thanks for the suggestions, but I was actually look for a text file of some such. I guess I should have been clearer. I just don't want to have to rewrite the entire English language.

while(true) { be awesome; }
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #5 - Posted 2012-12-12 04:44:19 »

I compiled a dictionary file a while back....enjoy!

Offline trvcic

Senior Newbie





« Reply #6 - Posted 2012-12-12 04:56:35 »

ra4king thank you so much! this is perfect! Grin

while(true) { be awesome; }
Offline Best Username Ever

Junior Member





« Reply #7 - Posted 2012-12-12 05:34:02 »

Coincidentally I recently thought about implementing Boggle or something similar just for the fun of it. It looks like their are structures designed for spell checking which mainly try to be compact and structures used for solving word game puzzles which try to enable fast search operations other than binary "is it in the list?" questions. Word lists are the simplest and most obvious answer, though.

Though it didn't come up and isn't what I was looking for, here are some simple improvements you could make. 1) Compress the file and read it using GZIPInputStream. (Probably won't save nearly as much space as you could with complex structures, but it's only one extra line.) 2) Create an index file with fewer words so that you can seek somewhere in the middle of a file and find the result sooner. (If it's not all in memory where you can use a binary search.) This is like the top of the page in a dictionary where it shows the first and last word on each page or the tabs with letter labels on them for large dictionaries.



Also, two possible vocabulary clarifications for everyone. You should say "word list" and not "dictionary". Word lists are simply files that contain one word per line. Dictionaries tend to refer to things that include extra data besides the words themselves or files that have words with the same root grouped together. I guess that's why some people call maps dictionaries, though word lists don't have a Java analog.

And avoid "spell check" if you're just looking for whether a word exists. Spell check implies spelling corrections. Stare Although I don't know what you should use instead. "Word check" maybe?
Offline GabrielBailey74
« Reply #8 - Posted 2012-12-12 06:19:57 »

I compiled a dictionary file a while back....enjoy!
'computer freezes while attempting to scroll down'
 Emo Emo

Offline trvcic

Senior Newbie





« Reply #9 - Posted 2012-12-12 07:26:44 »

i had the same problem for a while, it depends on what your using. notepad, word, other text editors should work fine. eclipse or anything that else won't be able to handle it. try dividing up the data also, like certain letters in one file.

while(true) { be awesome; }
Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline pjt33
« Reply #10 - Posted 2012-12-12 08:55:47 »

I compiled a dictionary file a while back....enjoy!
More details? Give us a reason to believe it's a good list!

Word lists with a bit of background and a licence which clearly allows their use include EOWL and 12dict. If you have good enough lawyers to take on Hasbro, you could also try to get hold of a SOWPODS or TWL file.

I don't know why some people think that a word list is too big to hold in RAM. We're talking 1 to 3 megabytes here, which is less than the memory required for a back buffer for a 1024x768 image at 32-bit depth. I hold that the most appropriate data structure for checking whether something is a word is a trie. You might want to generate it as a pre-processing step and serialise it to a file.
Offline ra4king

JGO Kernel


Medals: 336
Projects: 2
Exp: 5 years


I'm the King!


« Reply #11 - Posted 2012-12-13 04:41:42 »

I compiled a dictionary file a while back....enjoy!
More details? Give us a reason to believe it's a good list!

Word lists with a bit of background and a licence which clearly allows their use include EOWL and 12dict. If you have good enough lawyers to take on Hasbro, you could also try to get hold of a SOWPODS or TWL file.

I don't know why some people think that a word list is too big to hold in RAM. We're talking 1 to 3 megabytes here, which is less than the memory required for a back buffer for a 1024x768 image at 32-bit depth. I hold that the most appropriate data structure for checking whether something is a word is a trie. You might want to generate it as a pre-processing step and serialise it to a file.
Ah yeah that text file is a compilation of 12dict and others (I noticed some words missing from 12dict). I then wrote a program that removed duplicates and sorted them, so don't worry Tongue

Pages: [1]
  ignore  |  Print  
 
 
You cannot reply to this message, because it is very, very old.

 

Add your game by posting it in the WIP section,
or publish it in Showcase.

The first screenshot will be displayed as a thumbnail.

ctomni231 (33 views)
2014-07-18 06:55:21

Zero Volt (29 views)
2014-07-17 23:47:54

danieldean (24 views)
2014-07-17 23:41:23

MustardPeter (26 views)
2014-07-16 23:30:00

Cero (41 views)
2014-07-16 00:42:17

Riven (43 views)
2014-07-14 18:02:53

OpenGLShaders (31 views)
2014-07-14 16:23:47

Riven (30 views)
2014-07-14 11:51:35

quew8 (29 views)
2014-07-13 13:57:52

SHC (65 views)
2014-07-12 17:50:04
HotSpot Options
by dleskov
2014-07-08 03:59:08

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:58:24

Java and Game Development Tutorials
by SwordsMiner
2014-06-14 00:47:22

How do I start Java Game Development?
by ra4king
2014-05-17 11:13:37

HotSpot Options
by Roquen
2014-05-15 09:59:54

HotSpot Options
by Roquen
2014-05-06 15:03:10

Escape Analysis
by Roquen
2014-04-29 22:16:43

Experimental Toys
by Roquen
2014-04-28 13:24:22
java-gaming.org is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑gaming.org
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!