jisho 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +58 -0
- data/Rakefile +10 -0
- data/jisho.gemspec +17 -0
- data/lib/jisho.rb +40 -0
- data/lib/jisho/misspellings.rb +9 -0
- data/lib/jisho/version.rb +3 -0
- data/test/jisho_test.rb +21 -0
- data/test/test_helper.rb +2 -0
- metadata +59 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Erol Fornoles
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# Jisho 辞書
|
2
|
+
|
3
|
+
[Jisho](http://erol.github.com/jisho) is a Ruby wrapper for [Hunspell](http://hunspell.sourceforge.net/).
|
4
|
+
|
5
|
+
## Dependencies
|
6
|
+
|
7
|
+
Jisho requires Hunspell and atleast one dictionary. You can install them on Mac OS X via MacPorts:
|
8
|
+
|
9
|
+
port install hunspell hunspell-dict-en_US
|
10
|
+
|
11
|
+
Or via HomeBrew:
|
12
|
+
|
13
|
+
brew install hunspell
|
14
|
+
|
15
|
+
Debian users can use `apt-get`:
|
16
|
+
|
17
|
+
apt-get install hunspell hunspell-en-us
|
18
|
+
|
19
|
+
## Installation
|
20
|
+
|
21
|
+
Add this line to your application's Gemfile:
|
22
|
+
|
23
|
+
gem 'jisho'
|
24
|
+
|
25
|
+
And then execute:
|
26
|
+
|
27
|
+
$ bundle
|
28
|
+
|
29
|
+
Or install it yourself as:
|
30
|
+
|
31
|
+
$ gem install jisho
|
32
|
+
|
33
|
+
## Usage
|
34
|
+
|
35
|
+
If you're not using Bundler, you will need to require Jisho in your application:
|
36
|
+
|
37
|
+
require 'jisho'
|
38
|
+
|
39
|
+
You can check for misspelled words by calling `Jisho.check`:
|
40
|
+
|
41
|
+
misspellings = Jisho.check 'Thiis sentence has a misspelled word.'
|
42
|
+
|
43
|
+
`Jisho.check` returns an array of hashes, each containing the misspelled word, the row and column where it is located, and the list of suggestions.
|
44
|
+
|
45
|
+
misspellings # => [{:word=>"Thiis", :row=>1, :column=>1, :suggestions=>["Thais", "This", "Thins"]}]
|
46
|
+
|
47
|
+
You can also get the unique set of misspelled words:
|
48
|
+
|
49
|
+
misspellings.words # => ["Thiis"]
|
50
|
+
|
51
|
+
## Contributing
|
52
|
+
|
53
|
+
1. Fork it
|
54
|
+
2. Create your feature branch ( `git checkout -b my-new-feature` )
|
55
|
+
3. Create tests and make them pass ( `rake test` )
|
56
|
+
4. Commit your changes ( `git commit -am 'Added some feature'` )
|
57
|
+
5. Push to the branch ( `git push origin my-new-feature` )
|
58
|
+
6. Create a new Pull Request
|
data/Rakefile
ADDED
data/jisho.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/jisho/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Erol Fornoles"]
|
6
|
+
gem.email = ["erol.fornoles@gmail.com"]
|
7
|
+
gem.description = %q{Ruby wrapper for Hunspell}
|
8
|
+
gem.summary = %q{Ruby wrapper for Hunspell}
|
9
|
+
gem.homepage = "http://erol.github.com/jisho"
|
10
|
+
|
11
|
+
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
14
|
+
gem.name = "jisho"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Jisho::VERSION
|
17
|
+
end
|
data/lib/jisho.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require 'jisho/version'
|
2
|
+
require 'jisho/misspellings'
|
3
|
+
|
4
|
+
module Jisho
|
5
|
+
# Check text for misspelled words.
|
6
|
+
#
|
7
|
+
# misspellings = Jisho.check 'Thiis sentence has a misspelled word.'
|
8
|
+
# misspellings.words # => ["Thiis"]
|
9
|
+
# misspellings.first[:word] # => "Thiis"
|
10
|
+
# misspellings.first[:row] # => 1
|
11
|
+
# misspellings.first[:column] # => 1
|
12
|
+
# misspellings.first[:suggestions] # => ["Thais", "This", "Thins"]
|
13
|
+
|
14
|
+
def self.check(text)
|
15
|
+
misspellings = Jisho::Misspellings.new
|
16
|
+
|
17
|
+
result = IO.popen "hunspell -d en_us", 'r+' do |io|
|
18
|
+
io.write text
|
19
|
+
io.close_write
|
20
|
+
io.read
|
21
|
+
end
|
22
|
+
|
23
|
+
row = 1
|
24
|
+
result.lines do |line|
|
25
|
+
case line
|
26
|
+
when ''
|
27
|
+
row += 1
|
28
|
+
when /^\& (.*?) (\d+) (\d+): (.*)/
|
29
|
+
misspellings << {
|
30
|
+
:word => $1,
|
31
|
+
:row => row,
|
32
|
+
:column => $3.to_i + 1,
|
33
|
+
:suggestions => $4.split(', ')
|
34
|
+
}
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
misspellings
|
39
|
+
end
|
40
|
+
end
|
data/test/jisho_test.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require_relative 'test_helper.rb'
|
2
|
+
|
3
|
+
require 'jisho.rb'
|
4
|
+
|
5
|
+
class JishoTest < MiniTest::Unit::TestCase
|
6
|
+
def test_jisho_check_returns_misspelled_words
|
7
|
+
misspellings = Jisho.check 'iincorrect spellingg'
|
8
|
+
|
9
|
+
refute_empty misspellings
|
10
|
+
assert_includes misspellings.words, 'iincorrect'
|
11
|
+
assert_includes misspellings.words, 'spellingg'
|
12
|
+
end
|
13
|
+
|
14
|
+
def test_jisho_check_ignores_non_misspelled_words
|
15
|
+
misspellings = Jisho.check 'correct spelling'
|
16
|
+
|
17
|
+
assert_empty misspellings
|
18
|
+
refute_includes misspellings.words, 'correct'
|
19
|
+
refute_includes misspellings.words, 'spelling'
|
20
|
+
end
|
21
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,59 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jisho
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Erol Fornoles
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-04-21 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby wrapper for Hunspell
|
15
|
+
email:
|
16
|
+
- erol.fornoles@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- Gemfile
|
23
|
+
- LICENSE
|
24
|
+
- README.md
|
25
|
+
- Rakefile
|
26
|
+
- jisho.gemspec
|
27
|
+
- lib/jisho.rb
|
28
|
+
- lib/jisho/misspellings.rb
|
29
|
+
- lib/jisho/version.rb
|
30
|
+
- test/jisho_test.rb
|
31
|
+
- test/test_helper.rb
|
32
|
+
homepage: http://erol.github.com/jisho
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.17
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Ruby wrapper for Hunspell
|
56
|
+
test_files:
|
57
|
+
- test/jisho_test.rb
|
58
|
+
- test/test_helper.rb
|
59
|
+
has_rdoc:
|