Michael Granger avatar Michael Granger committed ae31f32

Checkpoint commit:

* Fleshed out LinkParser::Linkage a bit more (not yet complete)
* Gave up on running tests with testrb and imported test.rb from
project-utils.
* Added TextMate project file
* Added an .irbrc

Comments (0)

Files changed (8)

+# -*- ruby -*-
+
+puts ">>> Adding 'lib' to load path..."
+$LOAD_PATH.unshift( "lib", "ext" )
+
+#puts ">>> Turning on $VERBOSE and $DEBUG..."
+# $VERBOSE = $DEBUG = true
+
+require './utils'
+include UtilityFunctions
+
+def colored( prompt, *args )
+	return ansiCode( *(args.flatten) ) + prompt + ansiCode( 'reset' )
+end
+
+
+# Modify prompt to do highlighting
+IRB.conf[:PROMPT][:LINKPARSER] = { # name of prompt mode
+ 	:PROMPT_I => colored( "%N(%m):%03n:%i>", %w{bold white on_blue} ) + " ",
+ 	:PROMPT_S => colored( "%N(%m):%03n:%i%l", %w{white on_blue} ) + " ",
+ 	:PROMPT_C => colored( "%N(%m):%03n:%i*", %w{white on_blue} ) + " ",
+    :RETURN => "    ==> %s\n\n"      # format to return value
+}
+IRB.conf[:PROMPT_MODE] = :LINKPARSER
+
+# Try to require the 'linkparser' library
+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
+

LinkParser Project.tmproj

+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple Computer//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+	<key>currentDocument</key>
+	<string>ext/linkage.c</string>
+	<key>documents</key>
+	<array>
+		<dict>
+			<key>expanded</key>
+			<true/>
+			<key>name</key>
+			<string>LinkParser</string>
+			<key>regexFolderFilter</key>
+			<string>!.*/(\.[^/]*|CVS|_darcs|\{arch\}|blib|.*~\.nib|.*\.(framework|app|pbproj|pbxproj|xcode(proj)?|bundle))$</string>
+			<key>sourceDirectory</key>
+			<string></string>
+		</dict>
+	</array>
+	<key>fileHierarchyDrawerWidth</key>
+	<integer>219</integer>
+	<key>metaData</key>
+	<dict>
+		<key>docs/link-includes.h</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>40</integer>
+				<key>line</key>
+				<integer>249</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>219</integer>
+		</dict>
+		<key>ext/dictionary.c</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>4</integer>
+		</dict>
+		<key>ext/linkage.c</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>1</integer>
+				<key>line</key>
+				<integer>62</integer>
+			</dict>
+			<key>columnSelection</key>
+			<false/>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>15</integer>
+			<key>selectFrom</key>
+			<dict>
+				<key>column</key>
+				<integer>1</integer>
+				<key>line</key>
+				<integer>56</integer>
+			</dict>
+			<key>selectTo</key>
+			<dict>
+				<key>column</key>
+				<integer>1</integer>
+				<key>line</key>
+				<integer>62</integer>
+			</dict>
+		</dict>
+		<key>ext/parseoptions.c</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>1093</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>959</integer>
+		</dict>
+		<key>ext/sentence.c</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>457</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>405</integer>
+		</dict>
+		<key>extconf.rb</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>41</integer>
+				<key>line</key>
+				<integer>27</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>17</integer>
+		</dict>
+		<key>test.rb</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>40</integer>
+				<key>line</key>
+				<integer>31</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>0</integer>
+		</dict>
+		<key>tests/dictionary.tests.rb</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>59</integer>
+		</dict>
+		<key>tests/linkage.tests.rb</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>87</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>30</integer>
+		</dict>
+		<key>tests/parseoptions.tests.rb</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>9</integer>
+		</dict>
+		<key>tests/sentence.tests.rb</key>
+		<dict>
+			<key>caret</key>
+			<dict>
+				<key>column</key>
+				<integer>0</integer>
+				<key>line</key>
+				<integer>28</integer>
+			</dict>
+			<key>firstVisibleColumn</key>
+			<integer>0</integer>
+			<key>firstVisibleLine</key>
+			<integer>8</integer>
+		</dict>
+	</dict>
+	<key>openDocuments</key>
+	<array>
+		<string>ext/linkage.c</string>
+		<string>extconf.rb</string>
+		<string>tests/linkage.tests.rb</string>
+		<string>docs/link-includes.h</string>
+	</array>
+	<key>showFileHierarchyDrawer</key>
+	<true/>
+	<key>windowFrame</key>
+	<string>{{47, 26}, {836, 1002}}</string>
+</dict>
+</plist>
 
 
 /* 
+ * 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.
+ */
+static VALUE
+rlink_linkage_print_postscript( self, full_doc )
+	VALUE self, full_doc;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	char *diagram_cstr;
+	VALUE diagram;
+	
+	diagram_cstr = linkage_print_postscript( (Linkage)ptr->linkage,
+		RTEST(full_doc) ? 1 : 0 );
+	diagram = rb_str_new2( diagram_cstr );
+	string_delete( diagram_cstr );
+	
+	return diagram;
+}
+
+
+/* 
  * links_and_domains
  * --
  * Return a String containing a lists all of the links and domain names for 
 
 
 
+/* 
+ * num_sublinkages
+ * --
+ * Return the number of sublinkages for a linkage with conjunctions, 1 
+ * otherwise.
+ */
+static VALUE
+rlink_linkage_num_sublinkages( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return INT2FIX( linkage_get_num_sublinkages((Linkage)ptr->linkage) );
+}
+
+
+/*
+ * num_words
+ * --
+ * The number of words in the sentence for which this is a linkage. Note that 
+ * this function does not return the number of words used in the current 
+ * sublinkage.
+ */
+static VALUE
+rlink_linkage_get_num_words( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return INT2FIX( linkage_get_num_words((Linkage)ptr->linkage) );
+}
+
+
+/*
+ * num_links
+ * --
+ * The number of links used in the current sublinkage.
+ */
+static VALUE
+rlink_linkage_get_num_links( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return INT2FIX( linkage_get_num_links((Linkage)ptr->linkage) );
+}
+
+
+/*
+ * link_lword( index )
+ * --
+ * The number of the word on the left end of the index-th link of the 
+ * current sublinkage.
+ */
+static VALUE
+rlink_linkage_get_link_lword( self, index )
+	VALUE self, index;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	int i = FIX2INT( index );
+	
+	return INT2FIX( linkage_get_link_lword((Linkage)ptr->linkage, i) );
+}
+
+
+/*
+ * link_rword( index )
+ * --
+ * The number of the word on the right end of the index-th link of the 
+ * current sublinkage.
+ */
+static VALUE
+rlink_linkage_get_link_rword( self, arg )
+	VALUE self, arg;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	int i = FIX2INT( index );
+	
+	return INT2FIX( linkage_get_link_rword((Linkage)ptr->linkage, i) );
+}
+
+
+/*
+ * link_length( index )
+ * --
+ * The number of words spanned by the index-th link of the current sublinkage.
+ */
+static VALUE
+rlink_linkage_get_link_length( self, index )
+	VALUE self, index;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	int i = FIX2INT( index );
+	
+	return INT2FIX( linkage_get_link_length((Linkage)ptr->linkage, i) );
+}
+
+
+/*
+ * link_label( index ) => str
+ * --
+ * The "intersection" of the left and right connectors that comprise the link.
+ */
+static VALUE
+rlink_linkage_get_link_label( self, index )
+	VALUE self, index;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	int i = FIX2INT( index );
+	char *label;
+	
+	label = linkage_get_link_label( (Linkage)ptr->linkage, i );
+	return rb_str_new2( label );
+}
+
+
+/*
+ * link_llabel => str
+ * --
+ * 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 *ptr = get_linkage( self );
+	int i = FIX2INT( index );
+	char *label;
+	
+	label = linkage_get_link_llabel( (Linkage)ptr->linkage, i );
+	return rb_str_new2( label );
+}
+
+/*
+ * link_rlabel => str
+ * --
+ * 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 *ptr = get_linkage( self );
+	int i = FIX2INT( index );
+	char *label;
+	
+	label = linkage_get_link_rlabel( (Linkage)ptr->linkage, i );
+	return rb_str_new2( label );
+}
+
+
+/*
+ * link_num_domains( index ) => fixnum
+ * --
+ * 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 count = 0;
+	
+	count = linkage_get_link_num_domains( (Linkage)ptr->linkage, i );
+	return INT2FIX( count );
+}
+
+
+/*
+ * link_domain_names => array
+ * --
+ * The names of the domains the index-th link belongs to.
+ */
+static VALUE
+rlink_linkage_get_link_domain_names( self, index )
+	VALUE self, index;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	char **names;
+	int i = FIX2INT( index );
+	int count;
+	VALUE names_ary;
+	
+	names = linkage_get_link_domain_names( (Linkage)ptr->linkage, i );
+	count = linkage_get_link_num_domains( (Linkage)ptr->linkage, i );
+	names_ary = rb_ary_new2( count );
+	
+	for ( i = 0; i < count; i++ ) {
+		rb_ary_store( names_ary, i, rb_str_new2(namesquicksilver[i]) );
+	}
+	
+	return 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.
+ */
+static VALUE
+rlink_linkage_get_words( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	char **words;
+	int count, i;
+	VALUE words_ary;
+	
+	count = linkage_get_num_words( (Linkage)ptr->linkage );
+	words = linkage_get_words( (Linkage)ptr->linkage );
+	words_ary = rb_ary_new2( count );
+	
+	for ( i = 0; i < count; i++ ) {
+		rb_ary_store( words_ary, i, rb_str_new2(words[i]) );
+	}
+	
+	return words_ary;
+}
+
+
+/*
+ * 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.
+ */
+static VALUE
+rlink_linkage_compute_union( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	int rval;
+	
+	rval = linkage_compute_union( )
+}
+
+/*
+ * unused_word_cost
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_unused_word_cost( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+/*
+ * disjunct_cost
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_disjunct_cost( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+/*
+ * and_cost
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_and_cost( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+/*
+ * link_cost
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_link_cost( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+/*
+ * canonical?
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_canonical_p( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+
+/*
+ * improper?
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_improper_p( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+
+/*
+ * has_inconsistent_domains?
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_has_inconsistent_domains_p( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+
+/*
+ * violation_name
+ * --
+ * 
+ */
+static VALUE
+rlink_linkage_get_violation_name( self )
+	VALUE self;
+{
+	rlink_LINKAGE *ptr = get_linkage( self );
+	return Qnil;
+}
+
+
+
 /* Class initializer */
 void
 rlink_init_linkage(void)
 	
 	rb_define_method( rlink_cLinkage, "initialize", rlink_linkage_init, -1 );
 	rb_define_method( rlink_cLinkage, "diagram", rlink_linkage_diagram, 0 );
-	rb_define_method( rlink_cLinkage, "diagram", rlink_linkage_diagram, 0 );
+	rb_define_method( rlink_cLinkage, "postscript_diagram",
+	 	rlink_linkage_print_postscript, 1 );
 	rb_define_method( rlink_cLinkage, "links_and_domains", 
 		rlink_linkage_links_and_domains, 0 );
-}
 
+	rb_define_method( rlink_cLinkage, "num_sublinkages", 
+		rlink_linkage_num_sublinkages, 0 );
+	
+	rb_define_method( rlink_cLinkage, "num_words",
+	 	rlink_linkage_get_num_words, 0 );
+	rb_define_method( rlink_cLinkage, "num_links",
+	 	rlink_linkage_get_num_links, 0 );
+	
+	rb_define_method( rlink_cLinkage, "link_lword",
+	 	rlink_linkage_get_link_lword, 1 );
+	rb_define_method( rlink_cLinkage, "link_rword",
+	 	rlink_linkage_get_link_rword, 1 );
+	rb_define_method( rlink_cLinkage, "link_length",
+	 	rlink_linkage_get_link_length, 1 );
+	rb_define_method( rlink_cLinkage, "link_label",
+	 	rlink_linkage_get_link_label, 1 );
+	rb_define_method( rlink_cLinkage, "link_llabel",
+	 	rlink_linkage_get_link_llabel, 1 );
+	rb_define_method( rlink_cLinkage, "link_rlabel",
+	 	rlink_linkage_get_link_rlabel, 1 );
+
+	rb_define_method( rlink_cLinkage, "link_num_domains",
+	 	rlink_linkage_get_link_num_domains, 1 );
+	rb_define_method( rlink_cLinkage, "link_domain_names",
+	 	rlink_linkage_get_link_domain_names, 1 );
+	
+	rb_define_method( rlink_cLinkage, "words",
+	 	rlink_linkage_get_words, 0 );
+
+	rb_define_method( rlink_cLinkage, "compute_union",
+	 	rlink_linkage_compute_union, 0 );
+	rb_define_method( rlink_cLinkage, "unused_word_cost",
+	 	rlink_linkage_unused_word_cost, 0 );
+	rb_define_method( rlink_cLinkage, "disjunct_cost",
+	 	rlink_linkage_disjunct_cost, 0 );
+	rb_define_method( rlink_cLinkage, "and_cost",
+	 	rlink_linkage_and_cost, 0 );
+	rb_define_method( rlink_cLinkage, "link_cost",
+	 	rlink_linkage_link_cost, 0 );
+	rb_define_method( rlink_cLinkage, "canonical?",
+	 	rlink_linkage_canonical_p, 0 );
+	rb_define_method( rlink_cLinkage, "improper?",
+	 	rlink_linkage_improper_p, 0 );
+	rb_define_method( rlink_cLinkage, "has_inconsistent_domains?",
+	 	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 );
+*/}
+
 	docs/makedocs.rb -v
 
 test: all
-	testrb -a tests/*.rb
+	testrb -a tests/*.tests.rb
 
 debugtest: clean all
-	ruby -wd test.rb
-
+	ruby -wd -e <<EOF \
+	require 'test/unit' \
+	(r = Test::Unit::AutoRunner.new(true)).process_args(ARGV) or \
+	  abort r.options.banner + " tests..." \
+	exit r.run \
 	EOF
 end
 
+#!/usr/bin/ruby
+#
+#	Test suite for LinkParser
+#
+#
+
+BEGIN {
+	$basedir = File.expand_path( File.dirname(__FILE__) )
+	["lib", "ext"].each do |subdir|
+		$LOAD_PATH.unshift File.join( $basedir, subdir )
+	end
+
+	require "#{$basedir}/utils"
+	include UtilityFunctions
+}
+
+require 'optparse'
+
+# Turn off output buffering
+$stderr.sync = $stdout.sync = true
+
+# Initialize variables
+safelevel = 0
+patterns = []
+requires = []
+$DebugPattern = nil
+
+# Parse command-line switches
+ARGV.options {|oparser|
+	oparser.banner = "Usage: #$0 [options] [TARGETS]\n"
+
+	oparser.on( "--debug", "-d", FalseClass, "Turn debugging on" ) {
+		$DEBUG = true
+	}
+
+	oparser.on( "--verbose", "-v", TrueClass, "Make progress verbose" ) {
+		$VERBOSE = true
+		debugMsg "Turned verbose on."
+	}
+
+	# Handle the 'help' option
+	oparser.on( "--help", "-h", "Display this text." ) {
+		$stderr.puts oparser
+		exit!(0)
+	}
+
+	oparser.parse!
+}
+
+verboseOff {
+	require 'find'
+	require 'test/unit'
+	require 'test/unit/testsuite'
+	require 'test/unit/ui/console/testrunner'
+}
+
+# Parse test patterns
+ARGV.each {|pat| patterns << Regexp.new( pat, Regexp::IGNORECASE )}
+$stderr.puts "#{patterns.length} patterns given on the command line:",
+    patterns.collect {|pat| "  " + pat.to_s }.join( "\n" )
+
+### Load all the tests from the tests dir
+Find.find( File.join($basedir, "tests") ) {|file|
+	Find.prune if /\/\./ =~ file or /~$/ =~ file
+	Find.prune if /TEMPLATE/ =~ file
+	next if File.stat( file ).directory?
+
+ 	unless patterns.empty?
+ 		Find.prune unless patterns.find {|pat| pat =~ file}
+ 	end
+
+	debugMsg "Considering '%s': " % file
+	next unless file =~ /\.tests.rb$/
+	debugMsg "Requiring '%s'..." % file
+	require "#{file}"
+	requires << file
+}
+
+$stderr.puts "Required #{requires.length} files."
+unless patterns.empty?
+	$stderr.puts "[" + requires.sort.join( ", " ) + "]"
+end
+
+class LinkParserTests
+	class << self
+		def suite
+			suite = Test::Unit::TestSuite.new( "Ruby-LinkParser" )
+
+			if suite.respond_to?( :add )
+				ObjectSpace.each_object( Class ) {|klass|
+					suite.add( klass.suite ) if klass < Test::Unit::TestCase
+				}
+			else
+				ObjectSpace.each_object( Class ) {|klass|
+					suite << klass.suite if klass < Test::Unit::TestCase
+				}			
+			end
+
+			return suite
+		end
+	end
+end
+
+# Run tests
+Dir.chdir( $basedir ) do
+	$SAFE = safelevel
+	Test::Unit::UI::Console::TestRunner.new( LinkParserTests ).start
+end
+

tests/linkage.tests.rb

+#!/usr/bin/ruby -w
+#
+# Unit tests for the LinkParser::Linkage class
+# $Id$
+#
+# Copyright (c) 2006 The FaerieMUD Consortium
+# 
+# This work is licensed under the Creative Commons Attribution-ShareAlike
+# License. To view a copy of this license, visit
+# http://creativecommons.org/licenses/by-sa/1.0/ or send a letter to Creative
+# Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
+#
+# 
+
+BEGIN {
+	require 'pathname'
+	basedir = Pathname.new( __FILE__ ).dirname.parent
+	
+	$LOAD_PATH.unshift( basedir + 'ext' ) unless 
+		$LOAD_PATH.include?( basedir + 'ext' )
+}
+
+require 'test/unit'
+require 'linkparser'
+
+class LinkParser::Linkage::TestCase < Test::Unit::TestCase
+
+	def setup
+		@dict = LinkParser::Dictionary.new( :verbosity => 0 )
+		@simple_sentence = @dict.parse( "The flag was wet." )
+		@conjunct_sentence = 
+			@dict.parse( "The ball rolled down the hill and bumped the curb." )
+	end
+
+
+	def test_diagram_should_return_a_diagram_string
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @simple_sentence.linkages.first.diagram
+		end
+		
+		assert_match( /LEFT-WALL/, rval )
+		assert_match( /the/, rval )
+		assert_match( /flag\.n/, rval )
+		assert_match( /was\.v/, rval )
+		assert_match( /wet\.a/, rval )
+
+		assert_match( /-Xp-/, rval )
+		assert_match( /-Wd-/, rval )
+		assert_match( /-Ds-/, rval )
+		assert_match( /-Ss-/, rval )
+		assert_match( /-Pa-/, rval )
+		
+	end
+	
+	
+	def test_links_and_domains_should_return_string_of_links_and_domains
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @simple_sentence.linkages.first.links_and_domains
+		end
+		
+		assert_match( /LEFT-WALL/, rval )
+		assert_match( /the/, rval )
+		assert_match( /flag\.n/, rval )
+		assert_match( /was\.v/, rval )
+		assert_match( /wet\.a/, rval )
+
+		assert_match( /-Xp-/, rval )
+		assert_match( /-Wd-/, rval )
+		assert_match( /-Ds-/, rval )
+		assert_match( /-Ss-/, rval )
+		assert_match( /-Pa-/, rval )
+	end
+	
+	def test_num_sublinkages_should_return_conjunction_count
+		rval = nil
+		
+		assert_nothing_raised do
+			rval = @conjunct_sentence.linkages.first.num_sublinkages
+		end
+		
+		assert_equal 2, rval, "2 conjunctions"
+	end
+	
+	
+end
+

tests/sentence.tests.rb

 class LinkParser::Sentence::TestCase < Test::Unit::TestCase
 
 	def setup
-		$deferr.puts "Creating a sentence test case"
 		@dict = LinkParser::Dictionary.new( :verbosity => 0 )
 		@sentence = LinkParser::Sentence.new( "The cat runs.", @dict )
 	end
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.