This repository has been archived by the owner on Jan 23, 2020. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Andreas Haller
committed
Aug 6, 2010
0 parents
commit dee0dc2
Showing
7 changed files
with
116 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
= hunspell-ffi | ||
|
||
A Ruby FFI interface to the Hunspell spelling checker | ||
|
||
It should work wherever Ruby FFI works (tested on Ruby 1.9.2, 1.8.7, JRuby 1.5.1). | ||
|
||
== Installation | ||
1. Install hunspell (OSX: 'brew install hunspell' Debian: 'apt-get install hunspell') | ||
2. gem install hunspell-ffi | ||
|
||
== Usage | ||
require 'hunspell-ffi' | ||
dict = Hunspell.new("path/to/cakes.aff", "path/to/cakes.dic") | ||
dict.spell("Baumkuchen") # => true same as #check | ||
dict.spell("Bomcuken") # => false | ||
dict.suggest("Baumgurken") # => ["Baumkuchen"] | ||
dict.suggest("qwss43easd") # => [] | ||
|
||
== Author | ||
Andreas Haller | ||
andreashaller@gmail.com | ||
|
||
== License | ||
Hereby placed under public domain, do what you want, just do not hold me accountable... | ||
|
||
== TODO | ||
Add other hunspell methods (add, remove, analyze, stem ...) | ||
|
||
Test on Windows |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
require 'rake/testtask' | ||
task :default => [:test] | ||
Rake::TestTask.new(:test) do |t| | ||
t.test_files = FileList['test/test_*.rb'] | ||
t.ruby_opts = ['-rubygems -I.'] if defined? Gem | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
# encoding: utf-8 | ||
Gem::Specification.new do |s| | ||
s.name = 'hunspell-ffi' | ||
s.version = '0.1' | ||
s.date = '2010-08-6' | ||
s.authors = ["Andreas Haller"] | ||
s.email = ["andreashaller@gmail.com"] | ||
s.homepage = "http://github.com/ahaller/hunspell-ffi" | ||
s.summary = "A Ruby FFI interface to the Hunspell spelling checker" | ||
s.required_rubygems_version = ">= 1.3.6" | ||
s.files = Dir['test/cakes*'] + Dir['test/*.rb'] + Dir['lib/**/*.rb'] + %w(Rakefile README.rdoc) | ||
s.test_files = Dir['test/test_*.rb'] | ||
s.require_path = 'lib' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# encoding: utf-8 | ||
require 'ffi' | ||
class Hunspell | ||
module C | ||
extend FFI::Library | ||
ffi_lib ['hunspell', 'libhunspell', 'hunspell-1.2', 'libhunspell-1.2'] | ||
attach_function :Hunspell_create, [:string, :string], :pointer | ||
attach_function :Hunspell_spell, [:pointer, :string], :bool | ||
attach_function :Hunspell_suggest, [:pointer, :pointer, :string], :int | ||
end | ||
|
||
# TODO RDoc | ||
|
||
def initialize(affpath, dicpath) | ||
@handler = C.Hunspell_create(affpath, dicpath) | ||
end | ||
|
||
def spell(word) | ||
C.Hunspell_spell(@handler, word) | ||
end | ||
alias_method :check, :spell | ||
|
||
def suggest(word) | ||
ptr = FFI::MemoryPointer.new(:pointer, 1) | ||
len = Hunspell::C.Hunspell_suggest(@handler, ptr, word) | ||
str_ptr = ptr.read_pointer | ||
str_ptr.null? ? [] : str_ptr.get_array_of_string(0, len).compact | ||
end | ||
end |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
20 | ||
Apfelkuchen | ||
Baumkuchen | ||
Bienenstich | ||
Butterkuchen | ||
Donauwelle | ||
Eierschecke | ||
Guglhupf | ||
Hefekuchen | ||
Käsekuchen | ||
Marmorkuchen | ||
Obstkuchen | ||
Panettone | ||
Pflaumenkuchen | ||
Russischer Zupfkuchen | ||
Rührkuchen | ||
Sandkuchen | ||
Schmandkuchen | ||
Stollen | ||
Streuselkuchen | ||
Zwiebelkuchen |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# encoding: utf-8 | ||
require "test/unit" | ||
require File.expand_path(File.dirname(__FILE__)) + '/../lib/hunspell-ffi' | ||
class TestHunspell < Test::Unit::TestCase | ||
def setup | ||
@dict_dir = File.dirname(__FILE__) | ||
@dict = Hunspell.new("#{@dict_dir}/cakes.aff", "#{@dict_dir}/cakes.dic") | ||
end | ||
|
||
def test_basic_spelling | ||
assert @dict.spell("Baumkuchen") == true | ||
assert @dict.check("Baumkuchen") == true # check alias | ||
assert @dict.spell("Bomcuken") == false | ||
assert_equal ["Baumkuchen"], @dict.suggest("Baumgurken") | ||
assert_equal [], @dict.suggest("qwss43easd") | ||
end | ||
end |