hunspell 0.1.6 → 0.1.7

Sign up to get free protection for your applications and to get access to all the features.
Files changed (6) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +16 -16
  3. data/hunspell.c +49 -5
  4. data/test/test_hunspell.rb +5 -2
  5. metadata +3 -4
  6. data/TODO +0 -8
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b419bc05f51b1ccfeafd8c5350e6adecfa13bca4
4
- data.tar.gz: b293f485c0859389301a36866fb2a6ba7844241f
3
+ metadata.gz: 5c6a59940f13e88d0c5955c9511a371b3b6eb763
4
+ data.tar.gz: a0ba6b29475923fdd26596a0bf6fb9ffffb27ef7
5
5
  SHA512:
6
- metadata.gz: 2d937f1edb0819240990ebd015d5500170ba8dce66473131c937645b8bac7e92f2a205a2babea747db429cf984035f10b777c375cc7a02214b09b64602ae29f8
7
- data.tar.gz: bc697ecf87f9504613d401cbcc2d7f74414a05dd028cf0ab12c9d6d3f57975e765e585847d962972d32eeaa46990edb0b387fd965ea9734e2d655d4399fb3697
6
+ metadata.gz: 802bf32e5a8b2a062d6197d38ec1e90bfc109d11e0a33e302de88ba3f55f953a8415222e5a478bd2d840e4bebf60260326123762188fd2baef7f85a37ce0af6e
7
+ data.tar.gz: 2fc4ee9fe06af891992768b1de15edc5e6987dd6a7ad26f4187efc5b9dcd374a1b8451be0af7d5352bd307b63499d30caf71a4c680b2447af0392ccb7b9e9fd1
data/README.md CHANGED
@@ -19,28 +19,28 @@ Before installing Hunspell ensure you have the following components already inst
19
19
  ## INSTALLATION
20
20
 
21
21
  The best way to get Hunspell is to use gem package manager
22
-
23
- gem install hunspell
24
-
22
+ ```sh
23
+ gem install hunspell
24
+ ```
25
25
  NOTE: if install fails on newer OSX versions, try this command
26
-
27
- sudo ARCHFLAGS="-arch x86_64" gem install hunspell
28
-
26
+ ```sh
27
+ sudo ARCHFLAGS="-arch x86_64" gem install hunspell
28
+ ```
29
29
  If you want to build Hunspell from scratch grab the source from [here](https://github.com/segabor/Hunspell) and execute the
30
30
  following command
31
-
32
- ruby extconf.rb && make
33
-
31
+ ```sh
32
+ ruby extconf.rb && make
33
+ ```
34
34
 
35
35
  FreeBSD gotcha: hunspell spell checker package does not deploy its header
36
36
  files. Run gem or ruby command with an extra option:
37
-
38
- gem install hunspell -- --with-include-dir=<incdir>
39
-
37
+ ```sh
38
+ gem install hunspell -- --with-include-dir=<incdir>
39
+ ```
40
40
  or
41
-
42
- ruby extconf.rb --with-include-dir=<incdir> && make
43
-
41
+ ```sh
42
+ ruby extconf.rb --with-include-dir=<incdir> && make
43
+ ```
44
44
  Replace _incdir_ with the path pointing to hunspell includes.
45
45
 
46
46
  ## FIRST STEPS
@@ -49,7 +49,7 @@ Here's a basic example how to use Hunspell. Cut it and run in ruby.
49
49
 
50
50
  ### example.rb
51
51
 
52
- ```
52
+ ```rb
53
53
  require "rubygems" # import gem package manager
54
54
  gem "hunspell" # load Hunspell module
55
55
  require "Hunspell" # inject Hunspell class to Ruby namespace
data/hunspell.c CHANGED
@@ -75,7 +75,7 @@ static VALUE mHunspellInitialize(VALUE self, VALUE affPath, VALUE dictPath) {
75
75
 
76
76
  Hunhandle **ptr;
77
77
  Data_Get_Struct(self, Hunhandle *, ptr);
78
-
78
+
79
79
  if (!handler) {
80
80
  // crash!
81
81
  rb_raise(rb_eRuntimeError, "Failed to initialize Hunspell.");
@@ -103,7 +103,7 @@ static VALUE mHunspellInitialize(VALUE self, VALUE affPath, VALUE dictPath) {
103
103
  */
104
104
  static VALUE mHunspellSpell(VALUE self, VALUE str) {
105
105
  int result;
106
-
106
+
107
107
  Hunhandle **ptr;
108
108
  Data_Get_Struct(self, Hunhandle *, ptr);
109
109
 
@@ -130,7 +130,7 @@ static VALUE mHunspellSuggest(VALUE self, VALUE str) {
130
130
  int n, i;
131
131
  char **lst;
132
132
  VALUE ret;
133
-
133
+
134
134
  Hunhandle **ptr;
135
135
  Data_Get_Struct(self, Hunhandle *, ptr);
136
136
 
@@ -159,6 +159,49 @@ static VALUE mHunspellSuggest(VALUE self, VALUE str) {
159
159
 
160
160
 
161
161
 
162
+ /*
163
+ * Get Morphological analysis of the word
164
+ *
165
+ * Input: word (String)
166
+ * Output: list of analysis results (Array of Strings)
167
+ *
168
+ * Example:
169
+ * sp.analyze("paprika") => [' st:paprika po:noun ts:NOM']
170
+ *
171
+ */
172
+ static VALUE mHunspellAnalyze(VALUE self, VALUE str) {
173
+ int n, i;
174
+ char **lst;
175
+ VALUE ret;
176
+
177
+ Hunhandle **ptr;
178
+ Data_Get_Struct(self, Hunhandle *, ptr);
179
+
180
+ n = Hunspell_analyze(*ptr, &lst, (const char *)StringValueCStr(str));
181
+ if (n > 0) {
182
+ const char *enc = Hunspell_get_dic_encoding(*ptr);
183
+
184
+ // allocate enough space in new array
185
+ ret = rb_ary_new2(n);
186
+ for (i=0; i<n; i++) {
187
+ // add string to list
188
+ VALUE rb_str = ENCODED_STR_NEW2(lst[i], enc);
189
+ rb_ary_push(ret, rb_str);
190
+ }
191
+ } else {
192
+ // create empty array
193
+ ret = rb_ary_new();
194
+ }
195
+
196
+ #ifdef DEBUG
197
+ printf("mHunspellSuggest %s -> %d\n", StringValueCStr(str), n);
198
+ #endif
199
+
200
+ return ret;
201
+ }
202
+
203
+
204
+
162
205
  /*
163
206
  * Returns dictionary encoding
164
207
  *
@@ -184,16 +227,17 @@ static VALUE mHunspellEncoding(VALUE self) {
184
227
  */
185
228
  void Init_Hunspell() {
186
229
  VALUE rb_cHunspell;
187
-
230
+
188
231
  // create Hunspell class
189
232
  rb_cHunspell = rb_define_class("Hunspell", rb_cObject);
190
233
 
191
234
  // register own allocator
192
235
  rb_define_alloc_func(rb_cHunspell, cHunspellAllocate);
193
-
236
+
194
237
  // register instance methods
195
238
  rb_define_method(rb_cHunspell, "initialize", mHunspellInitialize, 2);
196
239
  rb_define_method(rb_cHunspell, "spellcheck", mHunspellSpell, 1);
197
240
  rb_define_method(rb_cHunspell, "suggest", mHunspellSuggest, 1);
241
+ rb_define_method(rb_cHunspell, "analyze", mHunspellAnalyze, 1);
198
242
  rb_define_method(rb_cHunspell, "encoding", mHunspellEncoding, 0);
199
243
  }
@@ -3,7 +3,7 @@ require "Hunspell"
3
3
 
4
4
  class HunspellTest < Test::Unit::TestCase
5
5
  def setup
6
- @sp = Hunspell.new("test/dict/hu_HU.aff", "test/dict/hu_HU.dic")
6
+ @sp = Hunspell.new("test/dict/hu_HU.aff", "test/dict/hu_HU.dic")
7
7
  end
8
8
 
9
9
  def test_spellcheck
@@ -21,5 +21,8 @@ class HunspellTest < Test::Unit::TestCase
21
21
  assert !suggestions.include?('paprica')
22
22
  assert suggestions.include?('paprika')
23
23
  end
24
- end
25
24
 
25
+ def test_analyze
26
+ assert @sp.analyze('paprika') == [" st:paprika po:noun ts:NOM"]
27
+ end
28
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hunspell
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.6
4
+ version: 0.1.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gábor SEBESTYÉN
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-23 00:00:00.000000000 Z
11
+ date: 2017-08-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Hunspell is an easy native Ruby interface to the famous Hunspell spell checker
@@ -23,7 +23,6 @@ extra_rdoc_files: []
23
23
  files:
24
24
  - LGPL_LICENSE
25
25
  - README.md
26
- - TODO
27
26
  - example.rb
28
27
  - extconf.rb
29
28
  - hunspell.c
@@ -51,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
51
50
  requirements:
52
51
  - hunspell 1.3 or newer
53
52
  rubyforge_project:
54
- rubygems_version: 2.5.2
53
+ rubygems_version: 2.6.11
55
54
  signing_key:
56
55
  specification_version: 4
57
56
  summary: Ruby interface to hunspell spell checker
data/TODO DELETED
@@ -1,8 +0,0 @@
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