ffi-hunspell 0.2.5 → 0.2.6
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/ChangeLog.md +8 -0
- data/LICENSE.txt +1 -1
- data/README.md +7 -5
- data/gemspec.yml +1 -2
- data/lib/ffi/hunspell/dictionary.rb +7 -3
- data/lib/ffi/hunspell/hunspell.rb +4 -5
- data/spec/dictionary_spec.rb +44 -24
- metadata +2 -18
data/ChangeLog.md
CHANGED
@@ -1,3 +1,11 @@
|
|
1
|
+
### 0.2.6 / 2013-02-05
|
2
|
+
|
3
|
+
* Removed the env dependency.
|
4
|
+
* Check the returned count from `Hunsepll_stem` in
|
5
|
+
{FFI::Hunspell::Dictionary#stem}.
|
6
|
+
* Check the returned count from `Hunspell_suggest` in
|
7
|
+
{FFI::Hunspell::Dictionary#suggest}.
|
8
|
+
|
1
9
|
### 0.2.5 / 2012-05-11
|
2
10
|
|
3
11
|
* Load `libhunspell-1.2.so.0` if `libhunspell-1.2.so` cannot be found.
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -7,7 +7,7 @@
|
|
7
7
|
|
8
8
|
## Description
|
9
9
|
|
10
|
-
Ruby FFI bindings for [Hunspell]
|
10
|
+
Ruby FFI bindings for [Hunspell][libhunspell].
|
11
11
|
|
12
12
|
## Examples
|
13
13
|
|
@@ -47,9 +47,8 @@ Suggest alternate spellings for a word:
|
|
47
47
|
|
48
48
|
## Requirements
|
49
49
|
|
50
|
-
* [libhunspell]
|
51
|
-
* [ffi]
|
52
|
-
* [env](https://github.com/postmodern/env) ~> 0.2
|
50
|
+
* [libhunspell] >= 1.2.0
|
51
|
+
* [ffi] ~> 1.0
|
53
52
|
|
54
53
|
## Install
|
55
54
|
|
@@ -66,6 +65,9 @@ so that {FFI::Hunspell} can find the library:
|
|
66
65
|
|
67
66
|
## License
|
68
67
|
|
69
|
-
Copyright (c) 2010-
|
68
|
+
Copyright (c) 2010-2013 Hal Brodigan
|
70
69
|
|
71
70
|
See {file:LICENSE.txt} for license information.
|
71
|
+
|
72
|
+
[libhunspell]: http://hunspell.sourceforge.net/
|
73
|
+
[ffi]: https://github.com/ffi/ffi
|
data/gemspec.yml
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
name: ffi-hunspell
|
2
|
-
version: 0.2.
|
2
|
+
version: 0.2.6
|
3
3
|
summary: FFI bindings for Hunspell
|
4
4
|
description: Ruby FFI bindings for Hunspell spell checker.
|
5
5
|
license: MIT
|
@@ -12,7 +12,6 @@ requirements: libhunspell >= 1.2.0
|
|
12
12
|
|
13
13
|
dependencies:
|
14
14
|
ffi: ~> 1.0
|
15
|
-
env: ~> 0.2
|
16
15
|
|
17
16
|
development_dependencies:
|
18
17
|
rubygems-tasks: ~> 0.1
|
@@ -19,7 +19,7 @@ module FFI
|
|
19
19
|
# @param [String] affix_path
|
20
20
|
# The path to the `.aff` file.
|
21
21
|
#
|
22
|
-
# @param [String]
|
22
|
+
# @param [String] dic_path
|
23
23
|
# The path to the `.dic` file.
|
24
24
|
#
|
25
25
|
# @param [String] key
|
@@ -165,7 +165,9 @@ module FFI
|
|
165
165
|
count = Hunspell.Hunspell_stem(self,output,word.to_s)
|
166
166
|
ptr = output.get_pointer(0)
|
167
167
|
|
168
|
-
|
168
|
+
if count > 0
|
169
|
+
stems = ptr.get_array_of_string(0,count)
|
170
|
+
end
|
169
171
|
end
|
170
172
|
|
171
173
|
return stems
|
@@ -187,7 +189,9 @@ module FFI
|
|
187
189
|
count = Hunspell.Hunspell_suggest(self,output,word.to_s)
|
188
190
|
ptr = output.get_pointer(0)
|
189
191
|
|
190
|
-
|
192
|
+
if count > 0
|
193
|
+
suggestions = ptr.get_array_of_string(0,count)
|
194
|
+
end
|
191
195
|
end
|
192
196
|
|
193
197
|
return suggestions
|
@@ -1,5 +1,4 @@
|
|
1
1
|
require 'ffi'
|
2
|
-
require 'env'
|
3
2
|
|
4
3
|
module FFI
|
5
4
|
module Hunspell
|
@@ -30,7 +29,7 @@ module FFI
|
|
30
29
|
#
|
31
30
|
|
32
31
|
# The language to default to, if no 'LANG' env variable was set.
|
33
|
-
DEFAULT_LANG = 'en_US'
|
32
|
+
DEFAULT_LANG = ENV.fetch('LANG','en_US.UTF-8').split('.',2).first
|
34
33
|
|
35
34
|
#
|
36
35
|
# The default language.
|
@@ -41,13 +40,13 @@ module FFI
|
|
41
40
|
# @since 0.2.0
|
42
41
|
#
|
43
42
|
def Hunspell.lang
|
44
|
-
@lang ||=
|
43
|
+
@lang ||= DEFAULT_LANG
|
45
44
|
end
|
46
45
|
|
47
46
|
#
|
48
47
|
# Sets the default language.
|
49
48
|
#
|
50
|
-
# @param [String]
|
49
|
+
# @param [String] new_lang
|
51
50
|
# The new language name.
|
52
51
|
#
|
53
52
|
# @return [String]
|
@@ -65,7 +64,7 @@ module FFI
|
|
65
64
|
# Known directories to search within for dictionaries.
|
66
65
|
KNOWN_DIRECTORIES = [
|
67
66
|
# User
|
68
|
-
|
67
|
+
File.join(Gem.user_home,USER_DIR),
|
69
68
|
# Debian
|
70
69
|
'/usr/local/share/myspell/dicts',
|
71
70
|
'/usr/share/myspell/dicts',
|
data/spec/dictionary_spec.rb
CHANGED
@@ -9,48 +9,62 @@ describe Hunspell::Dictionary do
|
|
9
9
|
let(:affix_path) { File.join(Hunspell.directories.last,"#{lang}.aff") }
|
10
10
|
let(:dic_path) { File.join(Hunspell.directories.last,"#{lang}.dic") }
|
11
11
|
|
12
|
-
|
13
|
-
subject
|
12
|
+
describe "#initialize" do
|
13
|
+
subject { described_class }
|
14
|
+
|
15
|
+
it "should create a dictionary from '.aff' and '.dic' files" do
|
16
|
+
dict = subject.new(affix_path,dic_path)
|
14
17
|
dict.should_not be_nil
|
18
|
+
|
19
|
+
dict.close
|
15
20
|
end
|
16
21
|
end
|
17
22
|
|
18
|
-
|
19
|
-
|
20
|
-
dict.should_not be_nil
|
23
|
+
describe "open" do
|
24
|
+
subject { described_class }
|
21
25
|
|
22
|
-
|
23
|
-
|
26
|
+
it "should find and open a dictionary file for a given language" do
|
27
|
+
subject.open(lang) do |dict|
|
28
|
+
dict.should_not be_nil
|
29
|
+
end
|
30
|
+
end
|
24
31
|
|
25
|
-
|
26
|
-
|
27
|
-
|
32
|
+
it "should close the dictionary" do
|
33
|
+
dict = subject.open(lang)
|
34
|
+
dict.close
|
28
35
|
|
29
|
-
|
36
|
+
dict.should be_closed
|
37
|
+
end
|
30
38
|
end
|
31
39
|
|
40
|
+
subject { described_class.new(affix_path,dic_path) }
|
41
|
+
|
42
|
+
after(:all) { subject.close }
|
43
|
+
|
32
44
|
it "should provide the encoding of the dictionary files" do
|
33
|
-
subject.
|
34
|
-
dict.encoding.should_not be_empty
|
35
|
-
end
|
45
|
+
subject.encoding.should_not be_empty
|
36
46
|
end
|
37
47
|
|
38
48
|
it "should check if a word is valid" do
|
39
|
-
subject.
|
40
|
-
|
41
|
-
dict.should_not be_valid('dxg')
|
42
|
-
end
|
49
|
+
subject.should be_valid('dog')
|
50
|
+
subject.should_not be_valid('dxg')
|
43
51
|
end
|
44
52
|
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
describe "#stem" do
|
54
|
+
it "should find the stems of a word" do
|
55
|
+
subject.stem('fishing').should == %w[fishing fish]
|
56
|
+
end
|
57
|
+
|
58
|
+
context "when there are no stems" do
|
59
|
+
it "should return []" do
|
60
|
+
subject.stem("zzzzzzz").should == []
|
61
|
+
end
|
48
62
|
end
|
49
63
|
end
|
50
64
|
|
51
|
-
|
52
|
-
|
53
|
-
|
65
|
+
describe "#suggest" do
|
66
|
+
it "should suggest alternate spellings for words" do
|
67
|
+
subject.suggest('arbitrage').should == %w[
|
54
68
|
arbitrage
|
55
69
|
arbitrages
|
56
70
|
arbitrager
|
@@ -58,5 +72,11 @@ describe Hunspell::Dictionary do
|
|
58
72
|
arbitrate
|
59
73
|
]
|
60
74
|
end
|
75
|
+
|
76
|
+
context "when there are no suggestions" do
|
77
|
+
it "should return []" do
|
78
|
+
subject.suggest("________").should == []
|
79
|
+
end
|
80
|
+
end
|
61
81
|
end
|
62
82
|
end
|
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.2.
|
4
|
+
version: 0.2.6
|
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:
|
12
|
+
date: 2013-02-05 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
@@ -27,22 +27,6 @@ dependencies:
|
|
27
27
|
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: '1.0'
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: env
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '0.2'
|
38
|
-
type: :runtime
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: '0.2'
|
46
30
|
- !ruby/object:Gem::Dependency
|
47
31
|
name: rubygems-tasks
|
48
32
|
requirement: !ruby/object:Gem::Requirement
|