runspell 0.0.1
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Rakefile +1 -0
- data/ext/extconf.rb +37 -0
- data/ext/runspell.c +74 -0
- data/runspell.gemspec +19 -0
- data/tests/simple.rb +13 -0
- metadata +63 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'bundler/gem_tasks'
|
data/ext/extconf.rb
ADDED
@@ -0,0 +1,37 @@
|
|
1
|
+
# Runspell - a ruby wrapper for hunspell
|
2
|
+
# Copyright (C) 2007 Martin Kihlgren <zond at troja dot ath dot cx>
|
3
|
+
#
|
4
|
+
# This program is free software; you can redistribute it and/or
|
5
|
+
# modify it under the terms of the GNU General Public License
|
6
|
+
# as published by the Free Software Foundation; either version 2
|
7
|
+
# of the License, or (at your option) any later version.
|
8
|
+
#
|
9
|
+
# This program is distributed in the hope that it will be useful,
|
10
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
11
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
12
|
+
# GNU General Public License for more details.
|
13
|
+
#
|
14
|
+
# You should have received a copy of the GNU General Public License
|
15
|
+
# along with this program; if not, write to the Free Software
|
16
|
+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
17
|
+
|
18
|
+
require 'mkmf'
|
19
|
+
|
20
|
+
def crash(s)
|
21
|
+
puts "--------------------------------------------------"
|
22
|
+
puts " extconf failure: #{s}"
|
23
|
+
puts "--------------------------------------------------"
|
24
|
+
exit 1
|
25
|
+
end
|
26
|
+
|
27
|
+
unless find_executable("pkg-config")
|
28
|
+
crash("pkg-config needed")
|
29
|
+
end
|
30
|
+
|
31
|
+
$LIBS += " " + `pkg-config --libs hunspell`.strip
|
32
|
+
|
33
|
+
unless have_library('hunspell-1.3')
|
34
|
+
crash "hunspell needed"
|
35
|
+
end
|
36
|
+
|
37
|
+
create_makefile("runspell")
|
data/ext/runspell.c
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
#include "ruby.h"
|
2
|
+
|
3
|
+
typedef struct Hunhandle Hunhandle;
|
4
|
+
Hunhandle *Hunspell_create (const char *affpath, const char *dicpath);
|
5
|
+
void Hunspell_destroy (Hunhandle *pHunspell);
|
6
|
+
int Hunspell_spell (Hunhandle *pHunspell, const char *word);
|
7
|
+
int Hunspell_suggest (Hunhandle *pHunspell, char ***slst, const char *word);
|
8
|
+
|
9
|
+
|
10
|
+
static Hunhandle *get_hunhandle(VALUE klass) {
|
11
|
+
Hunhandle *pHunspell;
|
12
|
+
Data_Get_Struct(klass, Hunhandle, pHunspell);
|
13
|
+
if (pHunspell == NULL) {
|
14
|
+
rb_raise(rb_eRuntimeError, "Something wrong with wrapped Hunspell handle.");
|
15
|
+
}
|
16
|
+
return pHunspell;
|
17
|
+
}
|
18
|
+
|
19
|
+
static VALUE new(VALUE self, VALUE _affpath, VALUE _dicpath) {
|
20
|
+
char * affpath = StringValuePtr(_affpath);
|
21
|
+
char * dicpath = StringValuePtr(_dicpath);
|
22
|
+
|
23
|
+
Hunhandle *pHunspell = Hunspell_create(affpath, dicpath);
|
24
|
+
if (pHunspell == NULL) {
|
25
|
+
rb_raise(rb_eRuntimeError, "Failed to initialize Hunspell.");
|
26
|
+
}
|
27
|
+
return (Data_Wrap_Struct(self, 0, Hunspell_destroy, pHunspell));
|
28
|
+
}
|
29
|
+
|
30
|
+
static VALUE check(VALUE self, VALUE _str) {
|
31
|
+
char * str = StringValuePtr(_str);
|
32
|
+
return ((Hunspell_spell(get_hunhandle(self), str) == 1 ? Qtrue : Qfalse));
|
33
|
+
}
|
34
|
+
|
35
|
+
static VALUE suggest(VALUE self, VALUE _word) {
|
36
|
+
char * word = StringValuePtr(_word);
|
37
|
+
|
38
|
+
int i, n;
|
39
|
+
char **list, *item;
|
40
|
+
VALUE suggestions;
|
41
|
+
|
42
|
+
n = Hunspell_suggest(get_hunhandle(self), &list, word);
|
43
|
+
suggestions = rb_ary_new2(n);
|
44
|
+
|
45
|
+
for (i = 0; i < n; ++i) {
|
46
|
+
item = list[i];
|
47
|
+
rb_ary_push(suggestions, rb_str_new2(item));
|
48
|
+
free(item);
|
49
|
+
}
|
50
|
+
|
51
|
+
if (n > 0) {
|
52
|
+
free(list);
|
53
|
+
}
|
54
|
+
|
55
|
+
return (suggestions);
|
56
|
+
}
|
57
|
+
|
58
|
+
|
59
|
+
|
60
|
+
#ifdef __cplusplus
|
61
|
+
extern "C" {
|
62
|
+
#endif
|
63
|
+
void Init_runspell() {
|
64
|
+
VALUE c = NULL;
|
65
|
+
c = rb_define_class( "Runspell", rb_cObject );
|
66
|
+
|
67
|
+
rb_define_method( c, "check", (VALUE(*)(ANYARGS))check, 1 );
|
68
|
+
rb_define_singleton_method( c, "new", (VALUE(*)(ANYARGS))new, 2 );
|
69
|
+
rb_define_method( c, "suggest", (VALUE(*)(ANYARGS))suggest, 1 );
|
70
|
+
|
71
|
+
}
|
72
|
+
#ifdef __cplusplus
|
73
|
+
}
|
74
|
+
#endif
|
data/runspell.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = "runspell"
|
5
|
+
s.version = "0.0.1"
|
6
|
+
s.authors = [ "Nguyen Tien Dung", "Julien DUMAS" ]
|
7
|
+
s.email = [ "dungtn@gmail.com", "julien.dumas@emediad.fr" ]
|
8
|
+
s.homepage = ""
|
9
|
+
s.summary = %q{Runspell C extension}
|
10
|
+
s.description = %q{Runspell is a wrapper to hunspell lib (not RubyInline version). All code is taken from rhunspell extension.}
|
11
|
+
s.has_rdoc = false
|
12
|
+
s.rubyforge_project = "runspell"
|
13
|
+
s.date = "2011-07-19"
|
14
|
+
|
15
|
+
s.files = `git ls-files`.split("\n")
|
16
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
17
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
18
|
+
s.extensions << 'ext/extconf.rb'
|
19
|
+
end
|
data/tests/simple.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'runspell'
|
2
|
+
|
3
|
+
aff_file = "/Users/julien/Downloads/hunspell-fr-moderne-v4.2/fr-moderne.aff"
|
4
|
+
dic_file = "/Users/julien/Downloads/hunspell-fr-moderne-v4.2/fr-moderne.dic"
|
5
|
+
|
6
|
+
dict = Runspell.new( aff_file, dic_file )
|
7
|
+
|
8
|
+
a = "Je veux etre un gentill home !"
|
9
|
+
a.split( " " ).each do |word|
|
10
|
+
puts dict.check( word )
|
11
|
+
puts dict.suggest( word ).first
|
12
|
+
p "-------------------------------------"
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: runspell
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.1
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Nguyen Tien Dung
|
9
|
+
- Julien DUMAS
|
10
|
+
autorequire:
|
11
|
+
bindir: bin
|
12
|
+
cert_chain: []
|
13
|
+
|
14
|
+
date: 2011-07-19 00:00:00 Z
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: Runspell is a wrapper to hunspell lib (not RubyInline version). All code is taken from rhunspell extension.
|
18
|
+
email:
|
19
|
+
- dungtn@gmail.com
|
20
|
+
- julien.dumas@emediad.fr
|
21
|
+
executables: []
|
22
|
+
|
23
|
+
extensions:
|
24
|
+
- ext/extconf.rb
|
25
|
+
extra_rdoc_files: []
|
26
|
+
|
27
|
+
files:
|
28
|
+
- .gitignore
|
29
|
+
- Gemfile
|
30
|
+
- Rakefile
|
31
|
+
- ext/extconf.rb
|
32
|
+
- ext/runspell.c
|
33
|
+
- runspell.gemspec
|
34
|
+
- tests/simple.rb
|
35
|
+
homepage: ""
|
36
|
+
licenses: []
|
37
|
+
|
38
|
+
post_install_message:
|
39
|
+
rdoc_options: []
|
40
|
+
|
41
|
+
require_paths:
|
42
|
+
- lib
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: "0"
|
55
|
+
requirements: []
|
56
|
+
|
57
|
+
rubyforge_project: runspell
|
58
|
+
rubygems_version: 1.8.5
|
59
|
+
signing_key:
|
60
|
+
specification_version: 3
|
61
|
+
summary: Runspell C extension
|
62
|
+
test_files: []
|
63
|
+
|