ffi-hunspell 0.2.6 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +14 -0
- data/ChangeLog.md +8 -0
- data/README.md +3 -10
- data/ffi-hunspell.gemspec +38 -105
- data/gemspec.yml +5 -3
- data/lib/ffi/hunspell/dictionary.rb +28 -13
- data/lib/ffi/hunspell/hunspell.rb +2 -0
- data/spec/dictionary_spec.rb +28 -8
- metadata +8 -9
data/.travis.yml
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
language: ruby
|
2
|
+
before_install:
|
3
|
+
- sudo apt-get install libhunspell-dev hunspell-en-us
|
4
|
+
- gem install ffi rubygems-tasks rspec yard
|
5
|
+
rvm:
|
6
|
+
- 1.9.3
|
7
|
+
- 2.0.0
|
8
|
+
- jruby-19mode
|
9
|
+
- rbx-19mode
|
10
|
+
matrix:
|
11
|
+
allow_failures:
|
12
|
+
- rvm: rbx-18mode
|
13
|
+
- rvm: rbx-19mode
|
14
|
+
script: rake test
|
data/ChangeLog.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.3.0 / 2013-05-01
|
2
|
+
|
3
|
+
* Detect Ubuntu's hunspell directory (`/usr/share/hunspell`).
|
4
|
+
* {FFI::Hunspell::Dictionary#encoding} now returns an `Encoding` object.
|
5
|
+
* Encode Strings returned from {FFI::Hunspell::Dictionary#stem} and
|
6
|
+
{FFI::Hunspell::Dictionary#suggestions} to match the dictionary's native
|
7
|
+
encoding.
|
8
|
+
|
1
9
|
### 0.2.6 / 2013-02-05
|
2
10
|
|
3
11
|
* Removed the env dependency.
|
data/README.md
CHANGED
@@ -2,9 +2,11 @@
|
|
2
2
|
|
3
3
|
* [Source](https://github.com/postmodern/ffi-hunspell)
|
4
4
|
* [Issues](https://github.com/postmodern/ffi-hunspell/issues)
|
5
|
-
* [Documentation](http://rubydoc.info/gems/ffi-hunspell)
|
5
|
+
* [Documentation](http://rubydoc.info/gems/ffi-hunspell/frames)
|
6
6
|
* [Email](postmodern.mod3 at gmail.com)
|
7
7
|
|
8
|
+
[![Build Status](https://secure.travis-ci.org/postmodern/ffi-hunspell.png?branch=master)](https://travis-ci.org/postmodern/ffi-hunspell)
|
9
|
+
|
8
10
|
## Description
|
9
11
|
|
10
12
|
Ruby FFI bindings for [Hunspell][libhunspell].
|
@@ -54,15 +56,6 @@ Suggest alternate spellings for a word:
|
|
54
56
|
|
55
57
|
$ gem install ffi-hunspell
|
56
58
|
|
57
|
-
## Known Issues
|
58
|
-
|
59
|
-
Some Linux distributions do not install the `libhunspell-1.2.so`
|
60
|
-
shared library file, but instead installs `libhunspell-1.2.so.0`.
|
61
|
-
Simply create a symbolic link to the hunspell shared library,
|
62
|
-
so that {FFI::Hunspell} can find the library:
|
63
|
-
|
64
|
-
# ln -s /usr/lib/libhunspell-1.2.so.0 /usr/lib/libhunspell-1.2.so
|
65
|
-
|
66
59
|
## License
|
67
60
|
|
68
61
|
Copyright (c) 2010-2013 Hal Brodigan
|
data/ffi-hunspell.gemspec
CHANGED
@@ -2,126 +2,59 @@
|
|
2
2
|
|
3
3
|
require 'yaml'
|
4
4
|
|
5
|
-
Gem::Specification.new do |
|
6
|
-
|
7
|
-
`git ls-files`.split($/)
|
8
|
-
elsif File.directory?('.hg')
|
9
|
-
`hg manifest`.split($/)
|
10
|
-
elsif File.directory?('.svn')
|
11
|
-
`svn ls -R`.split($/).select { |path| File.file?(path) }
|
12
|
-
else
|
13
|
-
Dir['{**/}{.*,*}'].select { |path| File.file?(path) }
|
14
|
-
end
|
5
|
+
Gem::Specification.new do |gem|
|
6
|
+
gemspec = YAML.load_file('gemspec.yml')
|
15
7
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
when String
|
21
|
-
(files & Dir[paths])
|
22
|
-
end
|
23
|
-
}
|
24
|
-
|
25
|
-
version = {
|
26
|
-
:file => 'lib/ffi/hunspell/version.rb',
|
27
|
-
:constant => 'FFI::Hunspell::VERSION'
|
28
|
-
}
|
29
|
-
|
30
|
-
defaults = {
|
31
|
-
'name' => File.basename(File.dirname(__FILE__)),
|
32
|
-
'files' => files,
|
33
|
-
'executables' => filter_files['bin/*'].map { |path| File.basename(path) },
|
34
|
-
'test_files' => filter_files['{test/{**/}*_test.rb,spec/{**/}*_spec.rb}'],
|
35
|
-
'extra_doc_files' => filter_files['*.{txt,rdoc,md,markdown,tt,textile}'],
|
36
|
-
}
|
37
|
-
|
38
|
-
metadata = defaults.merge(YAML.load_file('gemspec.yml'))
|
39
|
-
|
40
|
-
gemspec.name = metadata.fetch('name',defaults[:name])
|
41
|
-
gemspec.version = if metadata['version']
|
42
|
-
metadata['version']
|
43
|
-
elsif File.file?(version[:file])
|
44
|
-
require File.join('.',version[:file])
|
45
|
-
eval(version[:constant])
|
46
|
-
end
|
47
|
-
|
48
|
-
gemspec.summary = metadata.fetch('summary',metadata['description'])
|
49
|
-
gemspec.description = metadata.fetch('description',metadata['summary'])
|
50
|
-
|
51
|
-
case metadata['license']
|
52
|
-
when Array
|
53
|
-
gemspec.licenses = metadata['license']
|
54
|
-
when String
|
55
|
-
gemspec.license = metadata['license']
|
56
|
-
end
|
57
|
-
|
58
|
-
case metadata['authors']
|
59
|
-
when Array
|
60
|
-
gemspec.authors = metadata['authors']
|
61
|
-
when String
|
62
|
-
gemspec.author = metadata['authors']
|
63
|
-
end
|
8
|
+
gem.name = gemspec.fetch('name')
|
9
|
+
gem.version = gemspec.fetch('version') do
|
10
|
+
lib_dir = File.join(File.dirname(__FILE__),'lib')
|
11
|
+
$LOAD_PATH << lib_dir unless $LOAD_PATH.include?(lib_dir)
|
64
12
|
|
65
|
-
|
66
|
-
|
13
|
+
require 'ffi/hunspell/version'
|
14
|
+
FFI::Hunspell::VERSION
|
15
|
+
end
|
67
16
|
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
17
|
+
gem.summary = gemspec['summary']
|
18
|
+
gem.description = gemspec['description']
|
19
|
+
gem.licenses = Array(gemspec['license'])
|
20
|
+
gem.authors = Array(gemspec['authors'])
|
21
|
+
gem.email = gemspec['email']
|
22
|
+
gem.homepage = gemspec['homepage']
|
74
23
|
|
75
|
-
|
24
|
+
glob = lambda { |patterns| gem.files & Dir[*patterns] }
|
76
25
|
|
77
|
-
|
78
|
-
|
26
|
+
gem.files = `git ls-files`.split($/)
|
27
|
+
gem.files = glob[gemspec['files']] if gemspec['files']
|
79
28
|
|
80
|
-
|
81
|
-
|
29
|
+
gem.executables = gemspec.fetch('executables') do
|
30
|
+
glob['bin/*'].map { |path| File.basename(path) }
|
82
31
|
end
|
32
|
+
gem.default_executable = gem.executables.first if Gem::VERSION < '1.7.'
|
83
33
|
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
gemspec.extra_rdoc_files = metadata['extra_doc_files']
|
88
|
-
end
|
89
|
-
|
90
|
-
gemspec.post_install_message = metadata['post_install_message']
|
91
|
-
gemspec.requirements = metadata['requirements']
|
92
|
-
|
93
|
-
if gemspec.respond_to?(:required_ruby_version=)
|
94
|
-
gemspec.required_ruby_version = metadata['required_ruby_version']
|
95
|
-
end
|
34
|
+
gem.extensions = glob[gemspec['extensions'] || 'ext/**/extconf.rb']
|
35
|
+
gem.test_files = glob[gemspec['test_files'] || '{test/{**/}*_test.rb']
|
36
|
+
gem.extra_rdoc_files = glob[gemspec['extra_doc_files'] || '*.{txt,md}']
|
96
37
|
|
97
|
-
|
98
|
-
|
99
|
-
|
38
|
+
gem.require_paths = Array(gemspec.fetch('require_paths') {
|
39
|
+
%w[ext lib].select { |dir| File.directory?(dir) }
|
40
|
+
})
|
100
41
|
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
when String
|
106
|
-
versions.split(/,\s*/)
|
107
|
-
end
|
108
|
-
}
|
42
|
+
gem.requirements = gemspec['requirements']
|
43
|
+
gem.required_ruby_version = gemspec['required_ruby_version']
|
44
|
+
gem.required_rubygems_version = gemspec['required_rubygems_version']
|
45
|
+
gem.post_install_message = gemspec['post_install_message']
|
109
46
|
|
110
|
-
|
111
|
-
metadata['dependencies'].each do |name,versions|
|
112
|
-
gemspec.add_dependency(name,parse_versions[versions])
|
113
|
-
end
|
114
|
-
end
|
47
|
+
split = lambda { |string| string.split(/,\s*/) }
|
115
48
|
|
116
|
-
if
|
117
|
-
|
118
|
-
|
49
|
+
if gemspec['dependencies']
|
50
|
+
gemspec['dependencies'].each do |name,versions|
|
51
|
+
gem.add_dependency(name,split[versions])
|
119
52
|
end
|
120
53
|
end
|
121
54
|
|
122
|
-
if
|
123
|
-
|
124
|
-
|
55
|
+
if gemspec['development_dependencies']
|
56
|
+
gemspec['development_dependencies'].each do |name,versions|
|
57
|
+
gem.add_development_dependency(name,split[versions])
|
125
58
|
end
|
126
59
|
end
|
127
60
|
end
|
data/gemspec.yml
CHANGED
@@ -1,15 +1,17 @@
|
|
1
1
|
name: ffi-hunspell
|
2
|
-
version: 0.
|
2
|
+
version: 0.3.0
|
3
3
|
summary: FFI bindings for Hunspell
|
4
|
-
description: Ruby FFI bindings for Hunspell spell checker.
|
4
|
+
description: Ruby FFI bindings for the Hunspell spell checker.
|
5
5
|
license: MIT
|
6
6
|
authors: Postmodern
|
7
7
|
email: postmodern.mod3@gmail.com
|
8
|
-
homepage: https://github.com/postmodern/ffi-hunspell
|
8
|
+
homepage: https://github.com/postmodern/ffi-hunspell#readme
|
9
9
|
has_yard: true
|
10
10
|
|
11
11
|
requirements: libhunspell >= 1.2.0
|
12
12
|
|
13
|
+
required_ruby_version: ">= 1.9.1"
|
14
|
+
|
13
15
|
dependencies:
|
14
16
|
ffi: ~> 1.0
|
15
17
|
|
@@ -37,10 +37,8 @@ module FFI
|
|
37
37
|
raise("invalid dic path #{dic_path.inspect}")
|
38
38
|
end
|
39
39
|
|
40
|
-
@ptr = if key
|
41
|
-
|
42
|
-
else
|
43
|
-
Hunspell.Hunspell_create(affix_path,dic_path)
|
40
|
+
@ptr = if key then Hunspell.Hunspell_create_key(affix_path,dic_path,key)
|
41
|
+
else Hunspell.Hunspell_create(affix_path,dic_path)
|
44
42
|
end
|
45
43
|
end
|
46
44
|
|
@@ -59,7 +57,7 @@ module FFI
|
|
59
57
|
# @return [Dictionary]
|
60
58
|
# If no block is given, the open dictionary will be returned.
|
61
59
|
#
|
62
|
-
# @raise [
|
60
|
+
# @raise [ArgumentError]
|
63
61
|
# The dictionary files could not be found in any of the directories.
|
64
62
|
#
|
65
63
|
def self.open(name)
|
@@ -67,7 +65,7 @@ module FFI
|
|
67
65
|
|
68
66
|
Hunspell.directories.each do |dir|
|
69
67
|
affix_path = File.join(dir,"#{name}.#{AFF_EXT}")
|
70
|
-
dic_path
|
68
|
+
dic_path = File.join(dir,"#{name}.#{DIC_EXT}")
|
71
69
|
|
72
70
|
if (File.file?(affix_path) && File.file?(dic_path))
|
73
71
|
dict = self.new(affix_path,dic_path)
|
@@ -83,7 +81,7 @@ module FFI
|
|
83
81
|
end
|
84
82
|
end
|
85
83
|
|
86
|
-
raise("unable to find the dictionary #{name.dump} in any of the directories")
|
84
|
+
raise(ArgumentError,"unable to find the dictionary #{name.dump} in any of the directories")
|
87
85
|
end
|
88
86
|
|
89
87
|
#
|
@@ -99,11 +97,13 @@ module FFI
|
|
99
97
|
#
|
100
98
|
# The encoding of the dictionary file.
|
101
99
|
#
|
102
|
-
# @return [
|
100
|
+
# @return [Encoding]
|
103
101
|
# The encoding of the dictionary file.
|
104
102
|
#
|
105
103
|
def encoding
|
106
|
-
|
104
|
+
@encoding ||= Encoding.const_get(
|
105
|
+
Hunspell.Hunspell_get_dic_encoding(self).gsub('-','_')
|
106
|
+
)
|
107
107
|
end
|
108
108
|
|
109
109
|
#
|
@@ -163,14 +163,14 @@ module FFI
|
|
163
163
|
|
164
164
|
FFI::MemoryPointer.new(:pointer) do |output|
|
165
165
|
count = Hunspell.Hunspell_stem(self,output,word.to_s)
|
166
|
-
ptr
|
166
|
+
ptr = output.get_pointer(0)
|
167
167
|
|
168
168
|
if count > 0
|
169
169
|
stems = ptr.get_array_of_string(0,count)
|
170
170
|
end
|
171
171
|
end
|
172
172
|
|
173
|
-
return stems
|
173
|
+
return stems.map { |word| force_encoding(word) }
|
174
174
|
end
|
175
175
|
|
176
176
|
#
|
@@ -187,14 +187,14 @@ module FFI
|
|
187
187
|
|
188
188
|
FFI::MemoryPointer.new(:pointer) do |output|
|
189
189
|
count = Hunspell.Hunspell_suggest(self,output,word.to_s)
|
190
|
-
ptr
|
190
|
+
ptr = output.get_pointer(0)
|
191
191
|
|
192
192
|
if count > 0
|
193
193
|
suggestions = ptr.get_array_of_string(0,count)
|
194
194
|
end
|
195
195
|
end
|
196
196
|
|
197
|
-
return suggestions
|
197
|
+
return suggestions.map { |word| force_encoding(word) }
|
198
198
|
end
|
199
199
|
|
200
200
|
#
|
@@ -219,6 +219,21 @@ module FFI
|
|
219
219
|
@ptr
|
220
220
|
end
|
221
221
|
|
222
|
+
protected
|
223
|
+
|
224
|
+
#
|
225
|
+
# Encodes a String into the dictionary's encoding.
|
226
|
+
#
|
227
|
+
# @param [String] string
|
228
|
+
# The unencoded String.
|
229
|
+
#
|
230
|
+
# @return [String]
|
231
|
+
# The encoded String.
|
232
|
+
#
|
233
|
+
def force_encoding(string)
|
234
|
+
string.force_encoding(encoding)
|
235
|
+
end
|
236
|
+
|
222
237
|
end
|
223
238
|
end
|
224
239
|
end
|
data/spec/dictionary_spec.rb
CHANGED
@@ -35,6 +35,14 @@ describe Hunspell::Dictionary do
|
|
35
35
|
|
36
36
|
dict.should be_closed
|
37
37
|
end
|
38
|
+
|
39
|
+
context "when given an unknown dictionary name" do
|
40
|
+
it "should raise an ArgumentError" do
|
41
|
+
lambda {
|
42
|
+
subject.open('foo')
|
43
|
+
}.should raise_error(ArgumentError)
|
44
|
+
end
|
45
|
+
end
|
38
46
|
end
|
39
47
|
|
40
48
|
subject { described_class.new(affix_path,dic_path) }
|
@@ -42,7 +50,7 @@ describe Hunspell::Dictionary do
|
|
42
50
|
after(:all) { subject.close }
|
43
51
|
|
44
52
|
it "should provide the encoding of the dictionary files" do
|
45
|
-
subject.encoding.
|
53
|
+
subject.encoding.should == Encoding::ISO_8859_1
|
46
54
|
end
|
47
55
|
|
48
56
|
it "should check if a word is valid" do
|
@@ -55,6 +63,12 @@ describe Hunspell::Dictionary do
|
|
55
63
|
subject.stem('fishing').should == %w[fishing fish]
|
56
64
|
end
|
57
65
|
|
66
|
+
it "should force_encode all strings" do
|
67
|
+
subject.suggest('fishing').all? { |string|
|
68
|
+
string.encoding == subject.encoding
|
69
|
+
}.should be_true
|
70
|
+
end
|
71
|
+
|
58
72
|
context "when there are no stems" do
|
59
73
|
it "should return []" do
|
60
74
|
subject.stem("zzzzzzz").should == []
|
@@ -64,13 +78,19 @@ describe Hunspell::Dictionary do
|
|
64
78
|
|
65
79
|
describe "#suggest" do
|
66
80
|
it "should suggest alternate spellings for words" do
|
67
|
-
subject.suggest('arbitrage').should
|
68
|
-
arbitrage
|
69
|
-
arbitrages
|
70
|
-
arbitrager
|
71
|
-
arbitraged
|
72
|
-
arbitrate
|
73
|
-
]
|
81
|
+
subject.suggest('arbitrage').should include(*[
|
82
|
+
'arbitrage',
|
83
|
+
'arbitrages',
|
84
|
+
'arbitrager',
|
85
|
+
'arbitraged',
|
86
|
+
'arbitrate'
|
87
|
+
])
|
88
|
+
end
|
89
|
+
|
90
|
+
it "should force_encode all strings" do
|
91
|
+
subject.suggest('arbitrage').all? { |string|
|
92
|
+
string.encoding == subject.encoding
|
93
|
+
}.should be_true
|
74
94
|
end
|
75
95
|
|
76
96
|
context "when there are no suggestions" do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-hunspell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-02
|
12
|
+
date: 2013-05-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -75,7 +75,7 @@ dependencies:
|
|
75
75
|
- - ~>
|
76
76
|
- !ruby/object:Gem::Version
|
77
77
|
version: '0.7'
|
78
|
-
description: Ruby FFI bindings for Hunspell spell checker.
|
78
|
+
description: Ruby FFI bindings for the Hunspell spell checker.
|
79
79
|
email: postmodern.mod3@gmail.com
|
80
80
|
executables: []
|
81
81
|
extensions: []
|
@@ -87,6 +87,7 @@ files:
|
|
87
87
|
- .gemtest
|
88
88
|
- .gitignore
|
89
89
|
- .rspec
|
90
|
+
- .travis.yml
|
90
91
|
- .yardopts
|
91
92
|
- ChangeLog.md
|
92
93
|
- LICENSE.txt
|
@@ -100,7 +101,7 @@ files:
|
|
100
101
|
- spec/dictionary_spec.rb
|
101
102
|
- spec/hunspell_spec.rb
|
102
103
|
- spec/spec_helper.rb
|
103
|
-
homepage: https://github.com/postmodern/ffi-hunspell
|
104
|
+
homepage: https://github.com/postmodern/ffi-hunspell#readme
|
104
105
|
licenses:
|
105
106
|
- MIT
|
106
107
|
post_install_message:
|
@@ -112,7 +113,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
112
113
|
requirements:
|
113
114
|
- - ! '>='
|
114
115
|
- !ruby/object:Gem::Version
|
115
|
-
version:
|
116
|
+
version: 1.9.1
|
116
117
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
118
|
none: false
|
118
119
|
requirements:
|
@@ -122,10 +123,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
122
123
|
requirements:
|
123
124
|
- libhunspell >= 1.2.0
|
124
125
|
rubyforge_project:
|
125
|
-
rubygems_version: 1.8.
|
126
|
+
rubygems_version: 1.8.25
|
126
127
|
signing_key:
|
127
128
|
specification_version: 3
|
128
129
|
summary: FFI bindings for Hunspell
|
129
|
-
test_files:
|
130
|
-
- spec/dictionary_spec.rb
|
131
|
-
- spec/hunspell_spec.rb
|
130
|
+
test_files: []
|