C# - Checking Output against english dictionary

jefe323

Distinguished
Feb 14, 2010
89
0
18,590
2
As the title states, I am writing a program that takes a bunch of random letters and turns them into english words. I have gotten the program to output every variation of the inputted letters, but its hard searching through them all for actual english words. How would I go about checking the output against an english dictionary? Any help would be appreciated!
 

Ijack

Distinguished
I would read each line into a String (using StreamReader.ReadLine), or you could even read the whole file (using StreamReader.ReadToEnd) if it's not too big. Then split the String into words (using String.Split) at which point you can do the character-by-character comparison. An alternative would be to just read each character from the file (using StreamReader.Read) and create each word yourself. One thing that you need to be aware of is the possibility of end-of-line breaks (denoted by a hyphen); all depends upon what you know about the input file. In any case, actually extracting the individual words from the text file shouldn't be too difficult.
 

Ijack

Distinguished
First of all you need to store the dictionary somehow. There are a few ways you could do this ranging from a straightforward array to using a database. Probably the most efficient way would be to use some sort of tree structure. The top level nodes which each contain single letters of the alphabet; the second level nodes (up to 26 per first-level node) would contain a single letter which is a possible second letter for a word (so for 'a' there would probably be 26 second-level nodes, for 'q' only one or two), etc. To check a word against the dictionary you just check that the first letter is one of the first-level nodes, the second one of the second-level nodes for that first-level one, etc. That's probably the most efficient way of storing the dictionary for quick searches.

Of course the biggest problem is inputting the dictionary initially....
 

Pyroflea

Distinguished
Mar 18, 2007
341
0
18,930
0
I'm not sure if this is at all doable, but just emptying my brain out on the page. Would it be possible to query a pre-existing database (such as dictionary.com's)? As ijack said, the initial creation of said dictionary would be a pain.
 

Pyroflea

Distinguished
Mar 18, 2007
341
0
18,930
0


I just didn't see the OP specify, so figured it was a viable solution :D
 

jefe323

Distinguished
Feb 14, 2010
89
0
18,590
2
thanks for the input. I got a text document with most if not all the english words listed. Can I search that using something like a StreamReader?
 

Ijack

Distinguished
I would read each line into a String (using StreamReader.ReadLine), or you could even read the whole file (using StreamReader.ReadToEnd) if it's not too big. Then split the String into words (using String.Split) at which point you can do the character-by-character comparison. An alternative would be to just read each character from the file (using StreamReader.Read) and create each word yourself. One thing that you need to be aware of is the possibility of end-of-line breaks (denoted by a hyphen); all depends upon what you know about the input file. In any case, actually extracting the individual words from the text file shouldn't be too difficult.
 
Thread starter Similar threads Forum Replies Date
M Apps General Discussion 2
F Apps General Discussion 7
V Apps General Discussion 1
F Apps General Discussion 1
C Apps General Discussion 2
P Apps General Discussion 5
tarmiricmi Apps General Discussion 15
noyaus Apps General Discussion 2
G Apps General Discussion 0
jpe1701 Apps General Discussion 21
NewsFromHell Apps General Discussion 2
L Apps General Discussion 1
G Apps General Discussion 1
G Apps General Discussion 0
J Apps General Discussion 1
Lutfij Apps General Discussion 0
M Apps General Discussion 4
D Apps General Discussion 2
I Apps General Discussion 1
S Apps General Discussion 1

ASK THE COMMUNITY