linkparser 1.1.4 → 2.0.0

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/ext/linkparser.c CHANGED
@@ -1,11 +1,11 @@
1
1
  /*
2
2
  * linkparser.c - Ruby LinkParser
3
- * $Id: linkparser.c,v 21df914cedb1 2010/10/12 15:45:26 ged $
4
- *
3
+ * $Id: linkparser.c,v 85300de8d84c 2015/03/02 16:59:48 ged $
4
+ *
5
5
  * Authors:
6
6
  * * Michael Granger <ged@FaerieMUD.org>
7
- *
8
- * Please see the LICENSE file at the top of the distribution for licensing
7
+ *
8
+ * Please see the LICENSE file at the top of the distribution for licensing
9
9
  * information.
10
10
  */
11
11
 
@@ -27,51 +27,80 @@ VALUE rlink_cParseOptions;
27
27
  VALUE rlink_sLinkageCTree;
28
28
 
29
29
 
30
- /* --------------------------------------------------
31
- * Utility functions
32
- * -------------------------------------------------- */
30
+ /* --------------------------------------------------------------
31
+ * Logging Functions
32
+ * -------------------------------------------------------------- */
33
33
 
34
+ /*
35
+ * Log a message to the given +context+ object's logger.
36
+ */
34
37
  void
35
38
  #ifdef HAVE_STDARG_PROTOTYPES
36
- rlink_debug(const char *fmt, ...)
39
+ rlink_log_obj( VALUE context, const char *level, const char *fmt, ... )
37
40
  #else
38
- rlink_debug(fmt, va_alist)
39
- const char *fmt;
40
- va_dcl
41
+ rlink_log_obj( VALUE context, const char *level, const char *fmt, va_dcl )
41
42
  #endif
42
43
  {
43
- char buf[BUFSIZ], buf2[BUFSIZ];
44
+ char buf[BUFSIZ];
44
45
  va_list args;
46
+ VALUE logger = Qnil;
47
+ VALUE message = Qnil;
45
48
 
46
- if (!RTEST(ruby_debug)) return;
49
+ va_init_list( args, fmt );
50
+ vsnprintf( buf, BUFSIZ, fmt, args );
51
+ message = rb_str_new2( buf );
47
52
 
48
- snprintf( buf, BUFSIZ, "LinkParser Debug>>> %s", fmt );
53
+ logger = rb_funcall( context, rb_intern("log"), 0, 0 );
54
+ rb_funcall( logger, rb_intern(level), 1, message );
55
+
56
+ va_end( args );
57
+ }
58
+
59
+
60
+ /*
61
+ * Log a message to the global logger.
62
+ */
63
+ void
64
+ #ifdef HAVE_STDARG_PROTOTYPES
65
+ rlink_log( const char *level, const char *fmt, ... )
66
+ #else
67
+ rlink_log( const char *level, const char *fmt, va_dcl )
68
+ #endif
69
+ {
70
+ char buf[BUFSIZ];
71
+ va_list args;
72
+ VALUE logger = Qnil;
73
+ VALUE message = Qnil;
49
74
 
50
75
  va_init_list( args, fmt );
51
- vsnprintf( buf2, BUFSIZ, buf, args );
52
- fputs( buf2, stderr );
53
- fputs( "\n", stderr );
54
- fflush( stderr );
76
+ vsnprintf( buf, BUFSIZ, fmt, args );
77
+ message = rb_str_new2( buf );
78
+
79
+ logger = rb_funcall( rlink_mLinkParser, rb_intern("logger"), 0, 0 );
80
+ rb_funcall( logger, rb_intern(level), 1, message );
81
+
55
82
  va_end( args );
56
83
  }
57
84
 
58
85
 
59
86
  /*
60
87
  * Raise a LinkParser::Error. The link-grammar library no longer supports fetching the actual
61
- * error message, so this just raises an exception with "Unknown error" now. Hopefully the
88
+ * error message, so this just raises an exception with "Unknown error" now. Hopefully the
62
89
  * library will have printed out the actual problem to stderr, and stderr is pointed
63
- * somewhere useful.
90
+ * somewhere useful.
64
91
  */
65
92
  void
66
- rlink_raise_lp_error() {
93
+ rlink_raise_lp_error()
94
+ {
67
95
  rb_raise( rlink_eLpError, "Unknown error" );
68
96
  }
69
97
 
70
98
 
71
- /* Make a Parse_Options after merging the specified default_options with any
99
+ /* Make a Parse_Options after merging the specified default_options with any
72
100
  new options given. */
73
101
  VALUE
74
- rlink_make_parse_options( VALUE default_options, VALUE options ) {
102
+ rlink_make_parse_options( VALUE default_options, VALUE options )
103
+ {
75
104
  if ( NIL_P(options) ) options = rb_hash_new();
76
105
  options = rb_funcall( default_options, rb_intern("merge"), 1, options );
77
106
 
@@ -87,7 +116,8 @@ rlink_make_parse_options( VALUE default_options, VALUE options ) {
87
116
  *
88
117
  */
89
118
  static VALUE
90
- rlink_link_grammar_version( VALUE self ) {
119
+ rlink_link_grammar_version( VALUE self )
120
+ {
91
121
  #ifdef HAVE_LINKGRAMMAR_GET_VERSION
92
122
  const char *version = linkgrammar_get_version();
93
123
  if ( !version ) rb_bug( "linkgrammar_get_version returned NULL pointer" );
@@ -102,7 +132,8 @@ rlink_link_grammar_version( VALUE self ) {
102
132
  * LinkParser extension init function
103
133
  */
104
134
  void
105
- Init_linkparser_ext() {
135
+ Init_linkparser_ext()
136
+ {
106
137
  rlink_mLinkParser = rb_define_module( "LinkParser" );
107
138
 
108
139
  /* The exception class used for LinkParser errors */
@@ -111,8 +142,6 @@ Init_linkparser_ext() {
111
142
  rb_define_singleton_method( rlink_mLinkParser, "link_grammar_version",
112
143
  rlink_link_grammar_version, 0 );
113
144
 
114
- setlocale( LC_ALL, "" );
115
-
116
145
  rlink_init_dict();
117
146
  rlink_init_sentence();
118
147
  rlink_init_linkage();
data/ext/linkparser.h CHANGED
@@ -1,11 +1,11 @@
1
1
  /*
2
2
  * linkparser.h - Ruby-LinkParser Header
3
- * $Id: linkparser.h,v 65471608cc6e 2011/04/04 18:56:35 ged $
3
+ * $Id: linkparser.h,v 85300de8d84c 2015/03/02 16:59:48 ged $
4
4
  *
5
5
  * Authors:
6
6
  * * Michael Granger <ged@FaerieMUD.org>
7
7
  *
8
- * Please see the LICENSE file at the top of the distribution for licensing
8
+ * Please see the LICENSE file at the top of the distribution for licensing
9
9
  * information.
10
10
  */
11
11
 
@@ -22,16 +22,22 @@
22
22
 
23
23
  #include <link-grammar/link-includes.h>
24
24
 
25
+ #include "extconf.h"
26
+
27
+ /* --------------------------------------------------------------
28
+ * Declarations
29
+ * -------------------------------------------------------------- */
25
30
 
26
- /* Debugging functions/macros */
27
31
  #ifdef HAVE_STDARG_PROTOTYPES
28
32
  #include <stdarg.h>
29
33
  #define va_init_list(a,b) va_start(a,b)
30
- extern void rlink_debug(const char *fmt, ...);
34
+ void rlink_log_obj( VALUE, const char *, const char *, ... );
35
+ void rlink_log( const char *, const char *, ... );
31
36
  #else
32
37
  #include <varargs.h>
33
38
  #define va_init_list(a,b) va_start(a)
34
- extern void rlink_debug(fmt, va_alist);
39
+ void rlink_log_obj( VALUE, const char *, const char *, va_dcl );
40
+ void rlink_log( const char *, const char *, va_dcl );
35
41
  #endif
36
42
 
37
43
  extern void rlink_raise_lp_error _(( void ));
@@ -59,7 +65,7 @@ extern VALUE rlink_sLinkageCTree;
59
65
  extern VALUE rlink_eLpError;
60
66
 
61
67
 
62
- /*
68
+ /*
63
69
  * Structures
64
70
  */
65
71
  struct rlink_dictionary {
@@ -67,8 +73,8 @@ struct rlink_dictionary {
67
73
  };
68
74
 
69
75
  struct rlink_sentence {
70
- Sentence sentence;
71
- VALUE dictionary;
76
+ Sentence sentence;
77
+ VALUE dictionary;
72
78
  VALUE parsed_p;
73
79
  VALUE options;
74
80
  };
@@ -84,14 +90,6 @@ struct rlink_linkage {
84
90
  * Macros
85
91
  */
86
92
 
87
- /* Debugging macro */
88
- #if DEBUG
89
- # define debugMsg(f) rlink_debug f
90
- #else /* ! DEBUG */
91
- # define debugMsg(f)
92
- #endif /* DEBUG */
93
-
94
-
95
93
  #define IsDictionary( obj ) rb_obj_is_kind_of( (obj), rlink_cDictionary )
96
94
  #define IsSentence( obj ) rb_obj_is_kind_of( (obj), rlink_cSentence )
97
95
  #define IsLinkage( obj ) rb_obj_is_kind_of( (obj), rlink_cLinkage )
data/ext/parseoptions.c CHANGED
@@ -1,11 +1,11 @@
1
1
  /*
2
2
  * parseoptions.c - Ruby LinkParser::ParseOptions class
3
- * $Id: parseoptions.c,v 21df914cedb1 2010/10/12 15:45:26 ged $
4
- *
3
+ * $Id: parseoptions.c,v 92228378be38 2015/03/02 16:44:04 ged $
4
+ *
5
5
  * Authors:
6
6
  * * Michael Granger <ged@FaerieMUD.org>
7
- *
8
- * Please see the LICENSE file at the top of the distribution for licensing
7
+ *
8
+ * Please see the LICENSE file at the top of the distribution for licensing
9
9
  * information.
10
10
  */
11
11
 
@@ -16,13 +16,13 @@
16
16
  * Forward declarations
17
17
  * -------------------------------------------------- */
18
18
 
19
- static VALUE rlink_parseopts_each_opthash_i _(( VALUE, VALUE ));
20
-
21
19
 
22
20
  /* --------------------------------------------------
23
21
  * Macros and constants
24
22
  * -------------------------------------------------- */
25
23
 
24
+ VALUE vdal_sym;
25
+ VALUE corpus_sym;
26
26
 
27
27
  /* --------------------------------------------------
28
28
  * Memory-management functions
@@ -32,8 +32,11 @@ static VALUE rlink_parseopts_each_opthash_i _(( VALUE, VALUE ));
32
32
  * Free function
33
33
  */
34
34
  static void
35
- rlink_parseopts_gc_free( Parse_Options parseopts ) {
36
- if ( parseopts ) parse_options_delete( parseopts );
35
+ rlink_parseopts_gc_free( Parse_Options parseopts )
36
+ {
37
+ if ( parseopts ) {
38
+ parse_options_delete( parseopts );
39
+ }
37
40
  }
38
41
 
39
42
 
@@ -41,7 +44,8 @@ rlink_parseopts_gc_free( Parse_Options parseopts ) {
41
44
  * Object validity checker. Returns the data pointer.
42
45
  */
43
46
  static Parse_Options
44
- check_parseopts( VALUE self ) {
47
+ check_parseopts( VALUE self )
48
+ {
45
49
  Check_Type( self, T_DATA );
46
50
 
47
51
  if ( !IsParseOptions(self) ) {
@@ -57,7 +61,8 @@ check_parseopts( VALUE self ) {
57
61
  * Fetch the data pointer and check it for sanity.
58
62
  */
59
63
  static Parse_Options
60
- get_parseopts( VALUE self ) {
64
+ get_parseopts( VALUE self )
65
+ {
61
66
  Parse_Options parseopts = check_parseopts( self );
62
67
 
63
68
  if ( !parseopts )
@@ -67,12 +72,13 @@ get_parseopts( VALUE self ) {
67
72
  }
68
73
 
69
74
 
70
- /*
71
- * Get the Parse_Options struct behind the LinkParser::ParseOptions +object+
75
+ /*
76
+ * Get the Parse_Options struct behind the LinkParser::ParseOptions +object+
72
77
  * specified.
73
- */
78
+ */
74
79
  Parse_Options
75
- rlink_get_parseopts( VALUE obj ) {
80
+ rlink_get_parseopts( VALUE obj )
81
+ {
76
82
  return get_parseopts( obj );
77
83
  }
78
84
 
@@ -88,8 +94,9 @@ rlink_get_parseopts( VALUE obj ) {
88
94
  * Allocate a new LinkParser::ParseOptions object.
89
95
  */
90
96
  static VALUE
91
- rlink_parseopts_s_alloc( VALUE klass ) {
92
- debugMsg(( "Wrapping an uninitialized ParseOptions pointer." ));
97
+ rlink_parseopts_s_alloc( VALUE klass )
98
+ {
99
+ rlink_log( "debug", "Wrapping an uninitialized ParseOptions pointer." );
93
100
  return Data_Wrap_Struct( klass, 0, rlink_parseopts_gc_free, 0 );
94
101
  }
95
102
 
@@ -105,83 +112,69 @@ rlink_parseopts_s_alloc( VALUE klass ) {
105
112
  * LinkParser::ParseOptions.new( opthash ) -> obj
106
113
  *
107
114
  * Create a new ParseOptions object and set values from opthash.
108
- *
109
- * po = LinkParser::ParseOptions.new( :allow_null => true, :batch_mode => true )
110
- *
115
+ *
116
+ * po = LinkParser::ParseOptions.new( min_null_count: 1, verbosity: 0 )
117
+ *
111
118
  */
112
119
  static VALUE
113
- rlink_parseopts_init( int argc, VALUE *argv, VALUE self ) {
120
+ rlink_parseopts_init( int argc, VALUE *argv, VALUE self )
121
+ {
114
122
  if ( ! check_parseopts(self) ) {
115
123
  Parse_Options opts;
116
124
  VALUE opthash = Qnil;
117
125
 
118
- debugMsg(( "Initializing a ParseOptions: %p", self ));
126
+ rlink_log_obj( self, "debug", "Initializing a ParseOptions: %p", self );
119
127
  DATA_PTR( self ) = opts = parse_options_create();
120
128
 
121
129
  rb_scan_args( argc, argv, "01", &opthash );
122
130
  if ( RTEST(opthash) ) {
123
- debugMsg(( "Setting options from an opthash." ));
124
- rb_iterate( rb_each, opthash, rlink_parseopts_each_opthash_i, self );
131
+ rlink_log_obj( self, "debug", "Setting options from an opthash." );
132
+ rb_funcall( self, rb_intern("merge!"), 1, opthash );
125
133
  }
126
134
  }
127
135
 
128
136
  else {
129
- rb_raise( rb_eRuntimeError, "Cannot re-initialize a Dictionary object." );
137
+ rb_raise( rb_eRuntimeError, "Cannot re-initialize a ParseOptions object." );
130
138
  }
131
139
 
132
140
  return self;
133
141
  }
134
142
 
135
143
 
136
- /*
137
- * Iterator function for rlink_parseopts_init() -- for each element of the hash passed
138
- * to the constructor, call the corresponding accessor in the new object.
144
+ /*
145
+ * Copy constructor
139
146
  */
140
147
  static VALUE
141
- rlink_parseopts_each_opthash_i( VALUE pair, VALUE self ) {
142
- VALUE key, val, keystring;
143
- char *method_name;
144
- ID method;
145
-
146
- key = rb_ary_entry( pair, 0 );
147
- val = rb_ary_entry( pair, 1 );
148
-
149
- keystring = rb_obj_as_string( key );
150
-
151
- method_name = ALLOCA_N( char, RSTRING_LEN(keystring) + 1 );
152
- strncpy( method_name, RSTRING_PTR(keystring), RSTRING_LEN(keystring) + 1 );
153
- strncat( method_name, "=", 1 );
154
-
155
- debugMsg(( "Calling method %s", method_name ));
156
- method = rb_intern( method_name );
148
+ rlink_parseopts_init_copy( VALUE self, VALUE other )
149
+ {
150
+ if ( ! check_parseopts(self) ) {
151
+ Parse_Options opts;
157
152
 
158
- return rb_funcall( self, method, 1, val );
159
- }
153
+ rlink_log_obj( self, "debug", "Initializing a copied ParseOptions: %p", self );
154
+ DATA_PTR( self ) = opts = parse_options_create();
155
+ rb_funcall( self, rb_intern("merge!"), 1, other );
160
156
 
157
+ rb_call_super( 1, &other );
158
+ }
161
159
 
162
- /*
163
- * call-seq:
164
- * merge( other ) -> parseopts
165
- *
166
- * Merge the receiving parse options with the given +other+ object, which can
167
- * be either another LinkParser::ParseOptions object or a Hash of options.
168
- */
169
- /*static VALUE
170
- rlink_parseopts_merge( VALUE self, other ) {
160
+ else {
161
+ rb_raise( rb_eRuntimeError, "Can't recopy a ParseOptions object." );
162
+ }
171
163
 
164
+ return self;
172
165
  }
173
- */
174
166
 
175
167
 
176
168
  /*
177
169
  * call-seq:
178
170
  * opts.verbosity= fixnum
179
171
  *
180
- * This sets the level of description printed to stderr/stdout about the
172
+ * This sets the level of description printed to stderr/stdout about the
181
173
  * parsing process.
182
174
  */
183
175
  static VALUE
184
- rlink_parseopts_set_verbosity( VALUE self, VALUE verbosity ) {
176
+ rlink_parseopts_set_verbosity( VALUE self, VALUE verbosity )
177
+ {
185
178
  Parse_Options opts = get_parseopts( self );
186
179
  parse_options_set_verbosity( opts, NUM2INT(verbosity) );
187
180
  return verbosity;
@@ -192,11 +185,12 @@ rlink_parseopts_set_verbosity( VALUE self, VALUE verbosity ) {
192
185
  * call-seq:
193
186
  * opts.verbosity -> fixnum
194
187
  *
195
- * This gets the level of description printed to stderr/stdout about the
188
+ * This gets the level of description printed to stderr/stdout about the
196
189
  * parsing process.
197
190
  */
198
191
  static VALUE
199
- rlink_parseopts_get_verbosity( VALUE self ) {
192
+ rlink_parseopts_get_verbosity( VALUE self )
193
+ {
200
194
  Parse_Options opts = get_parseopts( self );
201
195
  int rval;
202
196
 
@@ -209,13 +203,14 @@ rlink_parseopts_get_verbosity( VALUE self ) {
209
203
  * call-seq:
210
204
  * opts.linkage_limit= fixnum
211
205
  *
212
- * This parameter determines the maximum number of linkages that are
213
- * considered in post-processing. If more than +linkage_limit+ linkages are found,
214
- * then a random sample of +linkage_limit+ is chosen for post-processing. When
206
+ * This parameter determines the maximum number of linkages that are
207
+ * considered in post-processing. If more than +linkage_limit+ linkages are found,
208
+ * then a random sample of +linkage_limit+ is chosen for post-processing. When
215
209
  * this happen a warning is displayed at verbosity levels greater than 1.
216
210
  */
217
211
  static VALUE
218
- rlink_parseopts_set_linkage_limit( VALUE self, VALUE linkage_limit ) {
212
+ rlink_parseopts_set_linkage_limit( VALUE self, VALUE linkage_limit )
213
+ {
219
214
  Parse_Options opts = get_parseopts( self );
220
215
  parse_options_set_linkage_limit( opts, NUM2INT(linkage_limit) );
221
216
  return linkage_limit;
@@ -226,13 +221,14 @@ rlink_parseopts_set_linkage_limit( VALUE self, VALUE linkage_limit ) {
226
221
  * call-seq:
227
222
  * opts.linkage_limit -> fixnum
228
223
  *
229
- * This parameter determines the maximum number of linkages that are
230
- * considered in post-processing. If more than +linkage_limit+ linkages are found,
231
- * then a random sample of +linkage_limit+ is chosen for post-processing. When
224
+ * This parameter determines the maximum number of linkages that are
225
+ * considered in post-processing. If more than +linkage_limit+ linkages are found,
226
+ * then a random sample of +linkage_limit+ is chosen for post-processing. When
232
227
  * this happen a warning is displayed at verbosity levels greater than 1.
233
228
  */
234
229
  static VALUE
235
- rlink_parseopts_get_linkage_limit( VALUE self ) {
230
+ rlink_parseopts_get_linkage_limit( VALUE self )
231
+ {
236
232
  Parse_Options opts = get_parseopts( self );
237
233
  int rval;
238
234
 
@@ -245,12 +241,13 @@ rlink_parseopts_get_linkage_limit( VALUE self ) {
245
241
  * call-seq:
246
242
  * opts.disjunct_cost= fixnum
247
243
  *
248
- * Determines the maximum disjunct cost used during parsing, where the cost
249
- * of a disjunct is equal to the maximum cost of all of its connectors. The
250
- * default is that all disjuncts, no matter what their cost, are considered.
244
+ * Determines the maximum disjunct cost used during parsing, where the cost
245
+ * of a disjunct is equal to the maximum cost of all of its connectors. The
246
+ * default is that all disjuncts, no matter what their cost, are considered.
251
247
  */
252
248
  static VALUE
253
- rlink_parseopts_set_disjunct_cost( VALUE self, VALUE disjunct_cost ) {
249
+ rlink_parseopts_set_disjunct_cost( VALUE self, VALUE disjunct_cost )
250
+ {
254
251
  Parse_Options opts = get_parseopts( self );
255
252
  parse_options_set_disjunct_cost( opts, NUM2INT(disjunct_cost) );
256
253
  return disjunct_cost;
@@ -264,7 +261,8 @@ rlink_parseopts_set_disjunct_cost( VALUE self, VALUE disjunct_cost ) {
264
261
  * Get the maximum disjunct cost used during parsing.
265
262
  */
266
263
  static VALUE
267
- rlink_parseopts_get_disjunct_cost( VALUE self ) {
264
+ rlink_parseopts_get_disjunct_cost( VALUE self )
265
+ {
268
266
  Parse_Options opts = get_parseopts( self );
269
267
  int rval;
270
268
 
@@ -277,12 +275,13 @@ rlink_parseopts_get_disjunct_cost( VALUE self ) {
277
275
  * call-seq:
278
276
  * opts.min_null_count= fixnum -> fixnum
279
277
  *
280
- * Set the minimum of null links that a parse can have. A call to
281
- * LinkParser::Sentence#parse will find all linkages having the minimum
278
+ * Set the minimum of null links that a parse can have. A call to
279
+ * LinkParser::Sentence#parse will find all linkages having the minimum
282
280
  * number of null links within the range specified by this parameter.
283
281
  */
284
282
  static VALUE
285
- rlink_parseopts_set_min_null_count( VALUE self, VALUE null_count ) {
283
+ rlink_parseopts_set_min_null_count( VALUE self, VALUE null_count )
284
+ {
286
285
  Parse_Options opts = get_parseopts( self );
287
286
  parse_options_set_min_null_count( opts, NUM2INT(null_count) );
288
287
  return null_count;
@@ -296,7 +295,8 @@ rlink_parseopts_set_min_null_count( VALUE self, VALUE null_count ) {
296
295
  * Get the minimum of null links that a parse can have.
297
296
  */
298
297
  static VALUE
299
- rlink_parseopts_get_min_null_count( VALUE self ) {
298
+ rlink_parseopts_get_min_null_count( VALUE self )
299
+ {
300
300
  Parse_Options opts = get_parseopts( self );
301
301
  int rval;
302
302
 
@@ -312,7 +312,8 @@ rlink_parseopts_get_min_null_count( VALUE self ) {
312
312
  * Set the maximum number of null links allowed in a parse.
313
313
  */
314
314
  static VALUE
315
- rlink_parseopts_set_max_null_count( VALUE self, VALUE null_count ) {
315
+ rlink_parseopts_set_max_null_count( VALUE self, VALUE null_count )
316
+ {
316
317
  Parse_Options opts = get_parseopts( self );
317
318
  parse_options_set_max_null_count( opts, NUM2INT(null_count) );
318
319
  return null_count;
@@ -326,7 +327,8 @@ rlink_parseopts_set_max_null_count( VALUE self, VALUE null_count ) {
326
327
  * Get the maximum number of null links allowed in a parse.
327
328
  */
328
329
  static VALUE
329
- rlink_parseopts_get_max_null_count( VALUE self ) {
330
+ rlink_parseopts_get_max_null_count( VALUE self )
331
+ {
330
332
  Parse_Options opts = get_parseopts( self );
331
333
  int rval;
332
334
 
@@ -335,53 +337,21 @@ rlink_parseopts_get_max_null_count( VALUE self ) {
335
337
  }
336
338
 
337
339
 
338
- /*
339
- * call-seq:
340
- * opts.null_block= null_block
341
- *
342
- * Set the null_block option to the specified value. The null_block option
343
- * allows null links to be counted in "bunches." For example, if null_block
344
- * is 4, then a linkage with 1,2,3 or 4 null links has a null cost of 1, a
345
- * linkage with 5,6,7 or 8 null links has a null cost of 2, etc.
346
- */
347
- static VALUE
348
- rlink_parseopts_set_null_block( VALUE self, VALUE null_block ) {
349
- Parse_Options opts = get_parseopts( self );
350
- parse_options_set_null_block( opts, NUM2INT(null_block) );
351
- return null_block;
352
- }
353
-
354
-
355
- /*
356
- * call-seq:
357
- * opts.null_block -> fixnum
358
- *
359
- * Get the value of the null_block option.
360
- */
361
- static VALUE
362
- rlink_parseopts_get_null_block( VALUE self ) {
363
- Parse_Options opts = get_parseopts( self );
364
- int rval;
365
-
366
- rval = parse_options_get_null_block( opts );
367
- return INT2FIX( rval );
368
- }
369
-
370
-
371
340
  /*
372
341
  * call-seq:
373
342
  * opts.islands_ok= boolean
374
343
  *
375
- * This option determines whether or not "islands" of links are allowed. For
344
+ * This option determines whether or not "islands" of links are allowed. For
376
345
  * example, the following linkage has an island:
377
346
  *
378
- * +------Wd-----+
347
+ * +------Wd-----+
379
348
  * | +--Dsu--+---Ss--+-Paf-+ +--Dsu--+---Ss--+--Pa-+
380
349
  * | | | | | | | | |
381
350
  * ///// this sentence.n is.v false.a this sentence.n is.v true.a
382
351
  */
383
352
  static VALUE
384
- rlink_parseopts_set_islands_ok( VALUE self, VALUE islands_ok ) {
353
+ rlink_parseopts_set_islands_ok( VALUE self, VALUE islands_ok )
354
+ {
385
355
  Parse_Options opts = get_parseopts( self );
386
356
  parse_options_set_islands_ok( opts, RTEST(islands_ok) );
387
357
  return islands_ok;
@@ -395,7 +365,8 @@ rlink_parseopts_set_islands_ok( VALUE self, VALUE islands_ok ) {
395
365
  * Get the value of the islands_ok option.
396
366
  */
397
367
  static VALUE
398
- rlink_parseopts_get_islands_ok_p( VALUE self ) {
368
+ rlink_parseopts_get_islands_ok_p( VALUE self )
369
+ {
399
370
  Parse_Options opts = get_parseopts( self );
400
371
  int rval;
401
372
 
@@ -408,14 +379,15 @@ rlink_parseopts_get_islands_ok_p( VALUE self ) {
408
379
  * call-seq:
409
380
  * opts.short_length= fixnum
410
381
  *
411
- * The short_length parameter determines how long the links are allowed to
412
- * be. The intended use of this is to speed up parsing by not considering
413
- * very long links for most connectors, since they are very rarely used in a
414
- * correct parse. An entry for UNLIMITED-CONNECTORS in the dictionary will
382
+ * The short_length parameter determines how long the links are allowed to
383
+ * be. The intended use of this is to speed up parsing by not considering
384
+ * very long links for most connectors, since they are very rarely used in a
385
+ * correct parse. An entry for UNLIMITED-CONNECTORS in the dictionary will
415
386
  * specify which connectors are exempt from the length limit.
416
387
  */
417
388
  static VALUE
418
- rlink_parseopts_set_short_length( VALUE self, VALUE short_length ) {
389
+ rlink_parseopts_set_short_length( VALUE self, VALUE short_length )
390
+ {
419
391
  Parse_Options opts = get_parseopts( self );
420
392
  parse_options_set_short_length( opts, NUM2INT(short_length) );
421
393
  return short_length;
@@ -429,7 +401,8 @@ rlink_parseopts_set_short_length( VALUE self, VALUE short_length ) {
429
401
  * Get the value of the short_length option.
430
402
  */
431
403
  static VALUE
432
- rlink_parseopts_get_short_length( VALUE self ) {
404
+ rlink_parseopts_get_short_length( VALUE self )
405
+ {
433
406
  Parse_Options opts = get_parseopts( self );
434
407
  int rval;
435
408
 
@@ -442,13 +415,14 @@ rlink_parseopts_get_short_length( VALUE self ) {
442
415
  * call-seq:
443
416
  * opts.max_memory= fixnum
444
417
  *
445
- * Determines the maximum memory allowed during parsing. This is used just as
446
- * max_parse_time is, so that the parsing process is terminated as quickly as
447
- * possible after the total memory (including that allocated to all
418
+ * Determines the maximum memory allowed during parsing. This is used just as
419
+ * max_parse_time is, so that the parsing process is terminated as quickly as
420
+ * possible after the total memory (including that allocated to all
448
421
  * dictionaries, etc.) exceeds the maximum allowed.
449
422
  */
450
423
  static VALUE
451
- rlink_parseopts_set_max_memory( VALUE self, VALUE mem ) {
424
+ rlink_parseopts_set_max_memory( VALUE self, VALUE mem )
425
+ {
452
426
  Parse_Options opts = get_parseopts( self );
453
427
  parse_options_set_max_memory( opts, NUM2INT(mem) );
454
428
  return mem;
@@ -462,7 +436,8 @@ rlink_parseopts_set_max_memory( VALUE self, VALUE mem ) {
462
436
  * Get the value of the max_memory option.
463
437
  */
464
438
  static VALUE
465
- rlink_parseopts_get_max_memory( VALUE self ) {
439
+ rlink_parseopts_get_max_memory( VALUE self )
440
+ {
466
441
  Parse_Options opts = get_parseopts( self );
467
442
  int rval;
468
443
 
@@ -471,48 +446,19 @@ rlink_parseopts_get_max_memory( VALUE self ) {
471
446
  }
472
447
 
473
448
 
474
- /*
475
- * call-seq:
476
- * opts.max_sentence_length= fixnum
477
- *
478
- * Determines the maximum length of a parsed sentence.
479
- */
480
- static VALUE
481
- rlink_parseopts_set_max_sentence_length( VALUE self, VALUE len ) {
482
- Parse_Options opts = get_parseopts( self );
483
- parse_options_set_max_sentence_length( opts, NUM2INT(len) );
484
- return len;
485
- }
486
-
487
-
488
- /*
489
- * call-seq:
490
- * opts.max_sentence_length -> fixnum
491
- *
492
- * Get the value of the max_sentence_length option.
493
- */
494
- static VALUE
495
- rlink_parseopts_get_max_sentence_length( VALUE self ) {
496
- Parse_Options opts = get_parseopts( self );
497
- int rval;
498
-
499
- rval = parse_options_get_max_sentence_length( opts );
500
- return INT2FIX( rval );
501
- }
502
-
503
-
504
449
  /*
505
450
  * call-seq:
506
451
  * opts.max_parse_time= seconds
507
452
  *
508
- * Determines the approximate maximum time that parsing is allowed to take.
509
- * The way it works is that after this time has expired, the parsing process
510
- * is artificially forced to complete quickly by pretending that no further
511
- * solutions (entries in the hash table) can be constructed. The actual
453
+ * Determines the approximate maximum time that parsing is allowed to take.
454
+ * The way it works is that after this time has expired, the parsing process
455
+ * is artificially forced to complete quickly by pretending that no further
456
+ * solutions (entries in the hash table) can be constructed. The actual
512
457
  * parsing time might be slightly longer.
513
458
  */
514
459
  static VALUE
515
- rlink_parseopts_set_max_parse_time( VALUE self, VALUE secs ) {
460
+ rlink_parseopts_set_max_parse_time( VALUE self, VALUE secs )
461
+ {
516
462
  Parse_Options opts = get_parseopts( self );
517
463
  parse_options_set_max_parse_time( opts, NUM2INT(secs) );
518
464
  return secs;
@@ -526,7 +472,8 @@ rlink_parseopts_set_max_parse_time( VALUE self, VALUE secs ) {
526
472
  * Get the number of seconds of the max_parse_time option.
527
473
  */
528
474
  static VALUE
529
- rlink_parseopts_get_max_parse_time( VALUE self ) {
475
+ rlink_parseopts_get_max_parse_time( VALUE self )
476
+ {
530
477
  Parse_Options opts = get_parseopts( self );
531
478
  int rval;
532
479
 
@@ -535,106 +482,17 @@ rlink_parseopts_get_max_parse_time( VALUE self ) {
535
482
  }
536
483
 
537
484
 
538
- /*
539
- * call-seq:
540
- * opts.screen_width= columns
541
- *
542
- * Set the screen width assumed by the diagramming functions.
543
- */
544
- static VALUE
545
- rlink_parseopts_set_screen_width( VALUE self, VALUE val ) {
546
- Parse_Options opts = get_parseopts( self );
547
- parse_options_set_screen_width( opts, NUM2INT(val) );
548
- return val;
549
- }
550
-
551
-
552
- /*
553
- * call-seq:
554
- * opts.screen_width -> fixnum
555
- *
556
- * Get the screen width assumed by the diagramming functions.
557
- */
558
- static VALUE
559
- rlink_parseopts_get_screen_width( VALUE self ) {
560
- Parse_Options opts = get_parseopts( self );
561
- int rval;
562
-
563
- rval = parse_options_get_screen_width( opts );
564
- return INT2FIX( rval );
565
- }
566
-
567
-
568
- /*
569
- * call-seq:
570
- * opts.allow_null= boolean
571
- *
572
- * Indicates whether or not linkages are allowed to have null links.
573
- */
574
- static VALUE
575
- rlink_parseopts_set_allow_null( VALUE self, VALUE val ) {
576
- Parse_Options opts = get_parseopts( self );
577
- parse_options_set_allow_null( opts, RTEST(val) );
578
- return val;
579
- }
580
-
581
-
582
- /*
583
- * call-seq:
584
- * opts.allow_null? -> true or false
585
- *
586
- * Get the value of the allow_null option.
587
- */
588
- static VALUE
589
- rlink_parseopts_get_allow_null_p( VALUE self ) {
590
- Parse_Options opts = get_parseopts( self );
591
- int rval;
592
-
593
- rval = parse_options_get_allow_null( opts );
594
- return rval ? Qtrue : Qfalse;
595
- }
596
-
597
-
598
- /*
599
- * call-seq:
600
- * opts.display_walls= boolean
601
- *
602
- * Whether or not to show the wall word(s) when a linkage diagram is printed.
603
- */
604
- static VALUE
605
- rlink_parseopts_set_display_walls( VALUE self, VALUE val ) {
606
- Parse_Options opts = get_parseopts( self );
607
- parse_options_set_display_walls( opts, RTEST(val) );
608
- return val;
609
- }
610
-
611
-
612
- /*
613
- * call-seq:
614
- * opts.display_walls? -> true or false
615
- *
616
- * Whether or not to show the wall word(s) when a linkage diagram is printed.
617
- */
618
- static VALUE
619
- rlink_parseopts_get_display_walls_p( VALUE self ) {
620
- Parse_Options opts = get_parseopts( self );
621
- int rval;
622
-
623
- rval = parse_options_get_display_walls( opts );
624
- return rval ? Qtrue : Qfalse;
625
- }
626
-
627
-
628
485
  /*
629
486
  * call-seq:
630
487
  * opts.all_short_connectors= boolean
631
488
  *
632
- * If true, then all connectors have length restrictions imposed on them --
633
- * they can be no farther than short_length apart. This is used when parsing
489
+ * If true, then all connectors have length restrictions imposed on them --
490
+ * they can be no farther than short_length apart. This is used when parsing
634
491
  * in "panic" mode, for example.
635
492
  */
636
493
  static VALUE
637
- rlink_parseopts_set_all_short_connectors( VALUE self, VALUE val ) {
494
+ rlink_parseopts_set_all_short_connectors( VALUE self, VALUE val )
495
+ {
638
496
  Parse_Options opts = get_parseopts( self );
639
497
  parse_options_set_all_short_connectors( opts, RTEST(val) );
640
498
  return val;
@@ -648,7 +506,8 @@ rlink_parseopts_set_all_short_connectors( VALUE self, VALUE val ) {
648
506
  * Get the value of the all_short_connectors option.
649
507
  */
650
508
  static VALUE
651
- rlink_parseopts_get_all_short_connectors_p( VALUE self ) {
509
+ rlink_parseopts_get_all_short_connectors_p( VALUE self )
510
+ {
652
511
  Parse_Options opts = get_parseopts( self );
653
512
  int rval;
654
513
 
@@ -659,321 +518,75 @@ rlink_parseopts_get_all_short_connectors_p( VALUE self ) {
659
518
 
660
519
  /*
661
520
  * call-seq:
662
- * opts.cost_model_type=
521
+ * opts.cost_model_type = :vdal
522
+ * opts.cost_model_type = :corpus
663
523
  *
664
- * The cost model type for ranking linkages, which is an index into an array
665
- * of function pointers. The current code only has a single entry, but others
666
- * could easily be added.
667
- */
668
- static VALUE
669
- rlink_parseopts_set_cost_model_type( VALUE self, VALUE cm ) {
670
- Parse_Options opts = get_parseopts( self );
671
- parse_options_set_cost_model_type( opts, NUM2INT(cm) );
672
- return cm;
673
- }
674
-
675
-
676
- /*
677
- * call-seq:
678
- * opts.cost_model_type -> fixnum
524
+ * The cost model type for ranking linkages. Currently, there are two models: VDAL (:vdal)
525
+ * and CORPUS (:corpus). The VDAL model ranks parses from lowest to highest cost in and-cost,
526
+ * disjunct-cost, unused-word-cost and structure-violations-cost. The CORPUS model ranks
527
+ * parses according to the frequency of use of disjuncts, based on a statistical analysis
528
+ * of a collection of texts. If you haven't compiled the link-grammar library with support
529
+ * for the CORPUS cost model, attempting to set it to this will raise an exception.
679
530
  *
680
- * Get the cost model type for ranking linkages.
681
531
  */
682
- /*
683
-
684
- There's no actual API function for getting the cost_model_type. I guess if
685
- there's ever more than one model type defined there will be.
686
-
687
532
  static VALUE
688
- rlink_parseopts_get_cost_model_type( VALUE self ) {
533
+ rlink_parseopts_set_cost_model_type( VALUE self, VALUE model_name )
534
+ {
689
535
  Parse_Options opts = get_parseopts( self );
690
- int rval;
691
-
692
- rval = parse_options_get_cost_model_type( opts );
693
- return INT2FIX( rval );
694
- }
695
- */
696
-
536
+ Cost_Model_type model;
697
537
 
698
- /*
699
- * call-seq:
700
- * opts.batch_mode= boolean
701
- *
702
- * Enable or disable "batch mode."
703
- *
704
- * :TODO: Figure out what batch mode is.
705
- */
706
- static VALUE
707
- rlink_parseopts_set_batch_mode( VALUE self, VALUE val ) {
708
- Parse_Options opts = get_parseopts( self );
709
- parse_options_set_batch_mode( opts, RTEST(val) );
710
- return val;
711
- }
712
-
713
-
714
- /*
715
- * call-seq:
716
- * opts.batch_mode? -> true or false
717
- *
718
- * Returns +true+ if batch mode is enabled.
719
- */
720
- static VALUE
721
- rlink_parseopts_get_batch_mode_p( VALUE self ) {
722
- Parse_Options opts = get_parseopts( self );
723
- int rval;
724
-
725
- rval = parse_options_get_batch_mode( opts );
726
- return rval ? Qtrue : Qfalse;
727
- }
728
-
729
- /*
730
- * call-seq:
731
- * opts.panic_mode= boolean
732
- *
733
- * Enable or disable "panic mode."
734
- *
735
- * :TODO: Figure out what enabling this option does. I only know about panic
736
- * mode in the parser -- does this allow/disallow the parser from entering it?
737
- */
738
- static VALUE
739
- rlink_parseopts_set_panic_mode( VALUE self, VALUE val ) {
740
- Parse_Options opts = get_parseopts( self );
741
- parse_options_set_panic_mode( opts, RTEST(val) );
742
- return val;
743
- }
744
-
745
-
746
- /*
747
- * call-seq:
748
- * opts.panic_mode? -> true or false
749
- *
750
- * Returns +true+ if panic mode is enabled.
751
- */
752
- static VALUE
753
- rlink_parseopts_get_panic_mode_p( VALUE self ) {
754
- Parse_Options opts = get_parseopts( self );
755
- int rval;
756
-
757
- rval = parse_options_get_panic_mode( opts );
758
- return rval ? Qtrue : Qfalse;
759
- }
760
-
761
-
762
- /*
763
- * call-seq:
764
- * opts.display_on= boolean
765
- *
766
- * Enable/disable display.
767
- *
768
- * :TODO: Figure out what this setting does.
769
- *
770
- */
771
- static VALUE
772
- rlink_parseopts_set_display_on( VALUE self, VALUE val ) {
773
- Parse_Options opts = get_parseopts( self );
774
- parse_options_set_display_on( opts, RTEST(val) );
775
- return val;
776
- }
777
-
778
-
779
- /*
780
- * call-seq:
781
- * opts.display_on? -> true or false
782
- *
783
- * Returns +true+ if ...?
784
- */
785
- static VALUE
786
- rlink_parseopts_get_display_on_p( VALUE self ) {
787
- Parse_Options opts = get_parseopts( self );
788
- int rval;
789
-
790
- rval = parse_options_get_display_on( opts );
791
- return rval ? Qtrue : Qfalse;
792
- }
793
-
794
-
795
- /*
796
- * call-seq:
797
- * opts.display_postscript= boolean
798
- *
799
- * Enable/disable display using Postscript.
800
- */
801
- static VALUE
802
- rlink_parseopts_set_display_postscript( VALUE self, VALUE val ) {
803
- Parse_Options opts = get_parseopts( self );
804
- parse_options_set_display_postscript( opts, RTEST(val) );
805
- return val;
806
- }
807
-
808
-
809
- /*
810
- * call-seq:
811
- * opts.display_postscript? -> true or false
812
- *
813
- * Returns +true+ if display should use Postscript instead of plain text.
814
- */
815
- static VALUE
816
- rlink_parseopts_get_display_postscript_p( VALUE self ) {
817
- Parse_Options opts = get_parseopts( self );
818
- int rval;
819
-
820
- rval = parse_options_get_display_postscript( opts );
821
- return rval ? Qtrue : Qfalse;
822
- }
823
-
824
-
825
- /*
826
- * call-seq:
827
- * opts.display_constituents= boolean
828
- *
829
- * Set the display_constituents option to the specified value.
830
- */
831
- static VALUE
832
- rlink_parseopts_set_display_constituents( VALUE self, VALUE val ) {
833
- Parse_Options opts = get_parseopts( self );
834
- parse_options_set_display_constituents( opts, RTEST(val) );
835
- return val;
836
- }
837
-
838
-
839
- /*
840
- * call-seq:
841
- * opts.display_constituents? -> true or false
842
- *
843
- * Get the value of the display_constituents option.
844
- */
845
- static VALUE
846
- rlink_parseopts_get_display_constituents_p( VALUE self ) {
847
- Parse_Options opts = get_parseopts( self );
848
- int rval;
849
-
850
- rval = parse_options_get_display_constituents( opts );
851
- return rval ? Qtrue : Qfalse;
852
- }
853
-
854
-
855
- /*
856
- * call-seq:
857
- * opts.display_bad= boolean
858
- *
859
- * Set the display_bad option to the specified value.
860
- */
861
- static VALUE
862
- rlink_parseopts_set_display_bad( VALUE self, VALUE val ) {
863
- Parse_Options opts = get_parseopts( self );
864
- parse_options_set_display_bad( opts, RTEST(val) );
865
- return val;
866
- }
867
-
868
-
869
- /*
870
- * call-seq:
871
- * opts.display_bad? -> true or false
872
- *
873
- * Get the value of the display_bad option.
874
- */
875
- static VALUE
876
- rlink_parseopts_get_display_bad_p( VALUE self ) {
877
- Parse_Options opts = get_parseopts( self );
878
- int rval;
879
-
880
- rval = parse_options_get_display_bad( opts );
881
- return rval ? Qtrue : Qfalse;
882
- }
883
-
884
-
885
- /*
886
- * call-seq:
887
- * opts.display_links= boolean
888
- *
889
- * Set the display_links option to the specified value.
890
- */
891
- static VALUE
892
- rlink_parseopts_set_display_links( VALUE self, VALUE val ) {
893
- Parse_Options opts = get_parseopts( self );
894
- parse_options_set_display_links( opts, RTEST(val) );
895
- return val;
896
- }
897
-
898
-
899
- /*
900
- * call-seq:
901
- * opts.display_links? -> true or false
902
- *
903
- * Get the value of the display_links option.
904
- */
905
- static VALUE
906
- rlink_parseopts_get_display_links_p( VALUE self ) {
907
- Parse_Options opts = get_parseopts( self );
908
- int rval;
909
-
910
- rval = parse_options_get_display_links( opts );
911
- return rval ? Qtrue : Qfalse;
912
- }
913
-
914
-
915
- /*
916
- * call-seq:
917
- * opts.display_union= boolean
918
- *
919
- * Set the display_union option to the specified value.
920
- */
921
- static VALUE
922
- rlink_parseopts_set_display_union( VALUE self, VALUE val ) {
923
- Parse_Options opts = get_parseopts( self );
924
- parse_options_set_display_union( opts, RTEST(val) );
925
- return val;
926
- }
538
+ if ( model_name == vdal_sym ) {
539
+ rlink_log_obj( self, "debug", "Selected the 'VDAL' cost model" );
540
+ model = VDAL;
541
+ } else if ( model_name == corpus_sym ) {
542
+ rlink_log_obj( self, "debug", "Selected the 'CORPUS' cost model" );
543
+ model = CORPUS;
544
+ } else {
545
+ rb_raise( rb_eArgError, "Unknown cost model %s (expected either :vdal or :corpus).",
546
+ RSTRING_PTR(rb_inspect( model_name )) );
547
+ }
927
548
 
549
+ rlink_log_obj( self, "info", "Setting the cost model to %s", model == VDAL ? "VDAL" : "CORPUS" );
550
+ parse_options_reset_resources( opts );
551
+ parse_options_set_cost_model_type( opts, model );
928
552
 
929
- /*
930
- * call-seq:
931
- * opts.display_union? -> true or false
932
- *
933
- * Get the value of the display_union option.
934
- */
935
- static VALUE
936
- rlink_parseopts_get_display_union_p( VALUE self ) {
937
- Parse_Options opts = get_parseopts( self );
938
- int rval;
553
+ if ( parse_options_get_cost_model_type(opts) != model ) {
554
+ rb_raise( rb_eArgError,
555
+ "Couldn't set the cost model: is link-grammar possibly compiled without it?" );
556
+ }
939
557
 
940
- rval = parse_options_get_display_union( opts );
941
- return rval ? Qtrue : Qfalse;
558
+ return model_name;
942
559
  }
943
560
 
944
561
 
945
562
  /*
946
563
  * call-seq:
947
- * opts.echo_on= boolean
564
+ * opts.cost_model_type -> Symbol
948
565
  *
949
- * Set the echo_on option to the specified value.
566
+ * Get the cost model type for ranking linkages.
950
567
  */
951
568
  static VALUE
952
- rlink_parseopts_set_echo_on( VALUE self, VALUE val ) {
569
+ rlink_parseopts_get_cost_model_type( VALUE self )
570
+ {
953
571
  Parse_Options opts = get_parseopts( self );
954
- parse_options_set_echo_on( opts, RTEST(val) );
955
- return val;
956
- }
957
-
572
+ Cost_Model_type model = parse_options_get_cost_model_type( opts );
573
+ VALUE model_name = Qnil;
958
574
 
959
- /*
960
- * call-seq:
961
- * opts.echo_on? -> true or false
962
- *
963
- * Get the value of the echo_on option.
964
- */
965
- static VALUE
966
- rlink_parseopts_get_echo_on_p( VALUE self ) {
967
- Parse_Options opts = get_parseopts( self );
968
- int rval;
575
+ switch( model ) {
576
+ case VDAL:
577
+ model_name = vdal_sym;
578
+ break;
579
+ case CORPUS:
580
+ model_name = corpus_sym;
581
+ break;
582
+ default:
583
+ rb_bug( "Unhandled cost model type %d", model );
584
+ }
969
585
 
970
- rval = parse_options_get_echo_on( opts );
971
- return rval ? Qtrue : Qfalse;
586
+ return model_name;
972
587
  }
973
588
 
974
589
 
975
-
976
-
977
590
  /*
978
591
  * call-seq:
979
592
  * opts.spell_guessing_enabled= boolean
@@ -981,7 +594,8 @@ rlink_parseopts_get_echo_on_p( VALUE self ) {
981
594
  * Enable/disable spell-guessing if it's supported.
982
595
  */
983
596
  static VALUE
984
- rlink_parseopts_set_spell_guess( VALUE self, VALUE val ) {
597
+ rlink_parseopts_set_spell_guess( VALUE self, VALUE val )
598
+ {
985
599
  #ifdef HAVE_PARSE_OPTIONS_GET_SPELL_GUESS
986
600
  Parse_Options opts = get_parseopts( self );
987
601
  parse_options_set_spell_guess( opts, RTEST(val) );
@@ -1001,7 +615,8 @@ rlink_parseopts_set_spell_guess( VALUE self, VALUE val ) {
1001
615
  * mean that it's supported, only that it will be used if it is.
1002
616
  */
1003
617
  static VALUE
1004
- rlink_parseopts_get_spell_guess_p( VALUE self ) {
618
+ rlink_parseopts_get_spell_guess_p( VALUE self )
619
+ {
1005
620
  #ifdef HAVE_PARSE_OPTIONS_GET_SPELL_GUESS
1006
621
  Parse_Options opts = get_parseopts( self );
1007
622
  int rval;
@@ -1027,7 +642,8 @@ rlink_parseopts_get_spell_guess_p( VALUE self ) {
1027
642
  * end
1028
643
  */
1029
644
  static VALUE
1030
- rlink_parseopts_timer_expired_p( VALUE self ) {
645
+ rlink_parseopts_timer_expired_p( VALUE self )
646
+ {
1031
647
  Parse_Options opts = get_parseopts( self );
1032
648
  int rval;
1033
649
 
@@ -1048,7 +664,8 @@ rlink_parseopts_timer_expired_p( VALUE self ) {
1048
664
  * end
1049
665
  */
1050
666
  static VALUE
1051
- rlink_parseopts_memory_exhausted_p( VALUE self ) {
667
+ rlink_parseopts_memory_exhausted_p( VALUE self )
668
+ {
1052
669
  Parse_Options opts = get_parseopts( self );
1053
670
  int rval;
1054
671
 
@@ -1069,7 +686,8 @@ rlink_parseopts_memory_exhausted_p( VALUE self ) {
1069
686
  * end
1070
687
  */
1071
688
  static VALUE
1072
- rlink_parseopts_resources_exhausted_p( VALUE self ) {
689
+ rlink_parseopts_resources_exhausted_p( VALUE self )
690
+ {
1073
691
  Parse_Options opts = get_parseopts( self );
1074
692
  int rval;
1075
693
 
@@ -1086,7 +704,8 @@ rlink_parseopts_resources_exhausted_p( VALUE self ) {
1086
704
  *
1087
705
  */
1088
706
  static VALUE
1089
- rlink_parseopts_reset_resources( VALUE self ) {
707
+ rlink_parseopts_reset_resources( VALUE self )
708
+ {
1090
709
  Parse_Options opts = get_parseopts( self );
1091
710
 
1092
711
  parse_options_reset_resources( opts );
@@ -1095,142 +714,52 @@ rlink_parseopts_reset_resources( VALUE self ) {
1095
714
 
1096
715
 
1097
716
 
1098
- /*
1099
- * LinkParser parse options class. Instances of this class are used to specify the different
1100
- * parameters that are used to parse sentences. Examples of the kinds of things that are
1101
- * controlled by ParseOptions include maximum parsing time and memory, whether to use
1102
- * null-links, and whether or not to use "panic" mode. This data structure is passed in to
1103
- * the various parsing and printing routines along with the sentence.
1104
- *
1105
- */
1106
717
  void
1107
- rlink_init_parseoptions() {
718
+ rlink_init_parseoptions()
719
+ {
1108
720
  rlink_cParseOptions = rb_define_class_under( rlink_mLinkParser,
1109
721
  "ParseOptions", rb_cObject );
1110
722
 
723
+ vdal_sym = ID2SYM( rb_intern("vdal") );
724
+ corpus_sym = ID2SYM( rb_intern("corpus") );
725
+
1111
726
  rb_define_alloc_func( rlink_cParseOptions, rlink_parseopts_s_alloc );
1112
727
  rb_define_method( rlink_cParseOptions, "initialize", rlink_parseopts_init, -1 );
728
+ rb_define_method( rlink_cParseOptions, "initialize_copy", rlink_parseopts_init_copy, 1 );
1113
729
  /*
1114
730
  rb_define_method( rlink_cParseOptions, "merge", rlink_parseopts_merge, 1 );
1115
731
  rb_define_method( rlink_cParseOptions, "merge!", rlink_parseopts_merge_bang, 1 );
1116
732
  */
1117
- rb_define_method( rlink_cParseOptions, "verbosity=",
1118
- rlink_parseopts_set_verbosity, 1 );
1119
- rb_define_method( rlink_cParseOptions, "verbosity",
1120
- rlink_parseopts_get_verbosity, 0 );
1121
- rb_define_method( rlink_cParseOptions, "linkage_limit=",
1122
- rlink_parseopts_set_linkage_limit, 1 );
1123
- rb_define_method( rlink_cParseOptions, "linkage_limit",
1124
- rlink_parseopts_get_linkage_limit, 0 );
1125
- rb_define_method( rlink_cParseOptions, "disjunct_cost=",
1126
- rlink_parseopts_set_disjunct_cost, 1 );
1127
- rb_define_method( rlink_cParseOptions, "disjunct_cost",
1128
- rlink_parseopts_get_disjunct_cost, 0 );
1129
- rb_define_method( rlink_cParseOptions, "min_null_count=",
1130
- rlink_parseopts_set_min_null_count, 1 );
1131
- rb_define_method( rlink_cParseOptions, "min_null_count",
1132
- rlink_parseopts_get_min_null_count, 0 );
1133
- rb_define_method( rlink_cParseOptions, "max_null_count=",
1134
- rlink_parseopts_set_max_null_count, 1 );
1135
- rb_define_method( rlink_cParseOptions, "max_null_count",
1136
- rlink_parseopts_get_max_null_count, 0 );
1137
- rb_define_method( rlink_cParseOptions, "null_block=",
1138
- rlink_parseopts_set_null_block, 1 );
1139
- rb_define_method( rlink_cParseOptions, "null_block",
1140
- rlink_parseopts_get_null_block, 0 );
1141
- rb_define_method( rlink_cParseOptions, "islands_ok=",
1142
- rlink_parseopts_set_islands_ok, 1 );
1143
- rb_define_method( rlink_cParseOptions, "islands_ok?",
1144
- rlink_parseopts_get_islands_ok_p, 0 );
1145
- rb_define_method( rlink_cParseOptions, "short_length=",
1146
- rlink_parseopts_set_short_length, 1 );
1147
- rb_define_method( rlink_cParseOptions, "short_length",
1148
- rlink_parseopts_get_short_length, 0 );
1149
- rb_define_method( rlink_cParseOptions, "max_memory=",
1150
- rlink_parseopts_set_max_memory, 1 );
1151
- rb_define_method( rlink_cParseOptions, "max_memory",
1152
- rlink_parseopts_get_max_memory, 0 );
1153
- rb_define_method( rlink_cParseOptions, "max_sentence_length=",
1154
- rlink_parseopts_set_max_sentence_length, 1 );
1155
- rb_define_method( rlink_cParseOptions, "max_sentence_length",
1156
- rlink_parseopts_get_max_sentence_length, 0 );
1157
- rb_define_method( rlink_cParseOptions, "max_parse_time=",
1158
- rlink_parseopts_set_max_parse_time, 1 );
1159
- rb_define_method( rlink_cParseOptions, "max_parse_time",
1160
- rlink_parseopts_get_max_parse_time, 0 );
1161
- rb_define_method( rlink_cParseOptions, "screen_width=",
1162
- rlink_parseopts_set_screen_width, 1 );
1163
- rb_define_method( rlink_cParseOptions, "screen_width",
1164
- rlink_parseopts_get_screen_width, 0 );
1165
- rb_define_method( rlink_cParseOptions, "allow_null=",
1166
- rlink_parseopts_set_allow_null, 1 );
1167
- rb_define_method( rlink_cParseOptions, "allow_null?",
1168
- rlink_parseopts_get_allow_null_p, 0 );
1169
- rb_define_method( rlink_cParseOptions, "display_walls=",
1170
- rlink_parseopts_set_display_walls, 1 );
1171
- rb_define_method( rlink_cParseOptions, "display_walls?",
1172
- rlink_parseopts_get_display_walls_p, 0 );
1173
- rb_define_method( rlink_cParseOptions, "all_short_connectors=",
1174
- rlink_parseopts_set_all_short_connectors, 1 );
1175
- rb_define_method( rlink_cParseOptions, "all_short_connectors?",
1176
- rlink_parseopts_get_all_short_connectors_p, 0 );
1177
- rb_define_method( rlink_cParseOptions, "cost_model_type=",
1178
- rlink_parseopts_set_cost_model_type, 1 );
1179
-
1180
- /* (No way to get the cost_model_type from the API)
1181
-
1182
- rb_define_method( rlink_cParseOptions, "cost_model_type",
1183
- rlink_parseopts_get_cost_model_type, 0 );
1184
- */
1185
- rb_define_method( rlink_cParseOptions, "batch_mode=",
1186
- rlink_parseopts_set_batch_mode, 1 );
1187
- rb_define_method( rlink_cParseOptions, "batch_mode?",
1188
- rlink_parseopts_get_batch_mode_p, 0 );
1189
- rb_define_method( rlink_cParseOptions, "panic_mode=",
1190
- rlink_parseopts_set_panic_mode, 1 );
1191
- rb_define_method( rlink_cParseOptions, "panic_mode?",
1192
- rlink_parseopts_get_panic_mode_p, 0 );
1193
- rb_define_method( rlink_cParseOptions, "display_on=",
1194
- rlink_parseopts_set_display_on, 1 );
1195
- rb_define_method( rlink_cParseOptions, "display_on?",
1196
- rlink_parseopts_get_display_on_p, 0 );
1197
- rb_define_method( rlink_cParseOptions, "display_postscript=",
1198
- rlink_parseopts_set_display_postscript, 1 );
1199
- rb_define_method( rlink_cParseOptions, "display_postscript?",
1200
- rlink_parseopts_get_display_postscript_p, 0 );
1201
- rb_define_method( rlink_cParseOptions, "display_constituents=",
1202
- rlink_parseopts_set_display_constituents, 1 );
1203
- rb_define_method( rlink_cParseOptions, "display_constituents?",
1204
- rlink_parseopts_get_display_constituents_p, 0 );
1205
- rb_define_method( rlink_cParseOptions, "display_bad=",
1206
- rlink_parseopts_set_display_bad, 1 );
1207
- rb_define_method( rlink_cParseOptions, "display_bad?",
1208
- rlink_parseopts_get_display_bad_p, 0 );
1209
- rb_define_method( rlink_cParseOptions, "display_links=",
1210
- rlink_parseopts_set_display_links, 1 );
1211
- rb_define_method( rlink_cParseOptions, "display_links?",
1212
- rlink_parseopts_get_display_links_p, 0 );
1213
- rb_define_method( rlink_cParseOptions, "display_union=",
1214
- rlink_parseopts_set_display_union, 1 );
1215
- rb_define_method( rlink_cParseOptions, "display_union?",
1216
- rlink_parseopts_get_display_union_p, 0 );
1217
- rb_define_method( rlink_cParseOptions, "echo_on=",
1218
- rlink_parseopts_set_echo_on, 1 );
1219
- rb_define_method( rlink_cParseOptions, "echo_on?",
1220
- rlink_parseopts_get_echo_on_p, 0 );
1221
- rb_define_method( rlink_cParseOptions, "spell_guessing_enabled=",
1222
- rlink_parseopts_set_spell_guess, 1 );
1223
- rb_define_method( rlink_cParseOptions, "spell_guessing_enabled?",
1224
- rlink_parseopts_get_spell_guess_p, 0 );
1225
-
1226
- rb_define_method( rlink_cParseOptions, "timer_expired?",
1227
- rlink_parseopts_timer_expired_p, 0 );
1228
- rb_define_method( rlink_cParseOptions, "memory_exhausted?",
1229
- rlink_parseopts_memory_exhausted_p, 0 );
1230
- rb_define_method( rlink_cParseOptions, "resources_exhausted?",
1231
- rlink_parseopts_resources_exhausted_p, 0 );
1232
- rb_define_method( rlink_cParseOptions, "reset_resources",
1233
- rlink_parseopts_reset_resources, 0 );
733
+ rb_define_method( rlink_cParseOptions, "verbosity=", rlink_parseopts_set_verbosity, 1 );
734
+ rb_define_method( rlink_cParseOptions, "verbosity", rlink_parseopts_get_verbosity, 0 );
735
+ rb_define_method( rlink_cParseOptions, "linkage_limit=", rlink_parseopts_set_linkage_limit, 1 );
736
+ rb_define_method( rlink_cParseOptions, "linkage_limit", rlink_parseopts_get_linkage_limit, 0 );
737
+ rb_define_method( rlink_cParseOptions, "disjunct_cost=", rlink_parseopts_set_disjunct_cost, 1 );
738
+ rb_define_method( rlink_cParseOptions, "disjunct_cost", rlink_parseopts_get_disjunct_cost, 0 );
739
+ rb_define_method( rlink_cParseOptions, "min_null_count=", rlink_parseopts_set_min_null_count, 1 );
740
+ rb_define_method( rlink_cParseOptions, "min_null_count", rlink_parseopts_get_min_null_count, 0 );
741
+ rb_define_method( rlink_cParseOptions, "max_null_count=", rlink_parseopts_set_max_null_count, 1 );
742
+ rb_define_method( rlink_cParseOptions, "max_null_count", rlink_parseopts_get_max_null_count, 0 );
743
+ rb_define_method( rlink_cParseOptions, "islands_ok=", rlink_parseopts_set_islands_ok, 1 );
744
+ rb_define_method( rlink_cParseOptions, "islands_ok?", rlink_parseopts_get_islands_ok_p, 0 );
745
+ rb_define_method( rlink_cParseOptions, "short_length=", rlink_parseopts_set_short_length, 1 );
746
+ rb_define_method( rlink_cParseOptions, "short_length", rlink_parseopts_get_short_length, 0 );
747
+ rb_define_method( rlink_cParseOptions, "max_memory=", rlink_parseopts_set_max_memory, 1 );
748
+ rb_define_method( rlink_cParseOptions, "max_memory", rlink_parseopts_get_max_memory, 0 );
749
+ rb_define_method( rlink_cParseOptions, "max_parse_time=", rlink_parseopts_set_max_parse_time, 1 );
750
+ rb_define_method( rlink_cParseOptions, "max_parse_time", rlink_parseopts_get_max_parse_time, 0 );
751
+ rb_define_method( rlink_cParseOptions, "all_short_connectors=", rlink_parseopts_set_all_short_connectors, 1 );
752
+ rb_define_method( rlink_cParseOptions, "all_short_connectors?", rlink_parseopts_get_all_short_connectors_p, 0 );
753
+ rb_define_method( rlink_cParseOptions, "cost_model_type=", rlink_parseopts_set_cost_model_type, 1 );
754
+ rb_define_method( rlink_cParseOptions, "cost_model_type", rlink_parseopts_get_cost_model_type, 0 );
755
+
756
+ rb_define_method( rlink_cParseOptions, "spell_guessing_enabled=", rlink_parseopts_set_spell_guess, 1 );
757
+ rb_define_method( rlink_cParseOptions, "spell_guessing_enabled?", rlink_parseopts_get_spell_guess_p, 0 );
758
+
759
+ rb_define_method( rlink_cParseOptions, "timer_expired?", rlink_parseopts_timer_expired_p, 0 );
760
+ rb_define_method( rlink_cParseOptions, "memory_exhausted?", rlink_parseopts_memory_exhausted_p, 0 );
761
+ rb_define_method( rlink_cParseOptions, "resources_exhausted?", rlink_parseopts_resources_exhausted_p, 0 );
762
+ rb_define_method( rlink_cParseOptions, "reset_resources", rlink_parseopts_reset_resources, 0 );
1234
763
 
1235
764
  }
1236
765