|
[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. |
|
|
|
|
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
|
20091118-EE-VQP-93 - Hierarchy / EE_QW_3_20080625