spell_check 0.0.1 → 0.0.2
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.
- checksums.yaml +5 -13
- data/lib/spell_check.rb +7 -35
- data/lib/spell_check/version.rb +1 -1
- metadata +7 -7
checksums.yaml
CHANGED
@@ -1,15 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
|
5
|
-
data.tar.gz: !binary |-
|
6
|
-
M2M0MzI4MTU1N2MzMTEwZTEzZTc2YWZmM2I1ZWUxZDNmNmFiNjczYw==
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ce688713ddfae655795ef42d25a7dff3b28589bf
|
4
|
+
data.tar.gz: 2cdcd1423e1ea0ba48262fc9de1a00f4e681c10d
|
7
5
|
SHA512:
|
8
|
-
metadata.gz:
|
9
|
-
|
10
|
-
NmU5NDc1ZjY0MmY1OWI2MGYxYTY2NGJkODIzMDcxNmI1NTE4YWI1MTczN2Q0
|
11
|
-
YWE1YTI5Y2UzM2Q3MDk2Y2IxNDhiNTJlMDMxMzIzZmIwMmRmMDk=
|
12
|
-
data.tar.gz: !binary |-
|
13
|
-
NDJkMjE1ZDM1MmExNjdjYTJiNzcwZDczNTZjNzM5MWM3NzI4MDUyN2E1Njdh
|
14
|
-
MzEzYzVhNzI5MzcyYTRiOTNkZjViYTc0MjUyYjczZjhkZDhlOTVlNDczNzY0
|
15
|
-
NTcwODZkMTBiYzRhNmQ3M2Y1NGQ0OWNiMjFkZTIyMTU0ZDE2Mzg=
|
6
|
+
metadata.gz: 0ede83eda143f02a3fdd5c8a424f29b74109416c53ef3d41dd23344056b90092df571ab0302136c271d98a3c3dddfa2d9a7c0fa909ac5f04e9a8b3a2ace9bb1e
|
7
|
+
data.tar.gz: 06cb4b8abab0a51435ae43532fd22c977fcbff4c4d60c7a5650f6d83837aed127f6c5c1556f9e594d1a5779b82c2b7186275e6a06818bc3961ee8af6501d660c
|
data/lib/spell_check.rb
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
require 'spell_check/version'
|
2
2
|
require 'spell_check/dictionary'
|
3
|
+
require 'levenshtein'
|
3
4
|
|
4
5
|
module SpellCheck
|
5
6
|
|
@@ -18,11 +19,11 @@ module SpellCheck
|
|
18
19
|
word = adjust_case( aWordToCheck )
|
19
20
|
|
20
21
|
# Attempt to see if input word is found before doing regular expression search
|
21
|
-
corrected_word = @dict.find_word
|
22
|
+
corrected_word = @dict.find_word word
|
22
23
|
return corrected_word unless corrected_word.nil?
|
23
24
|
|
24
25
|
# Input word was not found, so try matching regular expression
|
25
|
-
corrected_word = correct_repetitions
|
26
|
+
corrected_word = correct_repetitions word
|
26
27
|
return corrected_word unless corrected_word.nil?
|
27
28
|
|
28
29
|
return not_found
|
@@ -67,7 +68,7 @@ private
|
|
67
68
|
|
68
69
|
# Builds a RegExp object and then matches it against the dictionary values
|
69
70
|
# @param [String] word
|
70
|
-
# @return [
|
71
|
+
# @return [Set]
|
71
72
|
def self.find_reg_ex_matches( word )
|
72
73
|
reg_ex = build_reg_ex word
|
73
74
|
@dict.find_reg_ex_matches reg_ex
|
@@ -89,41 +90,12 @@ private
|
|
89
90
|
# Given a set of words that are possible corrections for the input word, this method compares the corrected words
|
90
91
|
# to the input and returns to closest matching correction using Levenshtein distance.
|
91
92
|
# @param [String] word
|
92
|
-
# @param [
|
93
|
+
# @param [Set] matches
|
94
|
+
# @return [Array]
|
93
95
|
def self.get_best_match( word, matches )
|
94
96
|
lev_array = matches.to_a
|
95
|
-
lev_array.sort! { |x,y|
|
97
|
+
lev_array.sort! { |x,y| Levenshtein.distance(x,word) <=> Levenshtein.distance(y,word)}
|
96
98
|
lev_array.first # lowest number of changes means closest match to original input
|
97
99
|
end
|
98
100
|
|
99
|
-
# The Levenshtein Distance algorithm measures the number of changes required to match two strings. For this reason
|
100
|
-
# it is a good method to compare the similarity of strings. Please note that this code was sourced at
|
101
|
-
# http://stackoverflow.com/questions/16323571/measure-the-distance-between-two-strings-with-ruby
|
102
|
-
# @param [String] s
|
103
|
-
# @param [String] t
|
104
|
-
# @return [Integer]
|
105
|
-
def self.levenshtein_distance(s, t)
|
106
|
-
m = s.length
|
107
|
-
n = t.length
|
108
|
-
return m if n == 0
|
109
|
-
return n if m == 0
|
110
|
-
d = Array.new(m+1) {Array.new(n+1)}
|
111
|
-
|
112
|
-
(0..m).each {|i| d[i][0] = i}
|
113
|
-
(0..n).each {|j| d[0][j] = j}
|
114
|
-
(1..n).each do |j|
|
115
|
-
(1..m).each do |i|
|
116
|
-
d[i][j] = if s[i-1] == t[j-1] # adjust index into string
|
117
|
-
d[i-1][j-1] # no operation required
|
118
|
-
else
|
119
|
-
[ d[i-1][j]+1, # deletion
|
120
|
-
d[i][j-1]+1, # insertion
|
121
|
-
d[i-1][j-1]+1, # substitution
|
122
|
-
].min
|
123
|
-
end
|
124
|
-
end
|
125
|
-
end
|
126
|
-
d[m][n]
|
127
|
-
end
|
128
|
-
|
129
101
|
end
|
data/lib/spell_check/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spell_check
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Solberg, Garrick L
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-09-
|
11
|
+
date: 2014-09-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,9 +38,9 @@ dependencies:
|
|
38
38
|
- - ~>
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
|
-
description:
|
42
|
-
gem will attempt to correct
|
43
|
-
|
41
|
+
description: |-
|
42
|
+
Checks if a word exists in text dictionary. If it does not, this gem will attempt to correct
|
43
|
+
the input by changing repeated characters and case.
|
44
44
|
email:
|
45
45
|
- Garrick.Solberg@gmail.com
|
46
46
|
executables: []
|
@@ -61,12 +61,12 @@ require_paths:
|
|
61
61
|
- lib
|
62
62
|
required_ruby_version: !ruby/object:Gem::Requirement
|
63
63
|
requirements:
|
64
|
-
- -
|
64
|
+
- - '>='
|
65
65
|
- !ruby/object:Gem::Version
|
66
66
|
version: '0'
|
67
67
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
68
68
|
requirements:
|
69
|
-
- -
|
69
|
+
- - '>='
|
70
70
|
- !ruby/object:Gem::Version
|
71
71
|
version: '0'
|
72
72
|
requirements: []
|