spell_checker 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- 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
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'stemmer'
|
2
|
+
|
3
|
+
class SpellChecker
|
4
|
+
def initialize(params={})
|
5
|
+
|
6
|
+
if params[:type].nil?
|
7
|
+
@dictionary = TextDictionary.new(params)
|
8
|
+
else
|
9
|
+
if params[:type] == :mysql
|
10
|
+
@dictionary = MysqlDictionary.new(params)
|
11
|
+
elsif params[:type] == :text
|
12
|
+
@dictionary = TextDictionary.new(params)
|
13
|
+
else
|
14
|
+
raise "invalid dictionary type #{params[:type]}"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
19
|
+
|
20
|
+
def check_word(word)
|
21
|
+
@dictionary.word_exists?(word.stem)
|
22
|
+
end
|
23
|
+
|
24
|
+
def stem_dictionary
|
25
|
+
@dictionary.filter_stemmed_words
|
26
|
+
end
|
27
|
+
end
|
data/spec/spec.opts
ADDED
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../lib/spell_checker')
|
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../spec_helper')
|
2
|
+
|
3
|
+
describe SpellChecker do
|
4
|
+
|
5
|
+
it "should create a SpellChecker object" do
|
6
|
+
|
7
|
+
SpellChecker.new.should be_an_instance_of SpellChecker
|
8
|
+
|
9
|
+
end
|
10
|
+
|
11
|
+
it "should return true for valid word" do
|
12
|
+
spell = SpellChecker.new
|
13
|
+
spell.check_word("word").should be_true
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should return false for an invalid word" do
|
17
|
+
spell = SpellChecker.new
|
18
|
+
spell.check_word("wordd").should be_false
|
19
|
+
end
|
20
|
+
|
21
|
+
describe "using stemming" do
|
22
|
+
|
23
|
+
it "should return true for plural" do
|
24
|
+
spell = SpellChecker.new
|
25
|
+
spell.check_word("words").should be_true
|
26
|
+
spell.check_word("fishes").should be_true
|
27
|
+
spell.check_word("fishing").should be_true
|
28
|
+
spell.check_word("fished").should be_true
|
29
|
+
spell.check_word("fisher").should be_true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: spell_checker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Stewart McKee
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-05-21 00:00:00 +01:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: stemmer
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
version: "0"
|
30
|
+
type: :runtime
|
31
|
+
version_requirements: *id001
|
32
|
+
description:
|
33
|
+
email: stewart.mckee@vamosa.com
|
34
|
+
executables: []
|
35
|
+
|
36
|
+
extensions: []
|
37
|
+
|
38
|
+
extra_rdoc_files:
|
39
|
+
- README
|
40
|
+
files:
|
41
|
+
- spec/spell_checker/spell_checker_spec.rb
|
42
|
+
- spec/spec.opts
|
43
|
+
- spec/spec_helper.rb
|
44
|
+
- lib/spell_checker/custom.txt
|
45
|
+
- lib/spell_checker/dictionary.rb
|
46
|
+
- lib/spell_checker/dictionary.txt
|
47
|
+
- lib/spell_checker/spell_checker.rb
|
48
|
+
- lib/spell_checker.rb
|
49
|
+
- README
|
50
|
+
has_rdoc: false
|
51
|
+
homepage: http://www.vamosa.com
|
52
|
+
licenses: []
|
53
|
+
|
54
|
+
post_install_message:
|
55
|
+
rdoc_options: []
|
56
|
+
|
57
|
+
require_paths:
|
58
|
+
- lib
|
59
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
60
|
+
requirements:
|
61
|
+
- - ">="
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
segments:
|
64
|
+
- 0
|
65
|
+
version: "0"
|
66
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
segments:
|
71
|
+
- 0
|
72
|
+
version: "0"
|
73
|
+
requirements: []
|
74
|
+
|
75
|
+
rubyforge_project:
|
76
|
+
rubygems_version: 1.3.6
|
77
|
+
signing_key:
|
78
|
+
specification_version: 3
|
79
|
+
summary: Word spell checker
|
80
|
+
test_files: []
|
81
|
+
|