hunspell 0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (8) hide show
  1. data/LGPL_LICENSE +165 -0
  2. data/README +84 -0
  3. data/TODO +8 -0
  4. data/example.rb +20 -0
  5. data/extconf.rb +6 -0
  6. data/hunspell.c +179 -0
  7. data/hunspell.rb +25 -0
  8. metadata +53 -0
data/LGPL_LICENSE ADDED
@@ -0,0 +1,165 @@
1
+ GNU LESSER GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
+
4
+ Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
+ Everyone is permitted to copy and distribute verbatim copies
6
+ of this license document, but changing it is not allowed.
7
+
8
+
9
+ This version of the GNU Lesser General Public License incorporates
10
+ the terms and conditions of version 3 of the GNU General Public
11
+ License, supplemented by the additional permissions listed below.
12
+
13
+ 0. Additional Definitions.
14
+
15
+ As used herein, "this License" refers to version 3 of the GNU Lesser
16
+ General Public License, and the "GNU GPL" refers to version 3 of the GNU
17
+ General Public License.
18
+
19
+ "The Library" refers to a covered work governed by this License,
20
+ other than an Application or a Combined Work as defined below.
21
+
22
+ An "Application" is any work that makes use of an interface provided
23
+ by the Library, but which is not otherwise based on the Library.
24
+ Defining a subclass of a class defined by the Library is deemed a mode
25
+ of using an interface provided by the Library.
26
+
27
+ A "Combined Work" is a work produced by combining or linking an
28
+ Application with the Library. The particular version of the Library
29
+ with which the Combined Work was made is also called the "Linked
30
+ Version".
31
+
32
+ The "Minimal Corresponding Source" for a Combined Work means the
33
+ Corresponding Source for the Combined Work, excluding any source code
34
+ for portions of the Combined Work that, considered in isolation, are
35
+ based on the Application, and not on the Linked Version.
36
+
37
+ The "Corresponding Application Code" for a Combined Work means the
38
+ object code and/or source code for the Application, including any data
39
+ and utility programs needed for reproducing the Combined Work from the
40
+ Application, but excluding the System Libraries of the Combined Work.
41
+
42
+ 1. Exception to Section 3 of the GNU GPL.
43
+
44
+ You may convey a covered work under sections 3 and 4 of this License
45
+ without being bound by section 3 of the GNU GPL.
46
+
47
+ 2. Conveying Modified Versions.
48
+
49
+ If you modify a copy of the Library, and, in your modifications, a
50
+ facility refers to a function or data to be supplied by an Application
51
+ that uses the facility (other than as an argument passed when the
52
+ facility is invoked), then you may convey a copy of the modified
53
+ version:
54
+
55
+ a) under this License, provided that you make a good faith effort to
56
+ ensure that, in the event an Application does not supply the
57
+ function or data, the facility still operates, and performs
58
+ whatever part of its purpose remains meaningful, or
59
+
60
+ b) under the GNU GPL, with none of the additional permissions of
61
+ this License applicable to that copy.
62
+
63
+ 3. Object Code Incorporating Material from Library Header Files.
64
+
65
+ The object code form of an Application may incorporate material from
66
+ a header file that is part of the Library. You may convey such object
67
+ code under terms of your choice, provided that, if the incorporated
68
+ material is not limited to numerical parameters, data structure
69
+ layouts and accessors, or small macros, inline functions and templates
70
+ (ten or fewer lines in length), you do both of the following:
71
+
72
+ a) Give prominent notice with each copy of the object code that the
73
+ Library is used in it and that the Library and its use are
74
+ covered by this License.
75
+
76
+ b) Accompany the object code with a copy of the GNU GPL and this license
77
+ document.
78
+
79
+ 4. Combined Works.
80
+
81
+ You may convey a Combined Work under terms of your choice that,
82
+ taken together, effectively do not restrict modification of the
83
+ portions of the Library contained in the Combined Work and reverse
84
+ engineering for debugging such modifications, if you also do each of
85
+ the following:
86
+
87
+ a) Give prominent notice with each copy of the Combined Work that
88
+ the Library is used in it and that the Library and its use are
89
+ covered by this License.
90
+
91
+ b) Accompany the Combined Work with a copy of the GNU GPL and this license
92
+ document.
93
+
94
+ c) For a Combined Work that displays copyright notices during
95
+ execution, include the copyright notice for the Library among
96
+ these notices, as well as a reference directing the user to the
97
+ copies of the GNU GPL and this license document.
98
+
99
+ d) Do one of the following:
100
+
101
+ 0) Convey the Minimal Corresponding Source under the terms of this
102
+ License, and the Corresponding Application Code in a form
103
+ suitable for, and under terms that permit, the user to
104
+ recombine or relink the Application with a modified version of
105
+ the Linked Version to produce a modified Combined Work, in the
106
+ manner specified by section 6 of the GNU GPL for conveying
107
+ Corresponding Source.
108
+
109
+ 1) Use a suitable shared library mechanism for linking with the
110
+ Library. A suitable mechanism is one that (a) uses at run time
111
+ a copy of the Library already present on the user's computer
112
+ system, and (b) will operate properly with a modified version
113
+ of the Library that is interface-compatible with the Linked
114
+ Version.
115
+
116
+ e) Provide Installation Information, but only if you would otherwise
117
+ be required to provide such information under section 6 of the
118
+ GNU GPL, and only to the extent that such information is
119
+ necessary to install and execute a modified version of the
120
+ Combined Work produced by recombining or relinking the
121
+ Application with a modified version of the Linked Version. (If
122
+ you use option 4d0, the Installation Information must accompany
123
+ the Minimal Corresponding Source and Corresponding Application
124
+ Code. If you use option 4d1, you must provide the Installation
125
+ Information in the manner specified by section 6 of the GNU GPL
126
+ for conveying Corresponding Source.)
127
+
128
+ 5. Combined Libraries.
129
+
130
+ You may place library facilities that are a work based on the
131
+ Library side by side in a single library together with other library
132
+ facilities that are not Applications and are not covered by this
133
+ License, and convey such a combined library under terms of your
134
+ choice, if you do both of the following:
135
+
136
+ a) Accompany the combined library with a copy of the same work based
137
+ on the Library, uncombined with any other library facilities,
138
+ conveyed under the terms of this License.
139
+
140
+ b) Give prominent notice with the combined library that part of it
141
+ is a work based on the Library, and explaining where to find the
142
+ accompanying uncombined form of the same work.
143
+
144
+ 6. Revised Versions of the GNU Lesser General Public License.
145
+
146
+ The Free Software Foundation may publish revised and/or new versions
147
+ of the GNU Lesser General Public License from time to time. Such new
148
+ versions will be similar in spirit to the present version, but may
149
+ differ in detail to address new problems or concerns.
150
+
151
+ Each version is given a distinguishing version number. If the
152
+ Library as you received it specifies that a certain numbered version
153
+ of the GNU Lesser General Public License "or any later version"
154
+ applies to it, you have the option of following the terms and
155
+ conditions either of that published version or of any later version
156
+ published by the Free Software Foundation. If the Library as you
157
+ received it does not specify a version number of the GNU Lesser
158
+ General Public License, you may choose any version of the GNU Lesser
159
+ General Public License ever published by the Free Software Foundation.
160
+
161
+ If the Library as you received it specifies that a proxy can decide
162
+ whether future versions of the GNU Lesser General Public License shall
163
+ apply, that proxy's public statement of acceptance of any version is
164
+ permanent authorization for you to choose that version for the
165
+ Library.
data/README ADDED
@@ -0,0 +1,84 @@
1
+ Hunspell
2
+ Ruby interface to hunspell spell checker
3
+
4
+ Copyright 2007, Gabor SEBESTYEN
5
+
6
+
7
+ WHAT IS THIS?
8
+ -------------
9
+
10
+ Hunspell is an easy native Ruby interface to the famous Hunspell spell checker
11
+ library which is part of OpenOffice and Mozilla products. With this bundle
12
+ you can start to develop your own AJAX based spell checker service for
13
+ Ruby on Rails.
14
+
15
+
16
+ REQUIREMENTS
17
+ ------------
18
+
19
+ Before install Hunspell be sure to have the following components:
20
+
21
+ - Ruby 1.8.x
22
+ - rubygems
23
+ - hunspell 1.1.x (libhunspell-1.1)
24
+ http://hunspell.sourceforge.net
25
+ - dictionary files for Hunspell
26
+ http://wiki.services.openoffice.org/wiki/Dictionaries
27
+
28
+
29
+ INSTALLATION
30
+ ------------
31
+
32
+ The best way is to use gem package manager.
33
+
34
+ gem install hunspell
35
+
36
+ If you want to build Hunspell from scratch grab the source and issue the
37
+ following commands:
38
+
39
+ ruby extconf.rb && make
40
+
41
+
42
+ FIRST STEPS
43
+ -----------
44
+
45
+ Here's a very simple example how to use Hunspell. Cut it and run in ruby.
46
+
47
+
48
+ === example.rb ===
49
+
50
+ require "rubygems" # import gem package manager
51
+ gem "hunspell" # load Hunspell module
52
+ require "Hunspell" # inject Hunspell class to Ruby namespace
53
+
54
+ # instantiate Hunspell with Hungarian affix and dictionary files
55
+ #
56
+ sp = Hunspell.new("hu.aff", "hu.dic")
57
+
58
+ # spell check Hungarian word 'ablak' (window) => true
59
+ #
60
+ puts "Is 'ablak' correct? #{sp.spellcheck('ablak')}"
61
+
62
+ # get suggestions for mispelled word 'paprika'
63
+ # => ["kaprica", "patrica", "paprika", "papcica",
64
+ # "papráca", "papruca", "paprima", "paprikáz",
65
+ # "paprikása", "paprikás", "Papradnó"
66
+ # ]
67
+ #
68
+ puts "Suggestions for 'paprica': " + sp.suggest("paprica").inspect
69
+
70
+ === end of example ===
71
+
72
+
73
+ FEEDBACK
74
+ --------
75
+
76
+ Any help or report warmly appreciated. Please visit the project's homepage at
77
+ http://hunspell.rubyforge.org or write me to segabor@gmail.com
78
+
79
+
80
+ DISCLAIMER
81
+ ----------
82
+
83
+ This software is at an early stage. Use at own your risk!
84
+ No warranty.
data/TODO ADDED
@@ -0,0 +1,8 @@
1
+ - Hunspell tested only with utf8 encoded dictionaries. No idea what will be
2
+ happening if I use dictionary having other encoding like ISO-8859-2.
3
+
4
+ - Native binding actually uses the C API of hunspell library which provides a
5
+ very basic set of functions. Basically it is enough for my original purposes
6
+ but likely to change to the much richer C++ API.
7
+
8
+ - rdoc
data/example.rb ADDED
@@ -0,0 +1,20 @@
1
+ require "rubygems" # import gem package manager
2
+ gem "hunspell" # load Hunspell module
3
+ require "Hunspell" # inject Hunspell class to Ruby namespace
4
+
5
+ # instantiate Hunspell with Hungarian affix and dictionary files
6
+ #
7
+ sp = Hunspell.new("hu.aff", "hu.dic")
8
+
9
+ # spell check Hungarian word 'ablak' (window) => true
10
+ #
11
+ puts "Is 'ablak' correct? #{sp.spellcheck('ablak')}"
12
+
13
+ # get suggestions for mispelled word 'paprika'
14
+ # => ["kaprica", "patrica", "paprika", "papcica",
15
+ # "papráca", "papruca", "paprima", "paprikáz",
16
+ # "paprikása", "paprikás", "Papradnó"
17
+ # ]
18
+ #
19
+ puts "Suggestions for 'paprica': " + sp.suggest("paprica").inspect
20
+
data/extconf.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'mkmf'
2
+
3
+ dir_config("Hunspell")
4
+ have_library("hunspell-1.1", "Hunspell_create")
5
+
6
+ create_makefile("Hunspell")
data/hunspell.c ADDED
@@ -0,0 +1,179 @@
1
+ /*
2
+ * Hunspell
3
+ * Ruby interface to hunspell spell checker
4
+ *
5
+ * Copyright 2007, Gabor SEBESTYEN
6
+ *
7
+ * == LICENSE
8
+ *
9
+ * This file is part of Hunspell.
10
+ *
11
+ * Hunspell is free software; you can redistribute it and/or modify
12
+ * it under the terms of the GNU General Public License as published by
13
+ * the Free Software Foundation; either version 3 of the License, or
14
+ * (at your option) any later version.
15
+ *
16
+ * Hunspell is distributed in the hope that it will be useful,
17
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ * GNU General Public License for more details.
20
+
21
+ * You should have received a copy of the GNU General Public License
22
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ */
24
+
25
+ #include "ruby.h"
26
+ #include "hunspell/hunspell.h"
27
+
28
+
29
+
30
+ /*
31
+ * Object allocator
32
+ */
33
+ static VALUE cHunspellAllocate (VALUE klass)
34
+ {
35
+ // bind the pointer to hunspell hander to Hunspell object
36
+ Hunhandle **ptr = malloc(sizeof(Hunhandle *));
37
+ *ptr = (Hunhandle *)0;
38
+
39
+ return Data_Wrap_Struct(klass, 0, 0, ptr);
40
+ }
41
+
42
+
43
+
44
+ /*
45
+ * Constructor function
46
+ *
47
+ * Instantiate Hunspell with paths pointing to affix and dictionary files.
48
+ *
49
+ * Example:
50
+ * sp = Hunspell.new("hu.aff", "hu.dic") => (Hunspell object)
51
+ *
52
+ */
53
+ static VALUE mHunspellInitialize(VALUE self, VALUE affPath, VALUE dictPath) {
54
+ Hunhandle *handler = Hunspell_create(StringValueCStr(affPath), StringValueCStr(dictPath));
55
+
56
+ Hunhandle **ptr;
57
+ Data_Get_Struct(self, Hunhandle **, ptr);
58
+
59
+ if (!handler) {
60
+ // crash!
61
+ rb_raise(rb_eRuntimeError, "Failed to initialize Hunspell.");
62
+ } else {
63
+ *ptr = handler;
64
+ }
65
+
66
+ #ifdef DEBUG
67
+ printf("DEBUG: mHunspellInitialize: 0x%x\n", handler);
68
+ #endif
69
+ return self;
70
+ }
71
+
72
+
73
+
74
+ /*
75
+ * Spellcheck a word
76
+ *
77
+ * Input: word (String)
78
+ * Output: found correct? (Boolean)
79
+ *
80
+ * Example:
81
+ * sp.spellcheck("ruby") => true
82
+ *
83
+ */
84
+ static VALUE mHunspellSpell(VALUE self, VALUE str) {
85
+ int result;
86
+
87
+ Hunhandle **ptr;
88
+ Data_Get_Struct(self, Hunhandle **, ptr);
89
+
90
+ result = Hunspell_spell(*ptr, (const char *)StringValueCStr(str));
91
+ #ifdef DEBUG
92
+ printf("DEBUG: mHunspellSpell: %s -> %d\n", StringValueCStr(str), result);
93
+ #endif
94
+ return (result == 1 ? Qtrue : Qfalse);
95
+ }
96
+
97
+
98
+
99
+ /*
100
+ * Get suggestions to a word
101
+ *
102
+ * Input: word (String)
103
+ * Output: list of suggestions (Array of Strings)
104
+ *
105
+ * Example:
106
+ * sp.suggest("sunmer") => ['summer', ...]
107
+ *
108
+ */
109
+ static VALUE mHunspellSuggest(VALUE self, VALUE str) {
110
+ int n, i;
111
+ char **lst;
112
+ VALUE ret;
113
+
114
+ Hunhandle **ptr;
115
+ Data_Get_Struct(self, Hunhandle **, ptr);
116
+
117
+ n = Hunspell_suggest(*ptr, &lst, (const char *)StringValueCStr(str));
118
+ if (n > 0) {
119
+ // allocate enough space in new array
120
+ ret = rb_ary_new2(n);
121
+ for (i=0; i<n; i++) {
122
+ // add string to list
123
+ VALUE rb_str = rb_str_new2(lst[i]);
124
+ rb_ary_push(ret, rb_str);
125
+ }
126
+ } else {
127
+ // create empty array
128
+ ret = rb_ary_new();
129
+ }
130
+
131
+ #ifdef DEBUG
132
+ printf("mHunspellSuggest %s -> %d\n", StringValueCStr(str), n);
133
+ #endif
134
+
135
+ return ret;
136
+ }
137
+
138
+
139
+
140
+ /*
141
+ * Returns dictionary encoding
142
+ *
143
+ * Note: it may return 'ISO-8859-1' if dictionary not found or invalid.
144
+ *
145
+ * Output: encoding (String)
146
+ *
147
+ */
148
+ static VALUE mHunspellEncoding(VALUE self) {
149
+ int result;
150
+
151
+ Hunhandle **ptr;
152
+ Data_Get_Struct(self, Hunhandle **, ptr);
153
+
154
+ char *enc = Hunspell_get_dic_encoding(*ptr);
155
+ #ifdef DEBUG
156
+ printf("DEBUG: mHunspellEncoding: %s\n", enc);
157
+ #endif
158
+ return rb_str_new2(enc);
159
+ }
160
+
161
+
162
+ /*
163
+ * Module entry point
164
+ */
165
+ void Init_Hunspell() {
166
+ VALUE rb_cHunspell;
167
+
168
+ // create Hunspell class
169
+ rb_cHunspell = rb_define_class("Hunspell", rb_cObject);
170
+
171
+ // register own allocator
172
+ rb_define_alloc_func(rb_cHunspell, cHunspellAllocate);
173
+
174
+ // register instance methods
175
+ rb_define_method(rb_cHunspell, "initialize", mHunspellInitialize, 2);
176
+ rb_define_method(rb_cHunspell, "spellcheck", mHunspellSpell, 1);
177
+ rb_define_method(rb_cHunspell, "suggest", mHunspellSuggest, 1);
178
+ rb_define_method(rb_cHunspell, "encoding", mHunspellEncoding, 0);
179
+ }
data/hunspell.rb ADDED
@@ -0,0 +1,25 @@
1
+ #
2
+ # Hunspell
3
+ # Ruby interface to hunspell spell checker
4
+ #
5
+ # Copyright 2007, Gabor SEBESTYEN
6
+ #
7
+ # == LICENSE
8
+ #
9
+ # This file is part of Hunspell.
10
+ #
11
+ # Hunspell is free software; you can redistribute it and/or modify
12
+ # it under the terms of the GNU General Public License as published by
13
+ # the Free Software Foundation; either version 3 of the License, or
14
+ # (at your option) any later version.
15
+ #
16
+ # Hunspell is distributed in the hope that it will be useful,
17
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
18
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19
+ # GNU General Public License for more details.
20
+ #
21
+ # You should have received a copy of the GNU General Public License
22
+ # along with this program. If not, see <http://www.gnu.org/licenses/>.
23
+ #
24
+
25
+ require "Hunspell.so"
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ rubygems_version: 0.9.2
3
+ specification_version: 1
4
+ name: hunspell
5
+ version: !ruby/object:Gem::Version
6
+ version: "0.1"
7
+ date: 2007-09-06 00:00:00 +02:00
8
+ summary: Ruby interface to hunspell spell checker
9
+ require_paths:
10
+ - lib
11
+ - .
12
+ email: segabor@gmail.com
13
+ homepage: http://hunspell.rubyforge.org
14
+ rubyforge_project:
15
+ description: Hunspell is an easy native Ruby interface to the famous Hunspell spell checker library which is part of OpenOffice and Mozilla products. With this bundle you can start to develop your own AJAX based spell checker service for Ruby on Rails.
16
+ autorequire:
17
+ default_executable:
18
+ bindir: bin
19
+ has_rdoc: false
20
+ required_ruby_version: !ruby/object:Gem::Version::Requirement
21
+ requirements:
22
+ - - ">"
23
+ - !ruby/object:Gem::Version
24
+ version: 0.0.0
25
+ version:
26
+ platform: ruby
27
+ signing_key:
28
+ cert_chain:
29
+ post_install_message:
30
+ authors:
31
+ - "G\xC3\xA1bor SEBESTY\xC3\x89N"
32
+ files:
33
+ - extconf.rb
34
+ - hunspell.c
35
+ - hunspell.rb
36
+ - TODO
37
+ - README
38
+ - example.rb
39
+ - LGPL_LICENSE
40
+ test_files: []
41
+
42
+ rdoc_options: []
43
+
44
+ extra_rdoc_files: []
45
+
46
+ executables: []
47
+
48
+ extensions:
49
+ - extconf.rb
50
+ requirements:
51
+ - hunspell 1.1.11 or later
52
+ dependencies: []
53
+