grammar_cop 0.1.0 → 0.1.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/.DS_Store CHANGED
Binary file
data/.gitignore CHANGED
@@ -1,4 +1,5 @@
1
1
  *.gem
2
2
  .bundle
3
3
  Gemfile.lock
4
+ .DS_Store
4
5
  pkg/*
data/README ADDED
@@ -0,0 +1,22 @@
1
+ grammar_cop is a standalone ruby extension for the link-grammar-4.7.4 C library. You don't have to install anything extra, so this is deployable on platforms like heroku, cloudfoundry.
2
+ Example:
3
+
4
+ require 'grammar_cop'
5
+
6
+ puts dir = File.expand_path('../data', File.dirname(__FILE__))
7
+ GrammarCop::Dictionary.set_dictionary_path(dir)
8
+
9
+ dict = GrammarCop::Dictionary.create("en")
10
+ opts = GrammarCop::ParseOptions.create
11
+ text = "Grammar is useless because there's nothing to say -- Gertrude Stein."
12
+ sentence = GrammarCop::Sentence.create(text, dict)
13
+ puts num = GrammarCop::Sentence.parse(sentence, opts)
14
+ if num > 0
15
+ linkage = GrammarCop::Linkage.create(0, sentence, opts)
16
+ puts GrammarCop::Linkage.create_diagram(linkage)
17
+ puts "sublinkages=#{GrammarCop::Linkage.sublinkages_count(linkage)}"
18
+ puts "num_words=#{GrammarCop::Linkage.num_words_count(linkage)}"
19
+ puts "num_links=#{GrammarCop::Linkage.num_links_count(linkage)}"
20
+ #GrammarCop::Linkage.destroy(linkage)
21
+ end
22
+ GrammarCop::Sentence.destroy(sentence)
Binary file
@@ -17,6 +17,16 @@ void Init_link_grammar() {
17
17
  rb_define_module_function(lg, "linkage_limit_get", linkage_limit_get, 1);
18
18
  rb_define_module_function(lg, "short_length_set", short_length_set, 2);
19
19
  rb_define_module_function(lg, "short_length_get", short_length_get, 1);
20
+ rb_define_module_function(lg, "disjunct_cost_set", disjunct_cost_set, 2);
21
+ rb_define_module_function(lg, "disjunct_cost_get", disjunct_cost_get, 1);
22
+ rb_define_module_function(lg, "min_null_count_set", min_null_count_set, 2);
23
+ rb_define_module_function(lg, "min_null_count_get", min_null_count_get, 1);
24
+ rb_define_module_function(lg, "max_null_count_set", max_null_count_set, 2);
25
+ rb_define_module_function(lg, "max_null_count_get", max_null_count_get, 1);
26
+ rb_define_module_function(lg, "options_null_block_set", options_null_block_set, 2);
27
+ rb_define_module_function(lg, "options_null_block_get", options_null_block_get, 1);
28
+ rb_define_module_function(lg, "islands_ok_set", islands_ok_set, 2);
29
+ rb_define_module_function(lg, "islands_ok_get", islands_ok_get, 1);
20
30
  rb_define_module_function(lg, "create_sentence", create_sentence, 2);
21
31
  rb_define_module_function(lg, "parse_sentence", parse_sentence, 2);
22
32
  rb_define_module_function(lg, "delete_sentence", delete_sentence, 1);
@@ -136,6 +146,71 @@ VALUE short_length_get(const VALUE self, VALUE opts) {
136
146
  return INT2FIX(l);
137
147
  }
138
148
 
149
+ VALUE disjunct_cost_set(const VALUE self, VALUE opts, volatile VALUE cost) {
150
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
151
+ int c = NUM2INT(cost);
152
+ parse_options_set_disjunct_cost(ptr->opts, c);
153
+ return Qnil;
154
+ }
155
+
156
+ VALUE disjunct_cost_get(const VALUE self, VALUE opts) {
157
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
158
+ int c = parse_options_get_disjunct_cost(ptr->opts);
159
+ return INT2FIX(c);
160
+ }
161
+
162
+ VALUE min_null_count_set(const VALUE self, VALUE opts, volatile VALUE count) {
163
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
164
+ int c = NUM2INT(count);
165
+ parse_options_set_min_null_count(ptr->opts, c);
166
+ return Qnil;
167
+ }
168
+
169
+ VALUE min_null_count_get(const VALUE self, VALUE opts) {
170
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
171
+ int c = parse_options_get_min_null_count(ptr->opts);
172
+ return INT2FIX(c);
173
+ }
174
+
175
+ VALUE max_null_count_set(const VALUE self, VALUE opts, volatile VALUE count) {
176
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
177
+ int c = NUM2INT(count);
178
+ parse_options_set_max_null_count(ptr->opts, c);
179
+ return Qnil;
180
+ }
181
+
182
+ VALUE max_null_count_get(const VALUE self, VALUE opts) {
183
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
184
+ int c = parse_options_get_max_null_count(ptr->opts);
185
+ return INT2FIX(c);
186
+ }
187
+
188
+ VALUE options_null_block_set(const VALUE self, VALUE opts, volatile VALUE n_block) {
189
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
190
+ int b = NUM2INT(n_block);
191
+ parse_options_set_null_block(ptr->opts, b);
192
+ return Qnil;
193
+ }
194
+
195
+ VALUE options_null_block_get(const VALUE self, VALUE opts) {
196
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
197
+ int n_block = parse_options_get_null_block(ptr->opts);
198
+ return INT2FIX(n_block);
199
+ }
200
+
201
+ VALUE islands_ok_set(const VALUE self, VALUE opts, volatile VALUE islands_ok) {
202
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
203
+ int i = NUM2INT(islands_ok);
204
+ parse_options_set_islands_ok(ptr->opts, i);
205
+ return Qnil;
206
+ }
207
+
208
+ VALUE islands_ok_get(const VALUE self, VALUE opts) {
209
+ ParseOptionsPtr *ptr = retrieve_parse_options(opts);
210
+ int i = parse_options_get_islands_ok(ptr->opts);
211
+ return INT2FIX(i);
212
+ }
213
+
139
214
  VALUE create_sentence(const VALUE self, volatile VALUE str, VALUE dict) {
140
215
  char *text = StringValuePtr(str);
141
216
  DictionaryPtr *dict_ptr = retrieve_dictionary(dict);
@@ -86,6 +86,16 @@ VALUE linkage_limit_set(const VALUE self, VALUE opts, volatile VALUE limit);
86
86
  VALUE linkage_limit_get(const VALUE self, VALUE opts);
87
87
  VALUE short_length_set(const VALUE self, VALUE opts, volatile VALUE length);
88
88
  VALUE short_length_get(const VALUE self, VALUE opts);
89
+ VALUE disjunct_cost_set(const VALUE self, VALUE opts, volatile VALUE cost);
90
+ VALUE disjunct_cost_get(const VALUE self, VALUE opts);
91
+ VALUE min_null_count_set(const VALUE self, VALUE opts, volatile VALUE count);
92
+ VALUE min_null_count_get(const VALUE self, VALUE opts);
93
+ VALUE max_null_count_set(const VALUE self, VALUE opts, volatile VALUE count);
94
+ VALUE max_null_count_get(const VALUE self, VALUE opts);
95
+ VALUE options_null_block_set(const VALUE self, VALUE opts, volatile VALUE n_block);
96
+ VALUE options_null_block_get(const VALUE self, VALUE opts);
97
+ VALUE islands_ok_set(const VALUE self, VALUE opts, volatile VALUE islands_ok);
98
+ VALUE islands_ok_get(const VALUE self, VALUE opts);
89
99
 
90
100
  VALUE create_sentence(const VALUE self, volatile VALUE str, VALUE dict);
91
101
  VALUE parse_sentence(const VALUE self, VALUE sentence, VALUE opts);
@@ -5,5 +5,6 @@ require 'grammar_cop/sentence'
5
5
  require 'grammar_cop/linkage'
6
6
 
7
7
  module GrammarCop
8
- GrammarCop::Dictionary.set_dictionary_path("#{Gem.loaded_specs['grammar_cop'].full_gem_path}/data")
8
+ #GrammarCop::Dictionary.set_dictionary_path("#{Gem.loaded_specs['grammar_cop'].full_gem_path}/data")
9
+ GrammarCop::Dictionary.set_dictionary_path(File.expand_path('../data', File.dirname(__FILE__)))
9
10
  end
Binary file
@@ -28,5 +28,44 @@ module GrammarCop
28
28
  short_length_get(opts)
29
29
  end
30
30
 
31
+ def self.set_disjunct_cost(opts, cost)
32
+ disjunct_cost_set(opts, cost)
33
+ end
34
+
35
+ def self.get_disjunct_cost(opts)
36
+ disjunct_cost_get(opts)
37
+ end
38
+
39
+ def self.set_min_null_count(opts, count)
40
+ min_null_count_set(opts, count)
41
+ end
42
+
43
+ def self.get_min_null_count(opts)
44
+ min_null_count_get(opts)
45
+ end
46
+
47
+ def self.set_max_null_count(opts, count)
48
+ max_null_count_set(opts, count)
49
+ end
50
+
51
+ def self.get_max_null_count(opts)
52
+ max_null_count_get(opts)
53
+ end
54
+
55
+ def self.set_null_block(opts, block)
56
+ options_null_block_set(opts, block)
57
+ end
58
+
59
+ def self.get_null_block(opts)
60
+ options_null_block_get(opts)
61
+ end
62
+
63
+ def self.set_islands_ok(opts, ok)
64
+ options_null_block_set(opts, ok)
65
+ end
66
+
67
+ def self.get_islands_ok(opts)
68
+ islands_ok_get(opts)
69
+ end
31
70
  end
32
71
  end
@@ -25,7 +25,8 @@ module GrammarCop
25
25
  end
26
26
 
27
27
  #however, sometimes the split results in all incomplete clause so check one more time in those cases
28
- if count == 0
28
+ #but make sure it's not a really long sentence which will cause link-grammar to choke with combinatorial explosion
29
+ if text.size < 250 and count == 0
29
30
  s = create_sentence(text, dictionary)
30
31
  count = parse_sentence(s, options)
31
32
  delete_sentence(s)
@@ -1,3 +1,3 @@
1
1
  module GrammarCop
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -4,11 +4,21 @@ puts dir = File.expand_path('../data', File.dirname(__FILE__))
4
4
  GrammarCop::Dictionary.set_dictionary_path(dir)
5
5
 
6
6
  dict = GrammarCop::Dictionary.create("en")
7
+
8
+ #create and set parse options
7
9
  opts = GrammarCop::ParseOptions.create
8
10
  GrammarCop::ParseOptions.set_short_length(opts, 7)
9
11
  puts "short_length=#{GrammarCop::ParseOptions.get_short_length(opts)}"
10
12
  GrammarCop::ParseOptions.set_linkage_limit(opts, 10)
11
13
  puts "linkage limit=#{GrammarCop::ParseOptions.get_linkage_limit(opts)}"
14
+ GrammarCop::ParseOptions.set_disjunct_cost(opts, 1000)
15
+ puts "disjunct cost=#{GrammarCop::ParseOptions.get_disjunct_cost(opts)}"
16
+
17
+ puts "min null count=#{GrammarCop::ParseOptions.get_min_null_count(opts)}"
18
+ puts "max null count=#{GrammarCop::ParseOptions.get_max_null_count(opts)}"
19
+ puts "null block=#{GrammarCop::ParseOptions.get_null_block(opts)}"
20
+ puts "islands ok=#{GrammarCop::ParseOptions.get_islands_ok(opts)}"
21
+
12
22
  text = "Grammar is useless because there's nothing to say -- Gertrude Stein."
13
23
  sentence = GrammarCop::Sentence.create(text, dict)
14
24
  puts num = GrammarCop::Sentence.parse(sentence, opts)
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: grammar_cop
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.1.0
5
+ version: 0.1.1
6
6
  platform: ruby
7
7
  authors:
8
8
  - Quan Nguyen
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-05-08 00:00:00 Z
13
+ date: 2011-05-13 00:00:00 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rake-compiler
@@ -36,8 +36,8 @@ files:
36
36
  - .DS_Store
37
37
  - .gitignore
38
38
  - Gemfile
39
+ - README
39
40
  - Rakefile
40
- - data/.DS_Store
41
41
  - data/Makefile
42
42
  - data/Makefile.am
43
43
  - data/Makefile.in
@@ -64,7 +64,6 @@ files:
64
64
  - data/en/Makefile.in
65
65
  - data/en/README
66
66
  - data/en/tiny.dict
67
- - data/en/words/.DS_Store
68
67
  - data/en/words/Makefile
69
68
  - data/en/words/Makefile.am
70
69
  - data/en/words/Makefile.in
@@ -148,7 +147,6 @@ files:
148
147
  - data/lt/Makefile.am
149
148
  - data/lt/Makefile.in
150
149
  - ext/.DS_Store
151
- - ext/link_grammar/.DS_Store
152
150
  - ext/link_grammar/extconf.rb
153
151
  - ext/link_grammar/link-grammar/.DS_Store
154
152
  - ext/link_grammar/link-grammar/.deps/analyze-linkage.Plo
@@ -366,7 +364,6 @@ files:
366
364
  - ext/link_grammar/link_grammar.c
367
365
  - ext/link_grammar/link_grammar.h
368
366
  - grammar_cop.gemspec
369
- - lib/.DS_Store
370
367
  - lib/grammar_cop.rb
371
368
  - lib/grammar_cop/.DS_Store
372
369
  - lib/grammar_cop/dictionary.rb
@@ -374,7 +371,6 @@ files:
374
371
  - lib/grammar_cop/parse_options.rb
375
372
  - lib/grammar_cop/sentence.rb
376
373
  - lib/grammar_cop/version.rb
377
- - test/.DS_Store
378
374
  - test/grammar_cop_test.rb
379
375
  homepage: https://github.com/mquan
380
376
  licenses: []
Binary file
Binary file
Binary file
Binary file
Binary file