Commits

Michael Granger committed 89aed20

* Mostly all of the low-level function wrapped.
* Added some high-level methods on Linkages.

Comments (0)

Files changed (19)

 begin
 	puts "Requiring 'linkparser' module..."
 	require 'linkparser'
-	
-	$dict = LinkParser::Dictionary.new
 rescue => e
 	$stderr.puts "Ack! LinkParser module failed to load: #{e.message}\n\t" +
 		e.backtrace.join( "\n\t" )
 end
 
+$dict = LinkParser::Dictionary.new

LinkParser Project.tmproj

 <plist version="1.0">
 <dict>
 	<key>currentDocument</key>
-	<string>tests/linkage.tests.rb</string>
+	<string>lib/linkparser/linkage.rb</string>
 	<key>documents</key>
 	<array>
 		<dict>
 	<integer>219</integer>
 	<key>metaData</key>
 	<dict>
+		<key>.irbrc</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>29</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>0</integer>
+		</dict>
 		<key>docs/link-includes.h</key>
 		<dict>
 			<key>caret</key>
 			<dict>
 				<key>column</key>
-				<integer>40</integer>
+				<integer>25</integer>
 				<key>line</key>
-				<integer>249</integer>
+				<integer>271</integer>
+			</dict>
+			<key>columnSelection</key>
+			<false/>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>243</integer>
+			<key>selectFrom</key>
+			<dict>
+				<key>column</key>
+				<integer>16</integer>
+				<key>line</key>
+				<integer>271</integer>
+			</dict>
+			<key>selectTo</key>
+			<dict>
+				<key>column</key>
+				<integer>25</integer>
+				<key>line</key>
+				<integer>271</integer>
+			</dict>
+		</dict>
+		<key>docs/public-functions.h</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>1</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>219</integer>
+			<integer>4</integer>
 		</dict>
 		<key>ext/dictionary.c</key>
 		<dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>4</integer>
+			<integer>105</integer>
+		</dict>
+		<key>ext/extconf.rb</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>32</integer>
+				<key>line</key>
+				<integer>33</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>0</integer>
 		</dict>
 		<key>ext/linkage.c</key>
 		<dict>
 				<key>column</key>
 				<integer>0</integer>
 				<key>line</key>
-				<integer>704</integer>
+				<integer>738</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>654</integer>
+			<integer>677</integer>
+		</dict>
+		<key>ext/linkparser.c</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>4</integer>
+				<key>line</key>
+				<integer>92</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>48</integer>
+		</dict>
+		<key>ext/linkparser.h</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>0</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>58</integer>
 		</dict>
 		<key>ext/parseoptions.c</key>
 		<dict>
 			<key>caret</key>
 			<dict>
 				<key>column</key>
-				<integer>0</integer>
+				<integer>23</integer>
 				<key>line</key>
-				<integer>457</integer>
+				<integer>80</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>405</integer>
+			<integer>456</integer>
 		</dict>
-		<key>extconf.rb</key>
+		<key>lib/linkparser.rb</key>
 		<dict>
 			<key>caret</key>
 			<dict>
 				<key>column</key>
-				<integer>41</integer>
+				<integer>28</integer>
 				<key>line</key>
-				<integer>27</integer>
+				<integer>33</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>17</integer>
+			<integer>0</integer>
+		</dict>
+		<key>lib/linkparser/linkage.rb</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>72</integer>
+				<key>line</key>
+				<integer>148</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>124</integer>
+		</dict>
+		<key>lib/linkparser/sentence.rb</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>7</integer>
+				<key>line</key>
+				<integer>58</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>7</integer>
 		</dict>
 		<key>test.rb</key>
 		<dict>
 				<key>column</key>
 				<integer>0</integer>
 				<key>line</key>
-				<integer>126</integer>
+				<integer>0</integer>
 			</dict>
 			<key>firstVisibleColumn</key>
 			<integer>0</integer>
 			<key>firstVisibleLine</key>
-			<integer>106</integer>
+			<integer>0</integer>
 		</dict>
 		<key>tests/parseoptions.tests.rb</key>
 		<dict>
 	</dict>
 	<key>openDocuments</key>
 	<array>
+		<string>ext/sentence.c</string>
+		<string>lib/linkparser/sentence.rb</string>
 		<string>ext/linkage.c</string>
-		<string>tests/linkage.tests.rb</string>
-		<string>extconf.rb</string>
-		<string>docs/link-includes.h</string>
+		<string>lib/linkparser/linkage.rb</string>
+		<string>lib/linkparser.rb</string>
+		<string>ext/linkparser.c</string>
+		<string>ext/extconf.rb</string>
+		<string>.irbrc</string>
 	</array>
 	<key>showFileHierarchyDrawer</key>
 	<true/>

experiments/diagram_sentences.rb

 #!/usr/bin/ruby
 
-$LOAD_PATH.unshift "ext"
+BEGIN {
+	require 'pathname'
+	basedir = Pathname.new( __FILE__ ).dirname.parent
+	require basedir + 'linkparser-path.rb'
+	require basedir + 'utils.rb'
+
+	include UtilityFunctions
+}
 
 require 'linkparser'
-require './utils.rb'
 
-include UtilityFunctions
-
-dict = LinkParser::Dictionary.new( :screen_width => 120 )
+dict = LinkParser::Dictionary.new( :screen_width => 120, :verbosity => 2 )
 loop do
 	input_string = prompt( "Sentence to diagram: " )
 	break if input_string.empty?

experiments/pps.rb

+#!/usr/bin/ruby
+
+BEGIN {
+	require 'pathname'
+	basedir = Pathname.new( __FILE__ ).dirname.parent
+	require basedir + 'linkparser-path.rb'
+	require basedir + 'utils.rb'
+
+	include UtilityFunctions
+}
+
+require 'linkparser'
+
+dict = LinkParser::Dictionary.new( :screen_width => 120 )
+loop do
+	input_string = prompt( "Sentence to parse: " )
+	break if input_string.empty?
+
+	sent = dict.parse( input_string.chomp )
+
+	sent.linkages.each do |linkage|
+		message "%s <%s> %s\n" % [ linkage.subject, linkage.verb, linkage.object ]
+	end
+end
+
 $CFLAGS << ' -Wall'
 $CFLAGS << ' -DDEBUG'
 
-dir_config( "linkparser" )
-have_header( "link-grammar/link-includes.h")
-have_header( "link-grammar/utilities.h")
+dir_config( "linkparser_ext" )
 have_library( "link-grammar", "dictionary_create" ) or
 	abort( "Could not find link-grammar library." )
+have_header( "link-grammar/link-includes.h" )
+have_header( "link-grammar/utilities.h" )
+have_func( "linkage_get_current_sublinkage", "link-grammar/link-includes.h" ) or
+	warn "Link grammar library is unpatched."
 
-create_makefile( "linkparser" )
+create_makefile( "linkparser_ext" )
  *  Forward declarations
  * -------------------------------------------------- */
 
+static VALUE rlink_linkage_make_cnode_array( CNode * );
+
 
 /* --------------------------------------------------
  * Macros and constants
 /*
  * Publicly-usable linkage-fetcher
  */
-/*rlink_LINKAGE *
+rlink_LINKAGE *
 rlink_get_linkage( self )
 {
 	return get_linkage( self );
 }
-*/
+
 
 
 /* --------------------------------------------------
  * -------------------------------------------------- */
 
 /*
- * allocate()
- * --
- * Allocate a new LinkParser::Linkage object.
+ *  call-seq:
+ *     LinkParser::Linkage.allocate   => LinkParser::Linkage
+ *
+ *  Allocate a new LinkParser::Linkage object.
  */
 static VALUE
 rlink_linkage_s_alloc( klass )
  * Instance methods
  * -------------------- */
 
-
 /*
- * initialize( index, sentence, options={} )
- * --
- * Create a new LinkParser::Linkage object out of the linkage indicated by
- * +index+ (a positive Integer) from the specified sentence (a 
- * LinkParser::Sentence). The optional options hash can be used to override
- * the parse options of the Sentence for the new linkage.
+ *  call-seq:
+ *     new( index, sentence, options={} )   => LinkParser::Linkage
+ *
+ *  Create a new LinkParser::Linkage object out of the linkage indicated by
+ *  +index+ (a positive Integer) from the specified sentence (a 
+ *  LinkParser::Sentence). The optional options hash can be used to override
+ *  the parse options of the Sentence for the new linkage.
  */
 static VALUE
 rlink_linkage_init( argc, argv, self )
 
 
 
-/* 
- * diagram
- * --
- * Return a String containing a diagram of the linkage.
+/*
+ *  call-seq:
+ *     diagram   => str
+ *
+ *  Return a String containing a diagram of the linkage.
  */
 static VALUE
 rlink_linkage_diagram( self )
 }
 
 
-/* 
- * postscript_diagram( full_doc=false )
- * --
- * Returns the macros needed to print out the linkage in a postscript file. 
- * By default, the output is just the set of postscript macros that describe 
- * the diagram. With full_doc=true a complete encapsulated postscript document 
- * is returned.
+/*
+ *  call-seq:
+ *     postscript_diagram( full_doc=false )   => str
+ *
+ *  Returns the macros needed to print out the linkage in a postscript file. 
+ *  By default, the output is just the set of postscript macros that describe 
+ *  the diagram. With full_doc=true a complete encapsulated postscript document 
+ *  is returned.
  */
 static VALUE
 rlink_linkage_print_postscript( self, full_doc )
 }
 
 
-/* 
- * links_and_domains
- * --
- * Return a String containing a lists all of the links and domain names for 
- * the current sublinkage. For example, for the sentence "I eat, therefore I 
- * think":
- * 
- *             /////          RW      <---RW---->  RW        /////
- *   (m)       /////          Wd      <---Wd---->  Wd        I.p
- *   (m)       I.p            CC      <---CC---->  CC        therefore
- *   (m)       I.p            Sp*i    <---Sp*i-->  Sp        eat
- *   (m)       ,              Xd      <---Xd---->  Xd        therefore
- *   (m) (m)   therefore      Wd      <---Wd---->  Wd        I.p
- *   (m) (m)   I.p            Sp*i    <---Sp*i-->  Sp        think.v
- * 
- * 
+/*
+ *  call-seq:
+ *     links_and_domains   => str
+ *
+ *  Return a String containing a lists all of the links and domain names for 
+ *  the current sublinkage.
+ *
+ *  Example:
+ *    sent = dict.parse("I eat, therefore I think")
+ *    puts sent.linkages.first.links_and_domains
+ *  
+ *  prints:
+ *              /////          RW      <---RW---->  RW        /////
+ *    (m)       /////          Wd      <---Wd---->  Wd        I.p
+ *    (m)       I.p            CC      <---CC---->  CC        therefore
+ *    (m)       I.p            Sp*i    <---Sp*i-->  Sp        eat
+ *    (m)       ,              Xd      <---Xd---->  Xd        therefore
+ *    (m) (m)   therefore      Wd      <---Wd---->  Wd        I.p
+ *    (m) (m)   I.p            Sp*i    <---Sp*i-->  Sp        think.v
  * 
  */
 static VALUE
 
 
 
-/* 
- * num_sublinkages
- * --
- * Return the number of sublinkages for a linkage with conjunctions, 1 
- * otherwise.
+/*
+ *  call-seq:
+ *     num_sublinkages   => fixnum
+ *
+ *  Return the number of sublinkages for a linkage with conjunctions, 1 
+ *  otherwise.
  */
 static VALUE
 rlink_linkage_num_sublinkages( self )
 
 
 /*
+ *  call-seq:
+ *     current_sublinkage = index   => true or false
+ *
+ *  After this call, all operations on the linkage will refer to the index-th 
+ *  sublinkage. In the case of a linkage without conjunctions, this has no 
+ *  effect.
+ */
+static VALUE
+rlink_linkage_current_sublinkage_eq( self, index )
+	VALUE self, index;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	int rval = 0;
+	
+	rval = linkage_set_current_sublinkage( (Linkage)ptr->linkage, NUM2INT(index) );
+	
+	return INT2FIX( rval );
+}
+
+
+/*
+ *  call-seq:
+ *     current_sublinkage   => fixnum
+ *
+ *  Get the index of the current sublinkage.
+ */
+static VALUE
+rlink_linkage_current_sublinkage( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	int rval = 0;
+
+	rval = linkage_get_current_sublinkage( (Linkage)ptr->linkage );
+	
+	return INT2FIX( rval );
+}
+
+
+/*
  * num_words
  * --
  * The number of words in the sentence for which this is a linkage. Note that 
 	VALUE self, index;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	int i = FIX2INT( index );
+	int i = NUM2INT( index );
 	
 	return INT2FIX( linkage_get_link_lword((Linkage)ptr->linkage, i) );
 }
  * current sublinkage.
  */
 static VALUE
-rlink_linkage_get_link_rword( self, arg )
-	VALUE self, arg;
+rlink_linkage_get_link_rword( self, index )
+	VALUE self, index;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	int i = FIX2INT( index );
+	int i = NUM2INT( index );
 	
 	return INT2FIX( linkage_get_link_rword((Linkage)ptr->linkage, i) );
 }
 	VALUE self, index;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	int i = FIX2INT( index );
+	int i = NUM2INT( index );
 	
 	return INT2FIX( linkage_get_link_length((Linkage)ptr->linkage, i) );
 }
 	VALUE self, index;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	int i = FIX2INT( index );
+	int i = NUM2INT( index );
 	char *label;
 	
 	label = linkage_get_link_label( (Linkage)ptr->linkage, i );
  * The label on the left word of the index-th link of the current sublinkage.
  */
 static VALUE
-rlink_linkage_get_link_llabel( self, arg )
-	VALUE self, arg;
+rlink_linkage_get_link_llabel( self, index )
+	VALUE self, index;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	int i = FIX2INT( index );
-	char *label;
+	int i = NUM2INT( index );
+	char *label = NULL;
 	
 	label = linkage_get_link_llabel( (Linkage)ptr->linkage, i );
+	if ( !label ) return Qnil;
+	
 	return rb_str_new2( label );
 }
 
  * The label on the right word of the index-th link of the current sublinkage.
  */
 static VALUE
-rlink_linkage_get_link_rlabel( self, arg )
-	VALUE self, arg;
+rlink_linkage_get_link_rlabel( self, index )
+	VALUE self, index;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	int i = FIX2INT( index );
-	char *label;
+	int i = NUM2INT( index );
+	char *label = NULL;
 	
 	label = linkage_get_link_rlabel( (Linkage)ptr->linkage, i );
+	if ( !label ) return Qnil;
+	
 	return rb_str_new2( label );
 }
 
 
 /*
- * link_num_domains( index ) => fixnum
- * --
- * The number of domains in the index-th link.
+ *  call-seq:
+ *     link_num_domains( index )   => fixnum
+ *
+ *  Returns the number of domains in the index-th link.
+ *
  */
 static VALUE
 rlink_linkage_get_link_num_domains( self, index )
 	VALUE self, index;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	int i = FIX2INT( index );
+	int i = NUM2INT( index );
 	int count = 0;
 	
 	count = linkage_get_link_num_domains( (Linkage)ptr->linkage, i );
 
 
 /*
- * link_domain_names => array
- * --
- * The names of the domains the index-th link belongs to.
+ *  call-seq:
+ *     link_domain_names( index )   => array
+ *
+ *  Returns the names of the domains the index-th link belongs to.
  */
 static VALUE
 rlink_linkage_get_link_domain_names( self, index )
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
 	char **names;
-	int i = FIX2INT( index );
+	int i = NUM2INT( index );
 	int count;
 	VALUE names_ary;
 	
 
 
 /*
- * words => array
- * --
- * Return the Array of word spellings or individual word spelling for the 
- * current sublinkage. These are the "inflected" spellings, such as "dog.n". 
- * The original spellings can be obtained by calls to Sentence#words.
+ *  call-seq:
+ *     words   => array
+ *
+ *  Return the Array of word spellings or individual word spelling for the 
+ *  current sublinkage. These are the "inflected" spellings, such as "dog.n". 
+ *  The original spellings can be obtained by calls to Sentence#words.
  */
 static VALUE
 rlink_linkage_get_words( self )
 
 
 /*
- * compute_union
- * --
- * If the linkage has a conjunction, combine all of the links occurring in all
- * sublinkages together -- in effect creating a "master" linkage (which may
- * have crossing links). The union is created as another sublinkage, thus
- * increasing the number of sublinkages by one, and is returned by this method.
- * If the linkage has no conjunctions, computing its union has no effect, and
- * nil is returned.
+ *  call-seq:
+ *     compute_union   => fixnum or nil
+ *
+ *  If the linkage has a conjunction, combine all of the links occurring in all
+ *  sublinkages together -- in effect creating a "master" linkage (which may
+ *  have crossing links). The union is created as another sublinkage, thus
+ *  increasing the number of sublinkages by one, and is returned by this method.
+ *  If the linkage has no conjunctions, computing its union has no effect, and
+ *  nil is returned.
  */
 static VALUE
 rlink_linkage_compute_union( self )
 	return INT2FIX( rval );
 }
 
+
 /*
- * unused_word_cost
- * --
- * 
+ *  call-seq:
+ *     linkage.unused_word_cost   => fixnum
+ *
+ *  Returns the unused word cost of the linkage, which corresponds to the number
+ *  of null links that were required to parse it.
+ *     
  */
 static VALUE
 rlink_linkage_unused_word_cost( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	int rval;
+	
+	rval = linkage_unused_word_cost( (Linkage)ptr->linkage );
+	
+	return INT2FIX( rval );
 }
 
+
 /*
- * disjunct_cost
- * --
- * 
+ *  call-seq:
+ *     disjunct_cost( fixnum )   => fixnum
+ *
+ *  Returns the connector or disjunct cost of the linkage.
+ *
  */
 static VALUE
 rlink_linkage_disjunct_cost( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	int rval;
+	
+	rval = linkage_disjunct_cost( (Linkage)ptr->linkage );
+	
+	return INT2FIX( rval );
 }
 
+
 /*
- * and_cost
- * --
- * 
+ *  call-seq:
+ *     and_cost   => fixnum
+ *
+ *  Returns the AND cost of the linkage, which is the difference in length 
+ *  between and-list elements.
+ *
  */
 static VALUE
 rlink_linkage_and_cost( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	int rval;
+	
+	rval = linkage_and_cost( (Linkage)ptr->linkage );
+	
+	return INT2FIX( rval );
 }
 
+
 /*
- * link_cost
- * --
- * 
+ *  call-seq:
+ *     link_cost   => fixnum
+ *
+ *  Returns the total (LEN) cost of the linkage, which is the total length of 
+ *  all links in the sentence minus the number of words -- since the total link 
+ *  length is never less than the number of words.
+ *
  */
 static VALUE
 rlink_linkage_link_cost( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	int rval;
+	
+	rval = linkage_link_cost( (Linkage)ptr->linkage );
+	
+	return INT2FIX( rval );
 }
 
+
 /*
- * canonical?
- * --
- * 
+ *  call-seq:
+ *     canonical?   => true or false
+ *
+ *  Returns +true+ if the linkage is canonical. The canonical linkage is the 
+ *  one in which the minimal disjunct that ever occurrs in a position is used 
+ *  in that position.
  */
 static VALUE
 rlink_linkage_canonical_p( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	int rval = 0;
+	
+	rval = linkage_is_canonical( (Linkage)ptr->linkage );
+	
+	return rval ? Qtrue : Qfalse;
 }
 
 
 /*
- * improper?
- * --
- * 
+ *  call-seq:
+ *     improper?   => true or false
+ *
+ *  Returns +true+ if the linkage is "improper". 
+ *  --
+ *  :FIXME: Find out what an "improper fat linkage" is.
+ *
  */
 static VALUE
 rlink_linkage_improper_p( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	int rval = 0;
+	
+	rval = linkage_is_improper( (Linkage)ptr->linkage );
+	
+	return rval ? Qtrue : Qfalse;
 }
 
 
 /*
- * has_inconsistent_domains?
- * --
- * 
+ *  call-seq:
+ *     has_inconsistent_domains?   => true or false
+ *
+ *  Returns +true+ if the linkage has inconsistent domains. 
+ *  --
+ *  :FIXME: Find out what it means that a linkage has inconsistent domains.
+ *
  */
 static VALUE
 rlink_linkage_has_inconsistent_domains_p( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	int rval = 0;
+	
+	rval = linkage_has_inconsistent_domains( (Linkage)ptr->linkage );
+	
+	return rval ? Qtrue : Qfalse;
 }
 
 
 /*
- * violation_name
- * --
- * 
+ *  call-seq:
+ *     violation_name   => str
+ *
+ *  If the linkage violated any post-processing rules, this method returns the 
+ *  name of the violated rule in the post-process knowledge file. 
  */
 static VALUE
 rlink_linkage_get_violation_name( self )
 	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
-	return Qnil;
+	char *violation_name = NULL;
+	
+	violation_name = linkage_get_violation_name( (Linkage)ptr->linkage );
+	
+	if ( violation_name ) {
+		return rb_str_new2( violation_name );
+	} else {
+		return Qnil;
+	}
+}
+
+
+/*
+ *  call-seq:
+ *     constituent_tree   => hash
+ *
+ *  Return the Linkage's constituent tree as a hash of hashes.
+ *
+ *     sent = dict.parse( "He is a big dog." )
+ *     link = sent.linkages.first
+ *     ctree = link.constituent_tree
+ *     #=> {}
+ *     
+ */
+static VALUE
+rlink_linkage_constituent_tree( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	CNode *ctree = NULL;
+	VALUE rval = Qnil;
+	
+	ctree = linkage_constituent_tree( (Linkage)ptr->linkage );
+	rval = rlink_linkage_make_cnode_array( ctree );
+	
+	linkage_free_constituent_tree( ctree );
+	return rval;
+}
+
+static VALUE
+rlink_linkage_make_cnode_array( ctree )
+	CNode *ctree;
+{
+	VALUE nodes = rb_ary_new();
+	VALUE rnode;
+	CNode *cnode = ctree;
+	
+	/*	
+		struct CNode_s {
+		  char  * label;
+		  CNode * child;
+		  CNode * next;
+		  int   start, end;
+		};
+	*/
+	while ( cnode ) {
+		rnode = rb_struct_new( rlink_sLinkageCTree,
+			rb_str_new2( linkage_constituent_node_get_label(cnode) ),
+			Qnil,
+			INT2FIX( linkage_constituent_node_get_start(cnode) ),
+			INT2FIX( linkage_constituent_node_get_end(cnode) )			/* end */
+		  );
+
+		/* Make a node array for any children */
+		rb_struct_aset( rnode, INT2FIX(1), 
+			rlink_linkage_make_cnode_array(linkage_constituent_node_get_child(cnode)) );
+
+		rb_ary_push( nodes, rnode );
+		cnode = linkage_constituent_node_get_next( cnode );
+	}
+	
+	return nodes;
+}
+
+
+/*
+ *  call-seq:
+ *     linkage.constituent_tree_string( mode=1 )   => str
+ *
+ *  Return 
+ *
+ *     example code
+ */
+static VALUE
+rlink_linkage_constituent_tree_string( self, mode )
+	VALUE self, mode;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	char *ctree_string = NULL;
+	VALUE rval = Qnil;
+	
+	ctree_string = linkage_print_constituent_tree( (Linkage)ptr->linkage, NUM2INT(mode) );
+
+	if ( ctree_string ) {
+		rval = rb_str_new2( ctree_string );
+		string_delete( ctree_string );
+	}
+	
+	return rval;
 }
 
 
 
 	rb_define_method( rlink_cLinkage, "num_sublinkages", 
 		rlink_linkage_num_sublinkages, 0 );
+	rb_define_method( rlink_cLinkage, "current_sublinkage=",
+		rlink_linkage_current_sublinkage_eq, 1 );
+	rb_define_method( rlink_cLinkage, "current_sublinkage",
+		rlink_linkage_current_sublinkage, 0 );
 	
 	rb_define_method( rlink_cLinkage, "num_words",
 	 	rlink_linkage_get_num_words, 0 );
+	rb_define_alias ( rlink_cLinkage, "word_count", "num_words" );
 	rb_define_method( rlink_cLinkage, "num_links",
 	 	rlink_linkage_get_num_links, 0 );
+	rb_define_alias ( rlink_cLinkage, "link_count", "num_links" );
 	
 	rb_define_method( rlink_cLinkage, "link_lword",
 	 	rlink_linkage_get_link_lword, 1 );
 	 	rlink_linkage_has_inconsistent_domains_p, 0 );
 	rb_define_method( rlink_cLinkage, "violation_name",
 	 	rlink_linkage_get_violation_name, 0 );
+
 	
-
-/*	rb_define_method( rlink_cLinkage, "print_constituent_tree",
-	 	rlink_linkage_print_constituent_tree, 1 );
-*/
-
+	rb_define_const( rlink_cLinkage, "CTree", rlink_sLinkageCTree );
+	rlink_sLinkageCTree = rb_struct_define( "LinkParserLinkageCTree", 
+		"label", "children", "start", "end", NULL );
+	rb_define_method( rlink_cLinkage, "constituent_tree",
+		rlink_linkage_constituent_tree, 0 );
+	rb_define_method( rlink_cLinkage, "constituent_tree_string",
+	 	rlink_linkage_constituent_tree_string, 1 );
 }
 
 VALUE rlink_cLinkage;
 VALUE rlink_cParseOptions;
 
+VALUE rlink_sLinkageCTree;
+
 
 /* --------------------------------------------------
  * Utility functions
 
 /* Library init function */
 void
-Init_linkparser(void)
+Init_linkparser_ext(void)
 {
 	rlink_mLinkParser = rb_define_module( "LinkParser" );
 	rlink_eLpError = rb_define_class_under( rlink_mLinkParser, "Error", rb_eRuntimeError );
 extern VALUE rlink_cPostProcessor;
 extern VALUE rlink_cConstituentTree;
 
+extern VALUE rlink_sLinkageCTree;
+
 extern VALUE rlink_eLpError;
 
 
 	rlink_SENTENCE *ptr;
 {
 	if ( ptr ) {
-		sentence_delete( (Sentence)ptr->sentence );
+		debugMsg(( "In free function of Sentence <%p>", ptr ));
+		
+		if ( rlink_get_dict(ptr->dictionary) ) {
+			debugMsg(( "Freeing Sentence <%p>", ptr->sentence ));
+			sentence_delete( (Sentence)ptr->sentence );
+		} else {
+			debugMsg(( "Not freeing a Sentence belonging to an already-freed dictionary." ));
+		}
+
 		ptr->sentence = NULL;
 		ptr->options = Qnil;
 		ptr->dictionary = Qnil;
  * -------------------------------------------------- */
 
 /*
- * allocate()
- * --
- * Allocate a new LinkParser::Sentence object.
+ *  call-seq:
+ *     LinkParser::Sentence.allocate   => sentence
+ *
+ *  Allocate a new LinkParser::Sentence object.
+ *
  */
 static VALUE
 rlink_sentence_s_alloc( klass )
 
 
 /*
- * initialize( input_string, dictionary )
- * --
- * Create a new LinkParser::Sentence object from the given +input_string+
- * .
+ *  call-seq:
+ *     LinkParser::Sentence.new( str, dict )   => sentence
+ *
+ *  Create a new LinkParser::Sentence object from the given input string
+ #  using the specified LinkParser::Dictionary.
+ *
+ *     dict = LinkParser::Dictionary.new
+ *     LinkParser::Sentence.new( "The boy runs", dict )  #=> #<LinkParser::Sentence:0x5481ac>
  */
 static VALUE
 rlink_sentence_init( self, input_string, dictionary )
 }
 
 
-
 /*
- * parse( options={} )
- * --
- * Attach a parse set to this sentence and return the number of linkages
- * found.
+ *  call-seq:
+ *     sent.parse( options={} )   => fixnum
+ *
+ *  Attach a parse set to this sentence and return the number of linkages
+ *  found. If any +options+ are specified, they override those set in the 
+ *  sentence's dictionary.
+ * 
  */
 static VALUE
 rlink_sentence_parse( argc, argv, self )
 
 
 /*
- * parsed? => true or false
- * --
- * Returns +true+ if the sentence has been parsed.
+ *  call-seq:
+ *     parsed?   => true or false
+ *
+ *  Returns +true+ if the sentence has been parsed.
+ *
+ *     sentence.parsed?   #=> false
+ *     sentence.parse     #=> 6
+ *     sentence.parsed?   #=> true
  */
 static VALUE
 rlink_sentence_parsed_p( self )
 }
 
 
-/* 
- * linkages
- * --
- * Returns an Array of the linkages
+/*
+ *  call-seq:
+ *     linkages   => array
+ *
+ *  Returns an Array of LinkParser::Linkage objects which represent the
+ *  parts parsed from the sentence for the current linkage.
+ *
  */
 static VALUE
 rlink_sentence_linkages( self )
 }
 
 
-/* 
- * length
- * --
- * Returns the number of words in the tokenized sentence, including the 
- * boundary words and punctuation.
+/*
+ *  call-seq:
+ *     sentence.length   => fixnum
+ *
+ *  Returns the number of words in the tokenized sentence, including the 
+ *  boundary words and punctuation.
+ *
  */
+
 static VALUE
 rlink_sentence_length( self )
 	VALUE self;
 	word = sentence_get_word( (Sentence)ptr->sentence, FIX2INT(n) );
 	return rb_str_new2( word );
 }
+
+
+/*
+ *  call-seq:
+ *     words   => array
+ *
+ *  Returns the words of the sentence as they appear after tokenization.
+ *
+ *     sentence = LinkParser::Dictionary.new.parse( "The dogs barks." )
+ *     sentence.words  #=> 
+ */
+static VALUE
+rlink_sentence_words( self )
+	VALUE self;
+{
+	rlink_SENTENCE *ptr = get_sentence( self );
+	char *word;
+	int i, length;
+	VALUE words = rb_ary_new();
 	
+	length = sentence_length( (Sentence)ptr->sentence );
+	for ( i = 0; i < length; i++ ) {
+		word = sentence_get_word( (Sentence)ptr->sentence, i );
+		rb_ary_push( words, rb_str_new2(word) );
+	}
+	
+	return words;
+}
+
 
 /* 
  * null_count
 
 	rb_define_method( rlink_cSentence, "length", rlink_sentence_length, 0 );
 	rb_define_method( rlink_cSentence, "word", rlink_sentence_word, 1 );
+	rb_define_method( rlink_cSentence, "words", rlink_sentence_words, 0 );
 	rb_define_alias( rlink_cSentence, "[]", "word" );
 
 	rb_define_method( rlink_cSentence, "null_count", 

lib/linkparser.rb

+#!/usr/bin/ruby
+# 
+# Additional high-level functionality for the LinkParser library.
+# 
+# == Synopsis
+# 
+#   
+# 
+# == Authors
+# 
+# * Michael Granger <ged@FaerieMUD.org>
+# 
+# == Copyright
+#
+# Copyright (c) 2006 The FaerieMUD Consortium. Some rights reserved.
+# 
+# This work is licensed under the Creative Commons Attribution License. To view
+# a copy of this license, visit http://creativecommons.org/licenses/by/1.0/ or
+# send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
+# 94305, USA.
+# 
+# == Version
+#
+#  $Id$
+# 
+
+require 'linkparser_ext'
+
+
+### Additional high-level functionality for the LinkParser library.
+module LinkParser
+
+	require 'linkparser/sentence'
+	require 'linkparser/linkage'
+
+	# SVN Revision
+	SVNRev = %q$Rev$
+
+	# SVN Id
+	SVNId = %q$Id$
+
+end # class LinkParser
+

lib/linkparser/linkage.rb

+#!/usr/bin/ruby
+# 
+# Additional high-level functionality for LinkParser::Sentence objects.
+# 
+# == Synopsis
+# 
+#   
+# 
+# == Authors
+# 
+# * Michael Granger <ged@FaerieMUD.org>
+# 
+# == Copyright
+#
+# Copyright (c) 2006 The FaerieMUD Consortium. Some rights reserved.
+# 
+# This work is licensed under the Creative Commons Attribution License. To view
+# a copy of this license, visit http://creativecommons.org/licenses/by/1.0/ or
+# send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
+# 94305, USA.
+# 
+# == Version
+#
+#  $Id$
+# 
+
+require 'linkparser'
+
+
+### Additional high-level functionality for LinkParser::Sentence objects.
+class LinkParser::Linkage
+
+	# SVN Revision
+	SVNRev = %q$Rev$
+
+	# SVN Id
+	SVNId = %q$Id$
+
+	LinkTypes = {
+		:A  => %{connects pre-noun ("attributive") adjectives to following nouns: "The BIG DOG chased me", "The BIG BLACK UGLY DOG chased me".},
+		:AA => %{is used in the construction "How [adj] a [noun] was it?". It connects the adjective to the following "a".},
+		:AF => %{connects adjectives to verbs in cases where the adjective is fronted, such as questions and indirect questions: "How BIG IS it?"},
+		:AL => %{connects a few determiners like "all" or "both" to following determiners: "ALL THE people are here".},
+		:AM => %{connects "as" to "much" or "many": "I don't go out AS MUCH now".},
+		:AN => %{connects noun-modifiers to following nouns: "The TAX PROPOSAL was rejected".},
+		:AZ => %{connects the word "as" back to certain verbs that can take "[obj] as [adj]" as a complement: "He VIEWED him AS stupid".},
+		:B  => %{serves various functions involving relative clauses and questions. It connects transitive verbs back to their objects in relative clauses, questions, and indirect questions ("The DOG we CHASED", "WHO did you SEE?"); it also connects the main noun to the finite verb in subject-type relative clauses ("The DOG who CHASED me was black").},
+		:BI => %{connects forms of the verb "be" to certain idiomatic expressions: for example, cases like "He IS PRESIDENT of the company".},
+		:BT => %{is used with time expressions acting as fronted objects: "How many YEARS did it LAST?".},
+		:BW => %{connects "what" to various verbs like "think", which are not really transitive but can connect back to "what" in questions: "WHAT do you THINK?"},
+		:C  => %{links conjunctions to subjects of subordinate clauses ("He left WHEN HE saw me"). it also links certain verbs to subjects of embedded clauses ("He SAID HE was sorry").},
+		:CC => %{connects clauses to following coordinating conjunctions ("SHE left BUT we stayed").},
+		:CO => %{connects "openers" to subjects of clauses: "APPARENTLY / ON Tuesday , THEY went to a movie".},
+		:CP => %{connects paraphrasing or quoting verbs to the wall (and, indirectly, to the paraphrased expression): "///// That is untrue, the spokesman SAID."},
+		:CQ => %{connects to auxiliaries in comparative constructions involving s-v inversion: "SHE has more money THAN DOES Joe".},
+		:CX => %{is used in comparative constructions where the right half of the comparative contains only an auxiliary: "She has more money THAN he DOES".},
+		:D  => %{connects determiners to nouns: "THE DOG chased A CAT and SOME BIRDS".},
+		:DD => %{connects definite determiners ("the", "his") to certain things like number expressions and adjectives acting as nouns: "THE POOR", "THE TWO he mentioned".},
+		:DG => %{connects the word "The" with proper nouns: "the Riviera", "the Mississippi".},
+		:DP => %{connects possessive determiners to gerunds: "YOUR TELLING John to leave was stupid".},
+		:DT => %{connects determiners to nouns in idiomatic time expressions: "NEXT WEEK", "NEXT THURSDAY".},
+		:E  => %{is used for verb-modifying adverbs which precede the verb: "He is APPARENTLY LEAVING".},
+		:EA => %{connects adverbs to adjectives: "She is a VERY GOOD player".},
+		:EB => %{connects adverbs to forms of "be" before an object or prepositional phrase: "He IS APPARENTLY a good programmer".},
+		:EC => %{connects adverbs to comparative adjectives: "It is MUCH BIGGER"},
+		:EE => %{connects adverbs to other adverbs: "He ran VERY QUICKLY".},
+		:EF => %{connects the word "enough" to preceding adjectives and adverbs: "He didn't run QUICKLY ENOUGH".},
+		:EI => %{connects a few adverbs to "after" and "before": "I left SOON AFTER I saw you".},
+		:EL => %{connects certain words to the word "else": something / everything / anything / nothing , somewhere (etc.), and someone (etc.).},
+		:EN => %{connects certain adverbs to expressions of quantity: "The class has NEARLY FIFTY students".},
+		:ER => %{is used the expression "The x-er..., the y-er...". it connects the two halfs of the expression together, via the comparative words (e.g. "The FASTER it is, the MORE they will like it").},
+		:EZ => %{connects certain adverbs to the word "as", like "just" and "almost": "You're JUST AS good as he is."},
+		:FL => %{connects "for" to "long": "I didn't wait FOR LONG".},
+		:FM => %{connects the preposition "from" to various other prepositions: "We heard a scream FROM INSIDE the house".},
+		:G  => %{connects proper noun words together in series: "GEORGE HERBERT WALKER BUSH is here."},
+		:GN => %{(stage 2 only) connects a proper noun to a preceding common noun which introduces it: "The ACTOR Eddie MURPHY attended the event".},
+		:H  => %{connects "how" to "much" or "many": "HOW MUCH money do you have".},
+		:I  => %{connects infinitive verb forms to certain words such as modal verbs and "to": "You MUST DO it", "I want TO DO it".},
+		:ID => %{is a special class of link-types generated by the parser, with arbitrary four-letter names (such as "IDBT"), to connect together words of idiomatic expressions such as "at_hand" and "head_of_state".},
+		:IN => %{connects the preposition "in" to certain time expressions: "We did it IN DECEMBER".},
+		:J  => %{connects prepositions to their objects: "The man WITH the HAT is here".},
+		:JG => %{connects certain prepositions to proper-noun objects: "The Emir OF KUWAIT is here".},
+		:JQ => %{connects prepositions to question-word determiners in "prepositional questions": "IN WHICH room were you sleeping?"},
+		:JT => %{connects certain conjunctions to time-expressions like "last week": "UNTIL last WEEK, I thought she liked me".},
+		:K  => %{connects certain verbs with particles like "in", "out", "up" and the like: "He STOOD UP and WALKED OUT".},
+		:L  => %{connects certain determiners to superlative adjectives: "He has THE BIGGEST room".},
+		:LE => %{is used in comparative constructions to connect an adjective to the second half of the comparative expression beyond a complement phrase: "It is more LIKELY that Joe will go THAN that Fred will go".},
+		:LI => %{connects certain verbs to the preposition "like": "I FEEL LIKE a fool."},
+		:M  => %{connects nouns to various kinds of post-noun modifiers: prepositional phrases ("The MAN WITH the hat"), participle modifiers ("The WOMAN CARRYING the box"), prepositional relatives ("The MAN TO whom I was speaking"), and other kinds.},
+		:MF => %{is used in the expression "Many people were injured, SOME OF THEM children".},
+		:MG => %{allows certain prepositions to modify proper nouns: "The EMIR OF Kuwait is here".},
+		:MV => %{connects verbs and adjectives to modifying phrases that follow, like adverbs ("The dog RAN QUICKLY"), prepositional phrases ("The dog RAN IN the yard"), subordinating conjunctions ("He LEFT WHEN he saw me"), comparatives, participle phrases with commas, and other things.},
+		:MX => %{connects modifying phrases with commas to preceding nouns: "The DOG, a POODLE, was black". "JOHN, IN a black suit, looked great".},
+		:N  => %{connects the word "not" to preceding auxiliaries: "He DID NOT go".},
+		:ND => %{connects numbers with expressions that require numerical determiners: "I saw him THREE WEEKS ago".},
+		:NF => %{is used with NJ in idiomatic number expressions involving "of": "He lives two THIRDS OF a mile from here".},
+		:NI => %{is used in a few special idiomatic number phrases: "I have BETWEEN 5 AND 20 dogs".},
+		:NJ => %{is used with NF in idiomatic number expressions involving "of": "He lives two thirds OF a MILE from here".},
+		:NN => %{connects number words together in series: "FOUR HUNDRED THOUSAND people live here".},
+		:NO => %{is used on words which have no normal linkage requirement, but need to be included in the dictionary, such as "um" and "ah".},
+		:NR => %{connects fraction words with superlatives: "It is the THIRD BIGGEST city in China".},
+		:NS => %{connects singular numbers (one, 1, a) to idiomatic expressions requiring number determiners: "I saw him ONE WEEK ago".},
+		:NT => %{connects "not" to "to": "I told you NOT TO come".},
+		:NW => %{is used in idiomatic fraction expressions: "TWO THIRDS of the students were women".},
+		:O  => %{connects transitive verbs to their objects, direct or indirect: "She SAW ME", "I GAVE HIM the BOOK".},
+		:OD => %{is used for verbs like "rise" and "fall" which can take expressions of distance as complements: "It FELL five FEET".},
+		:OF => %{connects certain verbs and adjectives to the word "of": "She ACCUSED him OF the crime", "I'm PROUD OF you".},
+		:ON => %{connectors the word "on" to dates or days of the week in time expressions: "We saw her again ON TUESDAY".},
+		:OT => %{is used for verbs like "last" which can take time expressions as objects: "It LASTED five HOURS".},
+		:OX => %{is an object connector, analogous to SF, used for special "filler" words like "it" and "there" when used as objects: "That MAKES IT unlikely that she will come".},
+		:P  => %{connects forms of the verb "be" to various words that can be its complements: prepositions, adjectives, and passive and progressive participles: "He WAS [ ANGRY / IN the yard / CHOSEN / RUNNING ]".},
+		:PF => %{is used in certain questions with "be", when the complement need of "be" is satisfied by a preceding question word: "WHERE are you?", "WHEN will it BE?"},
+		:PP => %{connects forms of "have" with past participles: "He HAS GONE".},
+		:Q  => %{is used in questions. It connects the wall to the auxiliary in simple yes-no questions ("///// DID you go?"); it connects the question word to the auxiliary in where-when-how questions ("WHERE DID you go").},
+		:QI => %{connects certain verbs and adjectives to question-words, forming indirect questions: "He WONDERED WHAT she would say".},
+		:R  => %{connects nouns to relative clauses. In subject-type relatives, it connects to the relative pronoun ("The DOG WHO chased me was black"); in object-type relatives, it connects either to the relative pronoun or to the subject of the relative clause ("The DOG THAT we chased was black", "The DOG WE chased was black").},
+		:RS => %{is used in subject-type relative clauses to connect the relative pronoun to the verb: "The dog WHO CHASED me was black".},
+		:RW => %{connects the right-wall to the left-wall in cases where the right-wall is not needed for punctuation purposes.},
+		:S  => %{connects subject nouns to finite verbs: "The DOG CHASED the cat": "The DOG [ IS chasing / HAS chased / WILL chase ] the cat".},
+		:SF => %{is a special connector used to connect "filler" subjects like "it" and "there" to finite verbs: "THERE IS a problem", "IT IS likely that he will go".},
+		:SFI => %{connects "filler" subjects like "it" and "there" to verbs in cases with subject-verb inversion: "IS THERE a problem?", "IS IT likely that he will go?"},
+		:SI => %{connects subject nouns to finite verbs in cases of subject-verb inversion: "IS JOHN coming?", "Who DID HE see?"},
+		:SX => %{connects "I" to special first-person verbs lke "was" and "am".},
+		:SXI => %{connects "I" to first-person verbs in cases of s-v inversion.},
+		:TA => %{is used to connect adjectives like "late" to month names: "We did it in LATE DECEMBER".},
+		:TD => %{connects day-of-the-week words to time expressions like "morning": "We'll do it MONDAY MORNING".},
+		:TH => %{connects words that take "that [clause]" complements with the word "that". These include verbs ("She TOLD him THAT..."), nouns ("The IDEA THAT..."), and adjectives ("We are CERTAIN THAT").},
+		:TI => %{is used for titles like "president", which can be used in certain cirumstances without a determiner: "AS PRESIDENT of the company, it is my decision".},
+		:TM => %{is used to connect month names to day numbers: "It happened on JANUARY 21".},
+		:TO => %{connects verbs and adjectives which take infinitival complements to the word "to": "We TRIED TO start the car", "We are EAGER TO do it".},
+		:TQ => %{is the determiner connector for time expressions acting as fronted objects: "How MANY YEARS did it last".},
+		:TS => %{connects certain verbs that can take subjunctive clauses as complements - "suggest", "require" - to the word that: "We SUGGESTED THAT he go".},
+		:TW => %{connects days of the week to dates in time expressions: "The meeting will be on MONDAY, JANUARY 21".},
+		:TY => %{is used for certain idiomatic usages of year numbers: "I saw him on January 21 , 1990 ". (In this case it connects the day number to the year number.)},
+		:U  => %{is a special connector on nouns, which is disjoined with both the determiner and subject-object connectors. It is used in idiomatic expressions like "What KIND_OF DOG did you buy?"},
+		:UN => %{connects the words "until" and "since" to certain time phrases like "after [clause]": "You should wait UNTIL AFTER you talk to me".},
+		:V  => %{connects various verbs to idiomatic expressions that may be non-adjacent: "We TOOK him FOR_GRANTED", "We HELD her RESPONSIBLE".},
+		:W  => %{connects the subjects of main clauses to the wall, in ordinary declaratives, imperatives, and most questions (except yes-no questions). It also connects coordinating conjunctions to following clauses: "We left BUT SHE stayed".},
+		:WN => %{connects the word "when" to time nouns like "year": "The YEAR WHEN we lived in England was wonderful".},
+		:WR => %{connects the word "where" to a few verbs like "put" in questions like "WHERE did you PUT it?".},
+		:X  => %{is used with punctuation, to connect punctuation symbols either to words or to each other. For example, in this case, POODLE connects to commas on either side: "The dog , a POODLE , was black."},
+		:Y  => %{is used in certain idiomatic time and place expressions, to connect quantity expressions to the head word of the expression: "He left three HOURS AGO", "She lives three MILES FROM the station".},
+		:YP => %{connects plural noun forms ending in s to "'" in possessive constructions: "The STUDENTS ' rooms are large".},
+		:YS => %{connects nouns to the possessive suffix "'s": "JOHN 'S dog is black".},
+		:Z  => %{connects the preposition "as" to certain verbs: "AS we EXPECTED, he was late".},
+	}
+
+	# Link struct types
+	Link = Struct.new( "LinkParserLink", :lword, :rword, :length, :label, :llabel, :rlabel, :desc )
+	
+
+	######
+	public
+	######
+
+	### Return a human-readable representation of the Sentence object.
+	def inspect
+		%{#<%s:0x%x: sublinkage %d: [%d links]>} % [
+			self.class.name,
+			self.object_id / 2,
+			self.current_sublinkage,
+			self.num_links
+		]
+	end
+
+
+	### Return the +index+th link.
+	def link( index )
+		Link.new( 
+			self.words[ self.link_lword(index) ],
+			self.words[ self.link_rword(index) ],
+			self.link_length(index),
+			self.link_label(index),
+			self.link_llabel(index),
+			self.link_rlabel(index),
+			LinkTypes[ self.link_label(index).gsub(/[^A-Z]+/, '').to_sym ]
+		)
+	end
+	
+
+	### Return the Array of words in the sentence as tokenized by the
+	### parser.
+	def links
+		( 0...self.link_count ).collect do |i|
+			self.link( i )
+		end
+	end
+
+
+	### Return the verb word from the linkage.
+	def verb
+		if link = self.links.find {|link| link.llabel =~ /^(O([DFNTX]?)|P|BI|K|LI|MV|Q)[a-z\*]*/ }
+			return link.lword.sub( /\.v$/, '' )
+		elsif link = self.links.find {|link| link.rlabel =~ /^(SI|S|AF)[a-z\*]*/ }
+			return link.lword.sub( /\.v$/, '' )
+		else
+			return nil
+		end
+	end
+
+
+	### Return the subject from the linkage.
+	def subject
+		link = self.links.find {|link| link.llabel[0] == ?S } or return nil
+		return link.lword.sub( /\.n$/, '' )
+	end
+	
+
+	### Return the object from the linkage.
+	def object
+		link = self.links.find {|link| link.rlabel[0] == ?O } or return nil
+		return link.rword.sub( /\.n$/, '' )
+	end
+
+
+	### Returns +true+ if the linkage indicates the sentence is phrased in the
+	### imperative voice.
+	def imperative?
+		return self.links.find {|link| link.label == 'Wi' && link.rword =~ /\.v$/ } ?
+			true : false
+	end
+	
+	
+	### Returns +true+ if the linkage has more than one sublinkage (i.e., the 
+	### sentence has a conjunction).
+	def has_conjunction?
+		return self.num_sublinkages > 1
+	end
+	
+
+end # class Sentence
+

lib/linkparser/sentence.rb

+#!/usr/bin/ruby
+# 
+# Additional high-level functionality for LinkParser::Sentence objects.
+# 
+# == Synopsis
+# 
+#   
+# 
+# == Authors
+# 
+# * Michael Granger <ged@FaerieMUD.org>
+# 
+# == Copyright
+#
+# Copyright (c) 2006 The FaerieMUD Consortium. Some rights reserved.
+# 
+# This work is licensed under the Creative Commons Attribution License. To view
+# a copy of this license, visit http://creativecommons.org/licenses/by/1.0/ or
+# send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California
+# 94305, USA.
+# 
+# == Version
+#
+#  $Id$
+# 
+
+require 'linkparser'
+
+
+### Additional high-level functionality for LinkParser::Sentence objects.
+class LinkParser::Sentence
+
+	# SVN Revision
+	SVNRev = %q$Rev$
+
+	# SVN Id
+	SVNId = %q$Id$
+
+
+	######
+	public
+	######
+
+	### Return a human-readable representation of the Sentence object.
+	def inspect
+		%{#<%s:0x%x "%s"/%d linkages/%d nulls>} % [
+			self.class.name,
+			self.object_id / 2,
+			self.words.join(" "),
+			self.num_linkages_found,
+			self.null_count,
+		]
+	end
+
+
+	### Return the Array of words in the sentence as tokenized by the
+	### parser.
+	def words
+		(0...self.length).to_a.collect do |i|
+			self.word( i )
+		end
+	end
+	
+
+end # class Sentence
+

linkparser-path.rb

+#!/usr/bin/ruby
+
+BEGIN {
+	require 'pathname'
+	basedir = Pathname.new( __FILE__ ).dirname
+	$LOAD_PATH.unshift( basedir + 'ext' ) unless 
+		$LOAD_PATH.include?( basedir + 'ext' )
+	$LOAD_PATH.unshift( basedir + 'lib' ) unless 
+		$LOAD_PATH.include?( basedir + 'lib' )
+}
 #
 
 BEGIN {
-	$basedir = File.expand_path( File.dirname(__FILE__) )
-	["lib", "ext"].each do |subdir|
-		$LOAD_PATH.unshift File.join( $basedir, subdir )
-	end
-
-	require "#{$basedir}/utils"
+	require 'pathname'
+	$basedir = Pathname.new( __FILE__ ).dirname
+	require $basedir + "linkparser-path.rb"
+	require $basedir + "utils.rb"
 	include UtilityFunctions
 }
 
     patterns.collect {|pat| "  " + pat.to_s }.join( "\n" )
 
 ### Load all the tests from the tests dir
-Find.find( File.join($basedir, "tests") ) {|file|
+Find.find( $basedir + "tests" ) {|file|
 	Find.prune if /\/\./ =~ file or /~$/ =~ file
 	Find.prune if /TEMPLATE/ =~ file
 	next if File.stat( file ).directory?

tests/dictionary.tests.rb

 BEGIN {
 	require 'pathname'
 	basedir = Pathname.new( __FILE__ ).dirname.parent
-	
-	$LOAD_PATH.unshift( basedir + 'ext' ) unless 
-		$LOAD_PATH.include?( basedir + 'ext' )
+	require basedir + "linkparser-path.rb"
 }
 
 require 'test/unit'

tests/linkage.tests.rb

 BEGIN {
 	require 'pathname'
 	basedir = Pathname.new( __FILE__ ).dirname.parent
-	
-	$LOAD_PATH.unshift( basedir + 'ext' ) unless 
-		$LOAD_PATH.include?( basedir + 'ext' )
+	require basedir + 'linkparser-path.rb'
 }
 
 require 'test/unit'
 		assert_respond_to @ss_linkage, :violation_name
 	end
 
+    #1         LEFT-WALL      Xp      <---Xp---->  Xp        .
+    #2   (m)   LEFT-WALL      Wd      <---Wd---->  Wd        flag.n
+    #3+4 (m)   the            D       <---Ds---->  Ds        flag.n
+    #5   (m)   flag.n         Ss      <---Ss---->  Ss        was.v
+    #6   (m)   was.v          Pa      <---Pa---->  Pa        wet.a
+	def test_linkage_links_should_contain_link_structs_describing_the_linkage
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @ss_linkage.links
+		end
+		
+		assert_instance_of Array, rval
+		assert_kind_of Struct, rval.first
+		assert_equal 'LEFT-WALL', rval.first.lword, "left word of first link"
+		assert_equal 'Xp', rval.first.label, "label of first link"
+		assert_equal 'RIGHT-WALL', rval.last.rword, "right word of last link"
+		assert_equal 'RW', rval.last.label, "label of last link"
+		assert_equal 'flag.n', rval[3].lword, "left word of the fourth link"
+		assert_equal 'was.v', rval[3].rword, "right word of the fourth link"
+		assert_equal 'Ss', rval[3].label, "label of the fourth link"
+	end
+
+
+	def test_linkage_verb_should_return_sentence_verb
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @ss_linkage.verb
+		end
+		
+		assert_equal "was", rval
+	end
+
+
+	# The ball rolled down the hill and bumped the curb.
+	def test_linkage_verb_should_return_vword_of_current_sublinkage_of_conjunction
+		rval = nil
+		linkage = @conjunct_sentence.linkages.first
+		
+		assert_nothing_raised do
+			rval = linkage.verb
+		end
+		
+		assert_equal 'rolled', rval
+		
+		assert_nothing_raised do
+			linkage.current_sublinkage = 1
+			rval = linkage.verb
+		end
+		
+		assert_equal 'bumped', rval
+	end
 end
 

tests/parseoptions.tests.rb

 BEGIN {
 	require 'pathname'
 	basedir = Pathname.new( __FILE__ ).dirname.parent
-	
-	$LOAD_PATH.unshift( basedir + 'ext' ) unless 
-		$LOAD_PATH.include?( basedir + 'ext' )
+	require basedir + "linkparser-path.rb"
 }
 
+
 require 'test/unit'
 require 'linkparser'
 

tests/sentence.tests.rb

 BEGIN {
 	require 'pathname'
 	basedir = Pathname.new( __FILE__ ).dirname.parent
-	
-	$LOAD_PATH.unshift( basedir + 'ext' ) unless 
-		$LOAD_PATH.include?( basedir + 'ext' )
+	require basedir + "linkparser-path.rb"
 }
 
+
 require 'test/unit'
 require 'linkparser'