hunspell-ffi 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +29 -0
- data/Rakefile +6 -0
- data/lib/hunspell-ffi.rb +29 -0
- data/test/cakes.aff +0 -0
- data/test/cakes.dic +21 -0
- data/test/test_hunspell.rb +17 -0
- metadata +86 -0
data/README.rdoc
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
= hunspell-ffi
|
2
|
+
|
3
|
+
A Ruby FFI interface to the Hunspell spelling checker
|
4
|
+
|
5
|
+
It should work wherever Ruby FFI works (tested on Ruby 1.9.2, 1.8.7, JRuby 1.5.1).
|
6
|
+
|
7
|
+
== Installation
|
8
|
+
1. Install hunspell (OSX: 'brew install hunspell' Debian: 'apt-get install hunspell')
|
9
|
+
2. gem install hunspell-ffi
|
10
|
+
|
11
|
+
== Usage
|
12
|
+
require 'hunspell-ffi'
|
13
|
+
dict = Hunspell.new("path/to/cakes.aff", "path/to/cakes.dic")
|
14
|
+
dict.spell("Baumkuchen") # => true same as #check
|
15
|
+
dict.spell("Bomcuken") # => false
|
16
|
+
dict.suggest("Baumgurken") # => ["Baumkuchen"]
|
17
|
+
dict.suggest("qwss43easd") # => []
|
18
|
+
|
19
|
+
== Author
|
20
|
+
Andreas Haller
|
21
|
+
andreashaller@gmail.com
|
22
|
+
|
23
|
+
== License
|
24
|
+
Hereby placed under public domain, do what you want, just do not hold me accountable...
|
25
|
+
|
26
|
+
== TODO
|
27
|
+
Add other hunspell methods (add, remove, analyze, stem ...)
|
28
|
+
|
29
|
+
Test on Windows
|
data/Rakefile
ADDED
data/lib/hunspell-ffi.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'ffi'
|
3
|
+
class Hunspell
|
4
|
+
module C
|
5
|
+
extend FFI::Library
|
6
|
+
ffi_lib ['libhunspell', 'libhunspell-1.2', 'libhunspell-1.2.so.0']
|
7
|
+
attach_function :Hunspell_create, [:string, :string], :pointer
|
8
|
+
attach_function :Hunspell_spell, [:pointer, :string], :bool
|
9
|
+
attach_function :Hunspell_suggest, [:pointer, :pointer, :string], :int
|
10
|
+
end
|
11
|
+
|
12
|
+
# TODO RDoc
|
13
|
+
|
14
|
+
def initialize(affpath, dicpath)
|
15
|
+
@handler = C.Hunspell_create(affpath, dicpath)
|
16
|
+
end
|
17
|
+
|
18
|
+
def spell(word)
|
19
|
+
C.Hunspell_spell(@handler, word)
|
20
|
+
end
|
21
|
+
alias_method :check, :spell
|
22
|
+
|
23
|
+
def suggest(word)
|
24
|
+
ptr = FFI::MemoryPointer.new(:pointer, 1)
|
25
|
+
len = Hunspell::C.Hunspell_suggest(@handler, ptr, word)
|
26
|
+
str_ptr = ptr.read_pointer
|
27
|
+
str_ptr.null? ? [] : str_ptr.get_array_of_string(0, len).compact
|
28
|
+
end
|
29
|
+
end
|
data/test/cakes.aff
ADDED
File without changes
|
data/test/cakes.dic
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
20
|
2
|
+
Apfelkuchen
|
3
|
+
Baumkuchen
|
4
|
+
Bienenstich
|
5
|
+
Butterkuchen
|
6
|
+
Donauwelle
|
7
|
+
Eierschecke
|
8
|
+
Guglhupf
|
9
|
+
Hefekuchen
|
10
|
+
Käsekuchen
|
11
|
+
Marmorkuchen
|
12
|
+
Obstkuchen
|
13
|
+
Panettone
|
14
|
+
Pflaumenkuchen
|
15
|
+
Russischer Zupfkuchen
|
16
|
+
Rührkuchen
|
17
|
+
Sandkuchen
|
18
|
+
Schmandkuchen
|
19
|
+
Stollen
|
20
|
+
Streuselkuchen
|
21
|
+
Zwiebelkuchen
|
@@ -0,0 +1,17 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require "test/unit"
|
3
|
+
require File.expand_path(File.dirname(__FILE__)) + '/../lib/hunspell-ffi'
|
4
|
+
class TestHunspell < Test::Unit::TestCase
|
5
|
+
def setup
|
6
|
+
@dict_dir = File.dirname(__FILE__)
|
7
|
+
@dict = Hunspell.new("#{@dict_dir}/cakes.aff", "#{@dict_dir}/cakes.dic")
|
8
|
+
end
|
9
|
+
|
10
|
+
def test_basic_spelling
|
11
|
+
assert @dict.spell("Baumkuchen") == true
|
12
|
+
assert @dict.check("Baumkuchen") == true # check alias
|
13
|
+
assert @dict.spell("Bomcuken") == false
|
14
|
+
assert_equal ["Baumkuchen"], @dict.suggest("Baumgurken")
|
15
|
+
assert_equal [], @dict.suggest("qwss43easd")
|
16
|
+
end
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hunspell-ffi
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 2
|
9
|
+
version: 0.1.2
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Andreas Haller
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-08-06 00:00:00 +02:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: ffi
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
- 6
|
31
|
+
- 3
|
32
|
+
version: 0.6.3
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description:
|
36
|
+
email:
|
37
|
+
- andreashaller@gmail.com
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- test/cakes.aff
|
46
|
+
- test/cakes.dic
|
47
|
+
- test/test_hunspell.rb
|
48
|
+
- lib/hunspell-ffi.rb
|
49
|
+
- Rakefile
|
50
|
+
- README.rdoc
|
51
|
+
has_rdoc: true
|
52
|
+
homepage: http://github.com/ahaller/hunspell-ffi
|
53
|
+
licenses: []
|
54
|
+
|
55
|
+
post_install_message:
|
56
|
+
rdoc_options: []
|
57
|
+
|
58
|
+
require_paths:
|
59
|
+
- lib
|
60
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
61
|
+
none: false
|
62
|
+
requirements:
|
63
|
+
- - ">="
|
64
|
+
- !ruby/object:Gem::Version
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
69
|
+
none: false
|
70
|
+
requirements:
|
71
|
+
- - ">="
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
segments:
|
74
|
+
- 1
|
75
|
+
- 3
|
76
|
+
- 6
|
77
|
+
version: 1.3.6
|
78
|
+
requirements: []
|
79
|
+
|
80
|
+
rubyforge_project:
|
81
|
+
rubygems_version: 1.3.7
|
82
|
+
signing_key:
|
83
|
+
specification_version: 3
|
84
|
+
summary: A Ruby FFI interface to the Hunspell spelling checker
|
85
|
+
test_files:
|
86
|
+
- test/test_hunspell.rb
|