Commits

Michael Granger committed d9ed649

* Fixes for documentation
* Fixed constituent_tree_string's mode argument.

Comments (0)

Files changed (5)

 
 
 /*
- * new( options={} )
- * new( language, options={} )
- * new( dict, pp, ck, affix, option={} )
- * --
- * Create a new LinkParser::Dictionary with data files for the given +language+, or
- * using the specified data files.
+ *  call-seq:
+ *    LinkParser::Dictionary.new( options={} )
+ *    LinkParser::Dictionary.new( language, options={} )
+ *    LinkParser::Dictionary.new( dict, pp, ck, affix, option={} )
+ * 
+ *  Create a new LinkParser::Dictionary with data files for the given +language+, or
+ *  using the specified data files.
+ *
+ *
+ *
  */
 static VALUE
 rlink_dict_initialize( argc, argv, self )
 void
 rlink_init_dict(void)
 {
+#ifdef FOR_RDOC
+	rlink_mLinkParser = rb_define_module( "LinkParser" );
+	rlink_eLpError = rb_define_class_under( rlink_mLinkParser, "Error", rb_eRuntimeError );
+#endif
+
 	rlink_cDictionary = rb_define_class_under( rlink_mLinkParser, "Dictionary",
 	 	rb_cObject );
 	
  *  call-seq:
  *     linkage.constituent_tree_string( mode=1 )   => str
  *
- *  Return 
+ *  Return the constituent tree as a printable string.
  *
- *     example code
+ *  Example:
+ *     sent = dict.parse( "He is a big dog." )
+ *     link = sent.linkages.first
+ *     link.constituent_tree_string
+ #  
+ #  # ==> "(S (NP He)\n   (VP is\n       (NP a big dog))\n   .)\n"
  */
 static VALUE
-rlink_linkage_constituent_tree_string( self, mode )
-	VALUE self, mode;
+rlink_linkage_constituent_tree_string( argc, argv, self )
+	int argc;
+	VALUE *argv;
+	VALUE self;
 {
 	rlink_LINKAGE *ptr = get_linkage( self );
 	char *ctree_string = NULL;
-	VALUE rval = Qnil;
+	VALUE rval, modenum;
+	int mode;
 	
-	ctree_string = linkage_print_constituent_tree( (Linkage)ptr->linkage, NUM2INT(mode) );
+	if ( rb_scan_args(argc, argv, "01", &modenum) == 1 ) {
+		mode = NUM2INT( modenum );
+	} else {
+		mode = 1;
+	}
+
+	if ( mode < 1 || mode > 3 )
+		rb_raise( rb_eArgError, "Illegal mode %d specified.", mode );
+
+	ctree_string = linkage_print_constituent_tree( (Linkage)ptr->linkage, mode );
 
 	if ( ctree_string ) {
 		rval = rb_str_new2( ctree_string );
 void
 rlink_init_linkage(void)
 {
+#ifdef FOR_RDOC
+	rlink_mLinkParser = rb_define_module( "LinkParser" );
+	rlink_eLpError = rb_define_class_under( rlink_mLinkParser, "Error", rb_eRuntimeError );
+#endif
+
 	rlink_cLinkage = rb_define_class_under( rlink_mLinkParser, "Linkage", rb_cObject );
 	
 	rb_define_alloc_func( rlink_cLinkage, rlink_linkage_s_alloc );
 	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 );
+	 	rlink_linkage_constituent_tree_string, -1 );
 }
 

ext/parseoptions.c

 void
 rlink_init_parseoptions(void)
 {
+#ifdef FOR_RDOC
+	rlink_mLinkParser = rb_define_module( "LinkParser" );
+	rlink_eLpError = rb_define_class_under( rlink_mLinkParser, "Error", rb_eRuntimeError );
+#endif
+	
 	rlink_cParseOptions = rb_define_class_under( rlink_mLinkParser, 
 		"ParseOptions", rb_cObject );
 
 void
 rlink_init_sentence( void )
 {
+#ifdef FOR_RDOC
+	rlink_mLinkParser = rb_define_module( "LinkParser" );
+	rlink_eLpError = rb_define_class_under( rlink_mLinkParser, "Error", rb_eRuntimeError );
+#endif
+
 	rlink_cSentence = rb_define_class_under( rlink_mLinkParser, "Sentence",
 	 	rb_cObject );
 	

tests/linkage.tests.rb

 		
 		assert_equal 'bumped', rval
 	end
+
+	
+	
+	Mode1CTreeString = "(S (NP The flag)\n   (VP was\n       (ADJP wet))\n   .)\n"
+	Mode2CTreeString = "[S [NP The flag NP] [VP was [ADJP wet ADJP] VP] . S] \n"
+	Mode3CTreeString = "(S (NP The flag) (VP was (ADJP wet)) .)\n"
+	
+	def test_constituent_tree_string_without_mode_should_return_mode1_string
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @ss_linkage.constituent_tree_string
+		end
+		
+		assert_equal Mode1CTreeString, rval
+	end
+
+
+	def test_constituent_tree_string_with_mode1_should_return_mode1_string
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @ss_linkage.constituent_tree_string( 1 )
+		end
+		
+		assert_equal Mode1CTreeString, rval
+	end
+
+	def test_constituent_tree_string_with_mode2_should_return_mode2_string
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @ss_linkage.constituent_tree_string( 2 )
+		end
+		
+		assert_equal Mode2CTreeString, rval
+	end
+
+	def test_constituent_tree_string_with_mode3_should_return_mode3_string
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @ss_linkage.constituent_tree_string( 3 )
+		end
+		
+		assert_equal Mode3CTreeString, rval
+	end
+
+	def test_constituent_tree_string_with_mode4_should_raise_exception
+		assert_raises( ArgumentError ) do
+			@ss_linkage.constituent_tree_string( 4 )
+		end
+	end
+
+	def test_constituent_tree_string_with_nonnumeric_should_raise_exception
+		assert_raises( TypeError ) do
+			@ss_linkage.constituent_tree_string( "Glah" )
+		end
+	end
+
+
+	def test_constituent_tree_should_return_array_of_CTree_structs
+		rval = nil
+		
+		assert_nothing_raised do 
+			rval = @ss_linkage.constituent_tree
+		end
+		
+		assert_kind_of Array, rval
+		assert_kind_of Struct, rval.first
+		assert_equal "S", rval.first.label
+		assert_equal "NP", rval.first.children.first.label
+		assert_equal "The", rval.first.children.first.children.first.label
+	end
+	
 end