Create a new ParseOptions object and set values from opthash.
po = LinkParser::ParseOptions.new( :allow_null => true, :batch_mode => true )
static VALUE
rlink_parseopts_init( int argc, VALUE *argv, VALUE self ) {
if ( ! check_parseopts(self) ) {
Parse_Options opts;
VALUE opthash = Qnil;
debugMsg(( "Initializing a ParseOptions: %p", self ));
DATA_PTR( self ) = opts = parse_options_create();
rb_scan_args( argc, argv, "01", &opthash );
if ( RTEST(opthash) ) {
debugMsg(( "Setting options from an opthash." ));
rb_iterate( rb_each, opthash, rlink_parseopts_each_opthash_i, self );
}
}
else {
rb_raise( rb_eRuntimeError, "Cannot re-initialize a Dictionary object." );
}
return self;
}
If true, then all connectors have length restrictions imposed on them – they can be no farther than #short_length apart. This is used when parsing in “panic” mode, for example.
static VALUE
rlink_parseopts_set_all_short_connectors( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_all_short_connectors( opts, RTEST(val) );
return val;
}
Get the value of the all_short_connectors option.
static VALUE
rlink_parseopts_get_all_short_connectors_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_all_short_connectors( opts );
return rval ? Qtrue : Qfalse;
}
Indicates whether or not linkages are allowed to have null links.
static VALUE
rlink_parseopts_set_allow_null( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_allow_null( opts, RTEST(val) );
return val;
}
Get the value of the allow_null option.
static VALUE
rlink_parseopts_get_allow_null_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_allow_null( opts );
return rval ? Qtrue : Qfalse;
}
Enable or disable “batch mode.”
:todo: Figure out what batch mode is.
static VALUE
rlink_parseopts_set_batch_mode( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_batch_mode( opts, RTEST(val) );
return val;
}
Returns true if batch mode is enabled.
static VALUE
rlink_parseopts_get_batch_mode_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_batch_mode( opts );
return rval ? Qtrue : Qfalse;
}
static VALUE
rlink_parseopts_get_cost_model_type( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_cost_model_type( opts );
return INT2FIX( rval );
}
The cost model type for ranking linkages, which is an index into an array of function pointers. The current code only has a single entry, but others could easily be added.
static VALUE
rlink_parseopts_set_cost_model_type( VALUE self, VALUE cm ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_cost_model_type( opts, NUM2INT(cm) );
return cm;
}
Get the maximum disjunct cost used during parsing.
static VALUE
rlink_parseopts_get_disjunct_cost( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_disjunct_cost( opts );
return INT2FIX( rval );
}
Determines the maximum disjunct cost used during parsing, where the cost
of a disjunct is equal to the maximum cost of all of its connectors. The default is that all disjuncts, no matter what their cost, are considered.
static VALUE
rlink_parseopts_set_disjunct_cost( VALUE self, VALUE disjunct_cost ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_disjunct_cost( opts, NUM2INT(disjunct_cost) );
return disjunct_cost;
}
Set the display_bad option to the specified value.
static VALUE
rlink_parseopts_set_display_bad( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_display_bad( opts, RTEST(val) );
return val;
}
Get the value of the display_bad option.
static VALUE
rlink_parseopts_get_display_bad_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_display_bad( opts );
return rval ? Qtrue : Qfalse;
}
Set the display_constituents option to the specified value.
static VALUE
rlink_parseopts_set_display_constituents( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_display_constituents( opts, RTEST(val) );
return val;
}
Get the value of the display_constituents option.
static VALUE
rlink_parseopts_get_display_constituents_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_display_constituents( opts );
return rval ? Qtrue : Qfalse;
}
Set the display_links option to the specified value.
static VALUE
rlink_parseopts_set_display_links( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_display_links( opts, RTEST(val) );
return val;
}
Get the value of the display_links option.
static VALUE
rlink_parseopts_get_display_links_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_display_links( opts );
return rval ? Qtrue : Qfalse;
}
Enable/disable display.
:todo: Figure out what this setting does.
static VALUE
rlink_parseopts_set_display_on( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_display_on( opts, RTEST(val) );
return val;
}
Returns true if …?
static VALUE
rlink_parseopts_get_display_on_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_display_on( opts );
return rval ? Qtrue : Qfalse;
}
Enable/disable display using Postscript.
static VALUE
rlink_parseopts_set_display_postscript( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_display_postscript( opts, RTEST(val) );
return val;
}
Returns true if display should use Postscript instead of plain
text.
static VALUE
rlink_parseopts_get_display_postscript_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_display_postscript( opts );
return rval ? Qtrue : Qfalse;
}
Set the display_union option to the specified value.
static VALUE
rlink_parseopts_set_display_union( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_display_union( opts, RTEST(val) );
return val;
}
Get the value of the display_union option.
static VALUE
rlink_parseopts_get_display_union_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_display_union( opts );
return rval ? Qtrue : Qfalse;
}
Whether or not to show the wall word(s) when a linkage diagram is printed.
static VALUE
rlink_parseopts_set_display_walls( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_display_walls( opts, RTEST(val) );
return val;
}
Whether or not to show the wall word(s) when a linkage diagram is printed.
static VALUE
rlink_parseopts_get_display_walls_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_display_walls( opts );
return rval ? Qtrue : Qfalse;
}
Set the echo_on option to the specified value.
static VALUE
rlink_parseopts_set_echo_on( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_echo_on( opts, RTEST(val) );
return val;
}
Get the value of the echo_on option.
static VALUE
rlink_parseopts_get_echo_on_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_echo_on( opts );
return rval ? Qtrue : Qfalse;
}
This option determines whether or not “islands” of links are allowed. For example, the following linkage has an island:
+------Wd-----+ | +--Dsu--+---Ss--+-Paf-+ +--Dsu--+---Ss--+--Pa-+ | | | | | | | | | ///// this sentence.n is.v false.a this sentence.n is.v true.a
static VALUE
rlink_parseopts_set_islands_ok( VALUE self, VALUE islands_ok ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_islands_ok( opts, RTEST(islands_ok) );
return islands_ok;
}
Get the value of the islands_ok option.
static VALUE
rlink_parseopts_get_islands_ok_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_islands_ok( opts );
return rval ? Qtrue : Qfalse;
}
This parameter determines the maximum number of linkages that are
considered in post-processing. If more than linkage_limit
linkages are found, then a random sample of linkage_limit is
chosen for post-processing. When this happen a warning is displayed at
verbosity levels greater than 1.
static VALUE
rlink_parseopts_get_linkage_limit( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_linkage_limit( opts );
return INT2FIX( rval );
}
This parameter determines the maximum number of linkages that are
considered in post-processing. If more than linkage_limit
linkages are found, then a random sample of linkage_limit is
chosen for post-processing. When this happen a warning is displayed at
verbosity levels greater than 1.
static VALUE
rlink_parseopts_set_linkage_limit( VALUE self, VALUE linkage_limit ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_linkage_limit( opts, NUM2INT(linkage_limit) );
return linkage_limit;
}
Get the value of the #max_memory option.
static VALUE
rlink_parseopts_get_max_memory( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_max_memory( opts );
return INT2FIX( rval );
}
Determines the maximum memory allowed during parsing. This is used just as #max_parse_time is, so that the parsing process is terminated as quickly as possible after the total memory (including that allocated to all dictionaries, etc.) exceeds the maximum allowed.
static VALUE
rlink_parseopts_set_max_memory( VALUE self, VALUE mem ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_max_memory( opts, NUM2INT(mem) );
return mem;
}
Get the maximum number of null links allowed in a parse.
static VALUE
rlink_parseopts_get_max_null_count( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_max_null_count( opts );
return INT2FIX( rval );
}
Set the maximum number of null links allowed in a parse.
static VALUE
rlink_parseopts_set_max_null_count( VALUE self, VALUE null_count ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_max_null_count( opts, NUM2INT(null_count) );
return null_count;
}
Get the number of seconds of the #max_parse_time option.
static VALUE
rlink_parseopts_get_max_parse_time( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_max_parse_time( opts );
return INT2FIX( rval );
}
Determines the approximate maximum time that parsing is allowed to take. The way it works is that after this time has expired, the parsing process is artificially forced to complete quickly by pretending that no further solutions (entries in the hash table) can be constructed. The actual parsing time might be slightly longer.
static VALUE
rlink_parseopts_set_max_parse_time( VALUE self, VALUE secs ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_max_parse_time( opts, NUM2INT(secs) );
return secs;
}
Get the value of the #max_sentence_length option.
static VALUE
rlink_parseopts_get_max_sentence_length( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_max_sentence_length( opts );
return INT2FIX( rval );
}
Determines the maximum length of a parsed sentence.
static VALUE
rlink_parseopts_set_max_sentence_length( VALUE self, VALUE len ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_max_sentence_length( opts, NUM2INT(len) );
return len;
}
Returns true if memory constraints were exceeded during parsing.
sentence.parse
if sentence.options.memory_exhausted?
$stderr.puts "Parsing sentence #{sentence} ran out of memory."
end
static VALUE
rlink_parseopts_memory_exhausted_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_memory_exhausted( opts );
return rval ? Qtrue : Qfalse;
}
static VALUE
rlink_parseopts_merge( VALUE self, other ) {
}
Get the minimum of null links that a parse can have.
static VALUE
rlink_parseopts_get_min_null_count( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_min_null_count( opts );
return INT2FIX( rval );
}
Set the minimum of null links that a parse can have. A call to LinkParser::Sentence#parse will find all linkages having the minimum number of null links within the range specified by this parameter.
static VALUE
rlink_parseopts_set_min_null_count( VALUE self, VALUE null_count ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_min_null_count( opts, NUM2INT(null_count) );
return null_count;
}
Get the value of the #null_block option.
static VALUE
rlink_parseopts_get_null_block( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_null_block( opts );
return INT2FIX( rval );
}
Set the #null_block option to the specified value. The #null_block option allows null links to be counted in “bunches.” For example, if #null_block is 4, then a linkage with 1,2,3 or 4 null links has a null cost of 1, a linkage with 5,6,7 or 8 null links has a null cost of 2, etc.
static VALUE
rlink_parseopts_set_null_block( VALUE self, VALUE null_block ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_null_block( opts, NUM2INT(null_block) );
return null_block;
}
Enable or disable “panic mode.”
:todo: Figure out what enabling this option does. I only know about panic mode in the parser – does this allow/disallow the parser from entering it?
static VALUE
rlink_parseopts_set_panic_mode( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_panic_mode( opts, RTEST(val) );
return val;
}
Returns true if panic mode is enabled.
static VALUE
rlink_parseopts_get_panic_mode_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_panic_mode( opts );
return rval ? Qtrue : Qfalse;
}
Reset the timer- and memory-constraint flags.
static VALUE
rlink_parseopts_reset_resources( VALUE self ) {
Parse_Options opts = get_parseopts( self );
parse_options_reset_resources( opts );
return Qnil;
}
Returns true if the memory or timer constraints were exceeded during parsing.
sentence.parse
if sentence.options.resources_exhausted?
$stderr.puts "Parsing sentence #{sentence} ran out of resources."
end
static VALUE
rlink_parseopts_resources_exhausted_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_resources_exhausted( opts );
return rval ? Qtrue : Qfalse;
}
Get the screen width assumed by the diagramming functions.
static VALUE
rlink_parseopts_get_screen_width( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_screen_width( opts );
return INT2FIX( rval );
}
Set the screen width assumed by the diagramming functions.
static VALUE
rlink_parseopts_set_screen_width( VALUE self, VALUE val ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_screen_width( opts, NUM2INT(val) );
return val;
}
Get the value of the #short_length option.
static VALUE
rlink_parseopts_get_short_length( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_short_length( opts );
return INT2FIX( rval );
}
The #short_length parameter determines how long the links are allowed to be. The intended use of this is to speed up parsing by not considering very long links for most connectors, since they are very rarely used in a correct parse. An entry for UNLIMITED-CONNECTORS in the dictionary will specify which connectors are exempt from the length limit.
static VALUE
rlink_parseopts_set_short_length( VALUE self, VALUE short_length ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_short_length( opts, NUM2INT(short_length) );
return short_length;
}
Enable/disable spell-guessing if it’s supported.
static VALUE
rlink_parseopts_set_spell_guess( VALUE self, VALUE val ) {
#ifdef HAVE_PARSE_OPTIONS_GET_SPELL_GUESS
Parse_Options opts = get_parseopts( self );
parse_options_set_spell_guess( opts, RTEST(val) );
return val;
#else
rb_notimplement();
return Qnil;
#endif /* HAVE_PARSE_OPTIONS_GET_SPELL_GUESS */
}
Returns true if spell-guessing is enabled. Note that a
true return value doesn’t mean that it’s supported, only that
it will be used if it is.
static VALUE
rlink_parseopts_get_spell_guess_p( VALUE self ) {
#ifdef HAVE_PARSE_OPTIONS_GET_SPELL_GUESS
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_spell_guess( opts );
return rval ? Qtrue : Qfalse;
#else
rb_notimplement();
return Qnil;
#endif /* HAVE_PARSE_OPTIONS_GET_SPELL_GUESS */
}
Returns true if timer constraints were exceeded during parsing.
sentence.parse
if sentence.options.timer_expired?
$stderr.puts "Parsing sentence #{sentence} timed out."
end
static VALUE
rlink_parseopts_timer_expired_p( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_timer_expired( opts );
return rval ? Qtrue : Qfalse;
}
This gets the level of description printed to stderr/stdout about the parsing process.
static VALUE
rlink_parseopts_get_verbosity( VALUE self ) {
Parse_Options opts = get_parseopts( self );
int rval;
rval = parse_options_get_verbosity( opts );
return INT2FIX( rval );
}
This sets the level of description printed to stderr/stdout about the parsing process.
static VALUE
rlink_parseopts_set_verbosity( VALUE self, VALUE verbosity ) {
Parse_Options opts = get_parseopts( self );
parse_options_set_verbosity( opts, NUM2INT(verbosity) );
return verbosity;
}