Sign in with
Sign up | Sign in
Your question
Solved

C# - Checking Output against english dictionary

Last response: in Applications
Share
January 6, 2011 1:48:30 AM

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!
a b L Programming
January 6, 2011 7:22:43 AM

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....
m
0
l
January 6, 2011 7:57:00 AM

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.
m
0
l
a b L Programming
January 6, 2011 8:02:54 AM

I was thinking of a standalone solution, but if online checking is acceptable then this thread may contain a few ideas of interest.
m
0
l
January 6, 2011 8:31:20 AM

Ijack said:
I was thinking of a standalone solution, but if online checking is acceptable then this thread may contain a few ideas of interest.


I just didn't see the OP specify, so figured it was a viable solution :D 
m
0
l
January 6, 2011 2:34:26 PM

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?
m
0
l

Best solution

a b L Programming
January 6, 2011 3:30:47 PM

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.
Share
January 6, 2011 4:06:41 PM

each word is listed on a single line in the text file, should i use carriage return or line feed with string.split?
m
0
l
a b L Programming
January 6, 2011 6:06:20 PM

If each word is on a single line then ReadLine should just read the word into a String. Exactly what you want!
m
0
l
January 6, 2011 8:28:59 PM

thanks ijack, i got it to work
m
0
l
January 6, 2011 8:29:22 PM

Best answer selected by jefe323.
m
0
l
!