[x]
Posted via EE Mobile

Search, ask, and monitor your questions on the go with EE Mobile. Visit Experts Exchange from your mobile device and never be out of touch again.

09/26/2009 at 10:51AM PDT, ID: 24764198 | Points: 500
[x]
Attachment Details

Ruby Spell Checker

Asked by uncwlk in Ruby Scripting Language, RubyOnRails, Algorithms

I'm constructing a spell checker using Ruby.  New to the language as of yesterday so bare with me.  I'm reading in a dictionary file and storing words line by line.  I've also got another file that I plan to use to "spell check."  I read this file in using a hash table.  I've constructed a binary search algorithm to search for my keys against the dictionary.  How can I access my array and hash table variables in order to pass them to my binary search algorithm?
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
if __FILE__ == $0
  
def loadDictionary()
  #Stores each line from file into an array
  dictionary = File.open("a7.txt", "r")
    lines = dictionary.readlines
      lines.each do|line|
      #puts "I read this line: #{line}"
      
  ##### Reads in file and prints line by line #####    
  #count = 1
  #dictionary = File.new("a7.txt", "r")
  #while(line = dictionary.gets)
    #puts "#{count}: #{line}"
    #count = count + 1
  #end
  
  end
end
 
  def loadFile(fileName)
  hashTable = {}
  File.open(fileName) do |processFile|
    processFile.each do |line|
      key, value = line.chomp.split("\t")
      hashTable[key] = value
      
    end
  end
end
 
 
loadFile("FCTVacationSpecials1.txt")
 
 
end
Attachments:
 
File to be spell checked
 
 
Dictionary
 
[+][-]10/18/09 09:19 AM, ID: 25600332

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 30-day free trial to view this Expert Comment or ask the Experts your question.

 
 
Loading Advertisement...
20091111-EE-VQP-91 - Hierarchy / EE_QW_3_20080625