spell_checker 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README +6 -0
- data/lib/spell_checker/custom.txt +0 -0
- data/lib/spell_checker/dictionary.rb +64 -0
- data/lib/spell_checker/dictionary.txt +43001 -0
- data/lib/spell_checker/spell_checker.rb +27 -0
- data/lib/spell_checker.rb +3 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +1 -0
- data/spec/spell_checker/spell_checker_spec.rb +33 -0
- metadata +81 -0
data/README
ADDED
File without changes
|
@@ -0,0 +1,64 @@
|
|
1
|
+
|
2
|
+
class Dictionary
|
3
|
+
|
4
|
+
end
|
5
|
+
|
6
|
+
|
7
|
+
class MysqlDictionary < Dictionary
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
class TextDictionary < Dictionary
|
12
|
+
require 'ftools'
|
13
|
+
|
14
|
+
def initialize(params={})
|
15
|
+
@params = params
|
16
|
+
if @params[:base_dictionary].nil?
|
17
|
+
@base_file = File.expand_path(File.dirname(__FILE__) + "/dictionary.txt")
|
18
|
+
else
|
19
|
+
@base_file = @params[:base_dictionary]
|
20
|
+
raise "Unable to find base dictionary '#{@params[:base_dictionary]}'" unless File.exist?(@params[:base_dictionary])
|
21
|
+
end
|
22
|
+
if @params[:custom_dictionary].nil?
|
23
|
+
@custom_file = File.expand_path(File.dirname(__FILE__) + "/custom.txt")
|
24
|
+
else
|
25
|
+
@custom_file = @params[:custom_dictionary]
|
26
|
+
raise "Unable to find base dictionary '#{@params[:custom_dictionary]}'" unless File.exist?(@params[:custom_dictionary])
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
def word_exists?( word )
|
31
|
+
unles
|
32
|
+
File.open(@custom_file, "w") unless File.exists?(@custom_file)
|
33
|
+
File.open(@base_file, "w") unless File.exists?(@base_file)
|
34
|
+
|
35
|
+
File.open( @custom_file ) do |io|
|
36
|
+
io.each {|line| line.chomp! ; return true if line == word}
|
37
|
+
end
|
38
|
+
File.open( @base_file ) do |io|
|
39
|
+
io.each {|line| line.chomp! ; return true if line == word}
|
40
|
+
end
|
41
|
+
false
|
42
|
+
end
|
43
|
+
|
44
|
+
def filter_stemmed_words
|
45
|
+
dictionary = []
|
46
|
+
puts "loading stemmed list"
|
47
|
+
File.move (@base_file, File.expand_path(File.dirname(@base_file) + "/original_dictionary.txt"))
|
48
|
+
File.open( File.expand_path(File.dirname(__FILE__) + "/original_dictionary.txt") ) do |io|
|
49
|
+
io.each {|line| puts "loading #{line}"; line.chomp! ; dictionary << line.stem}
|
50
|
+
end
|
51
|
+
|
52
|
+
dictionary.uniq!
|
53
|
+
puts "#{dictionary.length} stemmed words found"
|
54
|
+
|
55
|
+
puts "writing to #{@base_file}"
|
56
|
+
File.open(@base_file, "w") do |io|
|
57
|
+
dictionary.each do |word|
|
58
|
+
io.write(word + "\n")
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|