ffi-hunspell 0.5.0 → 0.6.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +37 -0
- data/ChangeLog.md +5 -0
- data/LICENSE.txt +1 -1
- data/README.md +12 -5
- data/lib/ffi/hunspell/dictionary.rb +23 -1
- data/lib/ffi/hunspell/hunspell.rb +13 -0
- data/lib/ffi/hunspell/version.rb +1 -1
- data/spec/dictionary_spec.rb +39 -1
- data/spec/fixtures/extra.dic +2 -0
- metadata +5 -4
- data/.travis.yml +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b29a3ff5f68640f1c8123c5895074ed2d986961a15fd3f8921baf1bd83769831
|
4
|
+
data.tar.gz: fcf088c5e73c7c6dd5ac23db60a8c14c9be58a4dea16e7aa2d0006ed5f019694
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef1c370fd0471c1f50748a6c4775313090b5f676c25ed9976932749149905d80c1c02d574ae8dd553ff7d380ddd7f9b5825f30240ec9f17f45e28ff6e98f2007
|
7
|
+
data.tar.gz: 365cb6e3fb48e17f1303e76cbd0082e57b0d3d5814f8ff7a2c8c0415fcaa1c3287fedd96ad6c0d94fc2e844d459a07556df38bd5ccd64b6f470c8e75bc860236
|
@@ -0,0 +1,37 @@
|
|
1
|
+
name: CI
|
2
|
+
|
3
|
+
on:
|
4
|
+
push:
|
5
|
+
branches: [ master ]
|
6
|
+
pull_request:
|
7
|
+
branches: ['**']
|
8
|
+
|
9
|
+
jobs:
|
10
|
+
tests:
|
11
|
+
runs-on: ubuntu-latest
|
12
|
+
strategy:
|
13
|
+
fail-fast: false
|
14
|
+
matrix:
|
15
|
+
ruby:
|
16
|
+
- 2.4
|
17
|
+
- 2.5
|
18
|
+
- 2.6
|
19
|
+
- 2.7
|
20
|
+
- jruby
|
21
|
+
name: Ruby ${{ matrix.ruby }}
|
22
|
+
steps:
|
23
|
+
- uses: actions/checkout@v2
|
24
|
+
- name: Set up Ruby
|
25
|
+
uses: ruby/setup-ruby@v1
|
26
|
+
with:
|
27
|
+
ruby-version: ${{ matrix.ruby }}
|
28
|
+
- name: Install libhunspell
|
29
|
+
run: |
|
30
|
+
sudo apt update -y && \
|
31
|
+
sudo apt install -y --no-install-recommends --no-install-suggests libhunspell-dev hunspell-en-us
|
32
|
+
- name: Install dependencies
|
33
|
+
run: bundle install --jobs 4 --retry 3
|
34
|
+
- name: Run tests
|
35
|
+
run: bundle exec rake test
|
36
|
+
env:
|
37
|
+
LANG: en_US.UTF-8
|
data/ChangeLog.md
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -5,8 +5,6 @@
|
|
5
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
|
-
|
10
8
|
## Description
|
11
9
|
|
12
10
|
Ruby FFI bindings for [Hunspell][libhunspell].
|
@@ -14,6 +12,7 @@ Ruby FFI bindings for [Hunspell][libhunspell].
|
|
14
12
|
## Examples
|
15
13
|
|
16
14
|
Open a dictionary:
|
15
|
+
|
17
16
|
```rb
|
18
17
|
require 'ffi/hunspell'
|
19
18
|
|
@@ -31,6 +30,7 @@ dict.close
|
|
31
30
|
```
|
32
31
|
|
33
32
|
Check if a word is valid:
|
33
|
+
|
34
34
|
```rb
|
35
35
|
dict.check?('dog')
|
36
36
|
# => true
|
@@ -38,30 +38,37 @@ dict.check?('dog')
|
|
38
38
|
dict.check?('d0g')
|
39
39
|
# => false
|
40
40
|
```
|
41
|
+
|
41
42
|
Find the stems of a word:
|
43
|
+
|
42
44
|
```rb
|
43
45
|
dict.stem('dogs')
|
44
46
|
# => ["dog"]
|
45
47
|
```
|
48
|
+
|
46
49
|
Suggest alternate spellings for a word:
|
50
|
+
|
47
51
|
```rb
|
48
52
|
dict.suggest('arbitrage')
|
49
53
|
# => ["arbitrage", "arbitrages", "arbitrager", "arbitraged", "arbitrate"]
|
50
54
|
```
|
55
|
+
|
51
56
|
## Requirements
|
52
57
|
|
53
|
-
* [libhunspell] >= 1.2.0
|
58
|
+
* [libhunspell] >= 1.2.0, <= 1.7.0
|
54
59
|
* [ffi] ~> 1.0
|
55
60
|
|
56
61
|
## Install
|
62
|
+
|
57
63
|
```sh
|
58
64
|
$ gem install ffi-hunspell
|
59
65
|
```
|
66
|
+
|
60
67
|
## License
|
61
68
|
|
62
|
-
Copyright (c) 2010-
|
69
|
+
Copyright (c) 2010-2020 Hal Brodigan
|
63
70
|
|
64
71
|
See {file:LICENSE.txt} for license information.
|
65
72
|
|
66
|
-
[libhunspell]: http://hunspell.
|
73
|
+
[libhunspell]: http://hunspell.github.io/
|
67
74
|
[ffi]: https://github.com/ffi/ffi
|
@@ -116,6 +116,8 @@ module FFI
|
|
116
116
|
Hunspell.Hunspell_add(self,word.to_s)
|
117
117
|
end
|
118
118
|
|
119
|
+
alias << add
|
120
|
+
|
119
121
|
#
|
120
122
|
# Adds a word to the dictionary with affix flags.
|
121
123
|
#
|
@@ -138,7 +140,27 @@ module FFI
|
|
138
140
|
add_with_affix(word,example)
|
139
141
|
end
|
140
142
|
|
141
|
-
|
143
|
+
#
|
144
|
+
# Load an extra dictionary file. The extra dictionaries use the
|
145
|
+
# affix file of the allocated Hunspell object.
|
146
|
+
#
|
147
|
+
# Maximal number of extra dictionaries is limited in the source code (20)
|
148
|
+
#
|
149
|
+
# @param [String] dic_path
|
150
|
+
# The path to the extra `.dic` file.
|
151
|
+
#
|
152
|
+
# @raise [ArgumentError]
|
153
|
+
# The extra `.dic` file did not exist.
|
154
|
+
#
|
155
|
+
# @since 0.6.0
|
156
|
+
#
|
157
|
+
def add_dic(dic_path)
|
158
|
+
unless File.file?(dic_path)
|
159
|
+
raise(ArgumentError,"invalid extra dictionary path #{dic_path.inspect}")
|
160
|
+
end
|
161
|
+
|
162
|
+
Hunspell.Hunspell_add_dic(self,dic_path)
|
163
|
+
end
|
142
164
|
|
143
165
|
#
|
144
166
|
# Removes a word from the dictionary.
|
@@ -28,6 +28,19 @@ module FFI
|
|
28
28
|
attach_function :Hunspell_remove, [:pointer, :string], :int
|
29
29
|
attach_function :Hunspell_free_list, [:pointer, :pointer, :int], :void
|
30
30
|
|
31
|
+
begin
|
32
|
+
attach_function :Hunspell_add_dic, [:pointer, :string], :int
|
33
|
+
rescue FFI::NotFoundError
|
34
|
+
def self.method_missing(symbol,*arguments,&block)
|
35
|
+
if symbol == :Hunspell_add_dic
|
36
|
+
raise NotImplementedError,
|
37
|
+
"Hunspell_add_dic was not found in [#{ffi_libraries.map(&:name).join(", ")}]. You must install Hunspell 1.3.4 or later if you need this functionality."
|
38
|
+
end
|
39
|
+
|
40
|
+
super
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
31
44
|
#
|
32
45
|
# missing functions:
|
33
46
|
#
|
data/lib/ffi/hunspell/version.rb
CHANGED
data/spec/dictionary_spec.rb
CHANGED
@@ -49,7 +49,7 @@ describe Hunspell::Dictionary do
|
|
49
49
|
after { subject.close }
|
50
50
|
|
51
51
|
it "should provide the encoding of the dictionary files" do
|
52
|
-
expect(subject.encoding).to
|
52
|
+
expect(subject.encoding).to be_instance_of Encoding
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should check if a word is valid" do
|
@@ -57,6 +57,44 @@ describe Hunspell::Dictionary do
|
|
57
57
|
expect(subject.valid?('dxg')).to be false
|
58
58
|
end
|
59
59
|
|
60
|
+
describe "#add_dic" do
|
61
|
+
let(:extra_dic) { File.join(File.dirname(__FILE__),'fixtures/extra.dic') }
|
62
|
+
|
63
|
+
if FFI::Hunspell.respond_to?(:Hunspell_add_dic)
|
64
|
+
context "when libhunspell supports add_dic" do
|
65
|
+
before do
|
66
|
+
subject.add_dic(extra_dic)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "should add an extra dictionary" do
|
70
|
+
expect(subject.add_dic(extra_dic)).to be 0
|
71
|
+
end
|
72
|
+
|
73
|
+
context "when the given extra dictionary file cannot be found" do
|
74
|
+
it do
|
75
|
+
expect { subject.add_dic('foo') }.to raise_error(ArgumentError)
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should validate a word from the extra dictionary" do
|
80
|
+
expect(subject.valid?('dxg')).to be true
|
81
|
+
end
|
82
|
+
|
83
|
+
it "should validate an affixed word based on an affix flag from base affix file" do
|
84
|
+
expect(subject.valid?('dxgs')).to be true
|
85
|
+
end
|
86
|
+
end
|
87
|
+
else
|
88
|
+
context "when libhunspell does not support add_dic" do
|
89
|
+
it "should raise an error" do
|
90
|
+
expect {
|
91
|
+
subject.add_dic(extra_dic)
|
92
|
+
}.to raise_error(NotImplementedError)
|
93
|
+
end
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
|
60
98
|
describe "#add" do
|
61
99
|
it "should add a word" do
|
62
100
|
expect(subject.add('cat')).to be 0
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ffi-hunspell
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Postmodern
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-11-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -48,9 +48,9 @@ extra_rdoc_files:
|
|
48
48
|
- README.md
|
49
49
|
files:
|
50
50
|
- ".gemtest"
|
51
|
+
- ".github/workflows/ruby.yml"
|
51
52
|
- ".gitignore"
|
52
53
|
- ".rspec"
|
53
|
-
- ".travis.yml"
|
54
54
|
- ".yardopts"
|
55
55
|
- ChangeLog.md
|
56
56
|
- Gemfile
|
@@ -64,6 +64,7 @@ files:
|
|
64
64
|
- lib/ffi/hunspell/hunspell.rb
|
65
65
|
- lib/ffi/hunspell/version.rb
|
66
66
|
- spec/dictionary_spec.rb
|
67
|
+
- spec/fixtures/extra.dic
|
67
68
|
- spec/hunspell_spec.rb
|
68
69
|
- spec/spec_helper.rb
|
69
70
|
homepage: https://github.com/postmodern/ffi-hunspell#readme
|
@@ -86,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
87
|
version: '0'
|
87
88
|
requirements:
|
88
89
|
- libhunspell >= 1.2.0, <= 1.7.0
|
89
|
-
rubygems_version: 3.
|
90
|
+
rubygems_version: 3.1.4
|
90
91
|
signing_key:
|
91
92
|
specification_version: 4
|
92
93
|
summary: FFI bindings for Hunspell
|