-
Notifications
You must be signed in to change notification settings - Fork 101
/
common-misspellings.rb
58 lines (41 loc) · 1.12 KB
/
common-misspellings.rb
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# coding: utf-8
class CommonMisspellings
#pp CommonMisspellings.misspelling("zebra")
# wich->which, witch
# ENABLE_REVERSE_MISPELLING allows the reverse,
# which -> wich
# should work - accension->accession, ascension
# need to read this in a relative location
# needs to be "installable"
$ENABLE_REVERSE_MISPELLING = true
@@file_contents=File.readlines($LOAD_PATH.first + "/common-misspellings.txt").delete_if { |line| line =~ /^#/ or line =~ /^[ ]*$/ }.join
def self.dictionary
setup unless defined? @@dictionary
@@dictionary
end
def self.misspelling(w)
setup unless defined? @@dictionary
@@dictionary[w]
end
private
def self.setup
@@dictionary={}
words_hash = @@file_contents.split("\n").map do |line|
line.downcase!
y = line.split("->")
[y[1],y[0]]
end
words_hash.map do |words,misspelling|
words.split(',').each do |word|
word.strip!
@@dictionary[word] = misspelling
# need to expand this into a matrix
#
# wich->which, witch
# which->wich
# which->witch
@@dictionary[misspelling] = word if $ENABLE_REVERSE_MISPELLING
end
end
end
end