spellchecker 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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2010 RedBeard Tech
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markup ADDED
@@ -0,0 +1,35 @@
1
+ # Spellchecker
2
+
3
+ A simple gem which wraps the Aspell command line utility to provide spell checking in ruby.
4
+
5
+ ## Features
6
+
7
+ * Supports all dictionaries supported by [Aspell](ftp://ftp.gnu.org/gnu/aspell/dict/0index.html). Defaults to English.
8
+ * Provides suggested spellings for misspelled words.
9
+
10
+ ## Usage
11
+
12
+ Spellchecker only has one method:
13
+
14
+ Spellchecker.check(text, dictionary='en')
15
+
16
+ The `check` method returns an array of hashes representing the words passed in with the initial string. Here's an example:
17
+
18
+ text_to_check = 'Theis sentence has many speling mistackes'
19
+
20
+ results = Spellchecker.check(text_to_check)
21
+
22
+ results[0] => { :original => 'Theis', :correct => false, :suggestions => ["The-is", "Theirs", "This"] }
23
+ results[1] => { :original => 'sentence', :correct => true }
24
+
25
+ ## Note on Patches/Pull Requests
26
+
27
+ * Fork the project.
28
+ * Make your feature addition or bug fix.
29
+ * Commit.
30
+ * Add tests if applicable. That way we won't break anything.
31
+ * Send me a pull request.
32
+
33
+ ## Copyright
34
+
35
+ Copyright (c) 2010 RedBeard Tech. See LICENSE for details.
@@ -0,0 +1,25 @@
1
+ class Spellchecker
2
+ require 'net/https'
3
+ require 'uri'
4
+ require 'rexml/document'
5
+
6
+ ASPELL_WORD_DATA_REGEX = Regexp.new(/\&\s\w+\s\d+\s\d+(.*)$/)
7
+ ASPELL_PATH = "aspell"
8
+
9
+ def self.check(text, lang='en')
10
+ spell_check_response = `echo "#{text}" | #{ASPELL_PATH} -a -l #{lang}`
11
+ unless spell_check_response == ''
12
+ response = text.split(' ').collect { |original| {:original => original} }
13
+ spell_check_response.split("\n").slice(1..-1).each_with_index do |error, index|
14
+ if match_data = error.match(ASPELL_WORD_DATA_REGEX)
15
+ response[index].merge!(:correct => false, :suggestions => error.split(',')[1..-1].collect(&:strip!))
16
+ else
17
+ response[index].merge!(:correct => true)
18
+ end
19
+ end
20
+ return response
21
+ else
22
+ raise 'Aspell command not found'
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module Spellchecker #:nodoc
2
+ VERSION = "0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: spellchecker
3
+ version: !ruby/object:Gem::Version
4
+ hash: 9
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ version: "0.1"
10
+ platform: ruby
11
+ authors:
12
+ - RedBeard Tech
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-10 00:00:00 -06:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A simple ruby gem to provide basic spell checking and recommendations. Wraps the Aspell command line utility.
22
+ email:
23
+ - mhodgson@redbeard-tech.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/spellchecker/version.rb
32
+ - lib/spellchecker.rb
33
+ - README.markup
34
+ - LICENSE
35
+ has_rdoc: true
36
+ homepage: http://github.com/redbeard-tech/spellchecker
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ hash: 3
50
+ segments:
51
+ - 0
52
+ version: "0"
53
+ required_rubygems_version: !ruby/object:Gem::Requirement
54
+ none: false
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ hash: 23
59
+ segments:
60
+ - 1
61
+ - 3
62
+ - 6
63
+ version: 1.3.6
64
+ requirements: []
65
+
66
+ rubyforge_project:
67
+ rubygems_version: 1.3.7
68
+ signing_key:
69
+ specification_version: 3
70
+ summary: A simple ruby spellchecking gem.
71
+ test_files: []
72
+