linkparser 1.0.4 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
1
  #
2
2
  # Rake tasklib for testing tasks
3
- # $Id: testing.rb 99 2009-04-14 13:03:03Z deveiant $
3
+
4
4
  #
5
5
  # Authors:
6
6
  # * Michael Granger <ged@FaerieMUD.org>
@@ -16,7 +16,7 @@ end
16
16
  SPEC_FILES = [] unless defined?( SPEC_FILES )
17
17
  TEST_FILES = [] unless defined?( TEST_FILES )
18
18
 
19
- COMMON_SPEC_OPTS = ['-Du', '-b'] unless defined?( COMMON_SPEC_OPTS )
19
+ COMMON_RSPEC_OPTS = [] unless defined?( COMMON_RSPEC_OPTS )
20
20
 
21
21
  COVERAGE_TARGETDIR = BASEDIR + 'coverage' unless defined?( COVERAGE_TARGETDIR )
22
22
  RCOV_EXCLUDES = 'spec,tests,/Library/Ruby,/var/lib,/usr/local/lib' unless
@@ -29,7 +29,7 @@ task :test do
29
29
  log "Running specs"
30
30
  Rake::Task['spec:quiet'].invoke
31
31
  end
32
-
32
+
33
33
  unless TEST_FILES.empty?
34
34
  log "Running unit tests"
35
35
  Rake::Task[:unittests].invoke
@@ -39,114 +39,55 @@ end
39
39
 
40
40
  ### RSpec specifications
41
41
  begin
42
- gem 'rspec', '>= 1.1.3'
42
+ gem 'rspec', '>= 2.0.0'
43
43
 
44
- require 'spec'
45
- require 'spec/rake/spectask'
44
+ require 'rspec'
45
+ require 'rspec/core/rake_task'
46
46
 
47
47
  ### Task: spec
48
48
  desc "Run specs"
49
49
  task :spec => 'spec:doc'
50
+ task :specs => :spec
50
51
 
51
52
  namespace :spec do
52
53
  desc "Run rspec every time there's a change to one of the files"
53
54
  task :autotest do
54
- require 'autotest/rspec'
55
-
56
- autotester = Autotest::Rspec.new
57
- autotester.run
55
+ require 'autotest'
56
+ Autotest.add_discovery { "rspec2" }
57
+ Autotest.run
58
58
  end
59
59
 
60
60
  desc "Generate regular color 'doc' spec output"
61
- Spec::Rake::SpecTask.new( :doc ) do |task|
62
- task.spec_files = SPEC_FILES
63
- task.spec_opts = COMMON_SPEC_OPTS + ['-f', 's', '-c']
61
+ RSpec::Core::RakeTask.new( :doc ) do |task|
62
+ task.rspec_opts = COMMON_RSPEC_OPTS + ['-f', 'd', '-c']
64
63
  end
65
64
 
66
65
  desc "Generate spec output with profiling"
67
- Spec::Rake::SpecTask.new( :profile ) do |task|
68
- task.spec_files = SPEC_FILES
69
- task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'o']
66
+ RSpec::Core::RakeTask.new( :profile ) do |task|
67
+ task.rspec_opts = COMMON_RSPEC_OPTS + ['-f', 'p', '-p']
70
68
  end
71
69
 
72
70
  desc "Generate quiet non-colored plain-text output"
73
- Spec::Rake::SpecTask.new( :quiet ) do |task|
74
- task.spec_files = SPEC_FILES
75
- task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'p']
71
+ RSpec::Core::RakeTask.new( :quiet ) do |task|
72
+ task.rspec_opts = COMMON_RSPEC_OPTS + ['-f', 'p']
76
73
  end
77
74
 
78
75
  desc "Generate HTML output"
79
- Spec::Rake::SpecTask.new( :html ) do |task|
80
- task.spec_files = SPEC_FILES
81
- task.spec_opts = COMMON_SPEC_OPTS + ['-f', 'h']
76
+ RSpec::Core::RakeTask.new( :html ) do |task|
77
+ task.rspec_opts = COMMON_RSPEC_OPTS + ['-f', 'h']
82
78
  end
83
79
 
84
- end
85
- rescue LoadError => err
86
- task :no_rspec do
87
- $stderr.puts "Specification tasks not defined: %s" % [ err.message ]
88
- end
89
80
 
90
- task :spec => :no_rspec
91
- namespace :spec do
92
- task :autotest => :no_rspec
93
- task :doc => :no_rspec
94
- task :profile => :no_rspec
95
- task :quiet => :no_rspec
96
- task :html => :no_rspec
97
81
  end
98
- end
99
-
100
-
101
- ### Test::Unit tests
102
- begin
103
- require 'rake/testtask'
104
-
105
- Rake::TestTask.new( :unittests ) do |task|
106
- task.libs += [LIBDIR]
107
- task.test_files = TEST_FILES
108
- task.verbose = true
109
- end
110
-
111
- rescue LoadError => err
112
- task :no_test do
113
- $stderr.puts "Test tasks not defined: %s" % [ err.message ]
114
- end
115
-
116
- task :unittests => :no_rspec
117
- end
118
-
119
-
120
- ### RCov (via RSpec) tasks
121
- begin
122
- gem 'rcov'
123
- gem 'rspec', '>= 1.1.3'
124
-
125
- require 'spec'
126
- require 'rcov'
127
82
 
128
83
  ### Task: coverage (via RCov)
129
84
  desc "Build test coverage reports"
130
- unless SPEC_FILES.empty?
131
- Spec::Rake::SpecTask.new( :coverage ) do |task|
132
- task.spec_files = SPEC_FILES
133
- task.libs += [LIBDIR]
134
- task.spec_opts = ['-f', 'p', '-b']
135
- task.rcov_opts = RCOV_OPTS
136
- task.rcov = true
137
- end
85
+ RSpec::Core::RakeTask.new( :coverage ) do |task|
86
+ task.ruby_opts = [ "-I#{LIBDIR}" ]
87
+ task.rspec_opts = ['-f', 'p', '-b']
88
+ task.rcov_opts = RCOV_OPTS
89
+ task.rcov = true
138
90
  end
139
- # unless TEST_FILES.empty?
140
- # require 'rcov/rcovtask'
141
-
142
- # Rcov::RcovTask.new do |task|
143
- # task.libs += [LIBDIR]
144
- # task.test_files = TEST_FILES
145
- # task.verbose = true
146
- # task.rcov_opts = RCOV_OPTS
147
- # end
148
- # end
149
-
150
91
 
151
92
  ### Task: rcov
152
93
  task :rcov => :coverage
@@ -154,50 +95,58 @@ begin
154
95
  ### Other coverage tasks
155
96
  namespace :coverage do
156
97
  desc "Generate a detailed text coverage report"
157
- Spec::Rake::SpecTask.new( :text ) do |task|
158
- task.spec_files = SPEC_FILES
98
+ RSpec::Core::RakeTask.new( :text ) do |task|
159
99
  task.rcov_opts = RCOV_OPTS + ['--text-report']
160
100
  task.rcov = true
161
101
  end
162
102
 
163
103
  desc "Show differences in coverage from last run"
164
- Spec::Rake::SpecTask.new( :diff ) do |task|
165
- task.spec_files = SPEC_FILES
166
- task.spec_opts = ['-f', 'p', '-b']
104
+ RSpec::Core::RakeTask.new( :diff ) do |task|
105
+ task.rspec_opts = ['-f', 'p', '-b']
167
106
  task.rcov_opts = RCOV_OPTS - ['--save'] + ['--text-coverage-diff']
168
107
  task.rcov = true
169
108
  end
170
109
 
171
- ### Task: verify coverage
172
- desc "Build coverage statistics"
173
- VerifyTask.new( :verify => :rcov ) do |task|
174
- task.threshold = COVERAGE_MINIMUM
175
- end
176
-
177
110
  desc "Run RCov in 'spec-only' mode to check coverage from specs"
178
- Spec::Rake::SpecTask.new( :speconly ) do |task|
179
- task.spec_files = SPEC_FILES
111
+ RSpec::Core::RakeTask.new( :speconly ) do |task|
180
112
  task.rcov_opts = ['--exclude', RCOV_EXCLUDES, '--text-report', '--save']
181
113
  task.rcov = true
182
114
  end
183
115
  end
184
116
 
185
117
  CLOBBER.include( COVERAGE_TARGETDIR )
186
-
187
118
  rescue LoadError => err
188
- task :no_rcov do
189
- $stderr.puts "Coverage tasks not defined: RSpec+RCov tasklib not available: %s" %
190
- [ err.message ]
119
+ task :no_rspec do
120
+ $stderr.puts "Specification tasks not defined: %s" % [ err.message ]
191
121
  end
192
122
 
193
- task :coverage => :no_rcov
194
- task :clobber_coverage
195
- task :rcov => :no_rcov
196
- namespace :coverage do
197
- task :text => :no_rcov
198
- task :diff => :no_rcov
123
+ task :spec => :no_rspec
124
+ namespace :spec do
125
+ task :autotest => :no_rspec
126
+ task :doc => :no_rspec
127
+ task :profile => :no_rspec
128
+ task :quiet => :no_rspec
129
+ task :html => :no_rspec
199
130
  end
200
- task :verify => :no_rcov
131
+ end
132
+
133
+
134
+ ### Test::Unit tests
135
+ begin
136
+ require 'rake/testtask'
137
+
138
+ Rake::TestTask.new( :unittests ) do |task|
139
+ task.libs += [LIBDIR]
140
+ task.test_files = TEST_FILES
141
+ task.verbose = true
142
+ end
143
+
144
+ rescue LoadError => err
145
+ task :no_test do
146
+ $stderr.puts "Test tasks not defined: %s" % [ err.message ]
147
+ end
148
+
149
+ task :unittests => :no_rspec
201
150
  end
202
151
 
203
152
 
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby -w
2
2
  #
3
3
  # Specification for various bugfixes to the LinkParser binding
4
- # $Id: bugfixes_spec.rb 48 2008-12-19 18:30:33Z deveiant $
4
+ # $Id: bugfixes_spec.rb,v 6c597e731a87 2010/11/22 15:59:36 ged $
5
5
  #
6
6
  # See the LICENSE file in the distribution for information about copyright and licensing.
7
7
  #
@@ -9,27 +9,33 @@
9
9
  BEGIN {
10
10
  require 'pathname'
11
11
  basedir = Pathname.new( __FILE__ ).dirname.parent
12
-
12
+
13
13
  libdir = basedir + 'lib'
14
14
  extdir = basedir + 'ext'
15
-
15
+
16
+ $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
16
17
  $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
17
18
  $LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
18
19
  }
19
20
 
20
- require 'spec/runner'
21
+ require 'rspec'
22
+
21
23
  require 'linkparser'
22
24
 
23
25
  # @dict = LinkParser::Dictionary.new( :verbosity => 0 )
24
26
  # s = LinkParser::Sentence.new('The cat runs.',@dict)
25
27
  # puts s.linkages.first.verb # "cat.n" !?!?!
26
28
  describe %{bugfix for #3: The first linkage for "The cat runs."} do
29
+ before( :all ) do
30
+ $DEBUG = true if ENV['DEBUG']
31
+ end
32
+
27
33
  before( :each ) do
28
- @dict = LinkParser::Dictionary.new( :verbosity => 0 )
34
+ @dict = LinkParser::Dictionary.new( 'en', :verbosity => 0 )
29
35
  @sentence = @dict.parse( "The cat runs." )
30
36
  @linkage = @sentence.linkages.first
31
37
  end
32
-
38
+
33
39
 
34
40
  it "thinks cat is the subject" do
35
41
  @linkage.subject.should == "cat"
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby -w
2
2
  #
3
3
  # Specification for the LinkParser::Dictionary class
4
- # $Id: dictionary_spec.rb 48 2008-12-19 18:30:33Z deveiant $
4
+ # $Id: dictionary_spec.rb,v a5e7d9e3cf5c 2010/11/25 00:50:55 ged $
5
5
  #
6
6
  # See the LICENSE file in the distribution for information about copyright and licensing.
7
7
  #
@@ -9,21 +9,36 @@
9
9
  BEGIN {
10
10
  require 'pathname'
11
11
  basedir = Pathname.new( __FILE__ ).dirname.parent.parent
12
-
12
+
13
13
  libdir = basedir + 'lib'
14
14
  extdir = basedir + 'ext'
15
-
15
+
16
+ $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
16
17
  $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
17
18
  $LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
18
19
  }
19
20
 
20
- require 'spec/runner'
21
+ require 'rspec'
22
+
21
23
  require 'linkparser'
22
24
 
23
25
 
24
26
  describe LinkParser::Dictionary do
27
+
28
+ ### Work around current system's locale
29
+ before( :all ) do
30
+ $LANG = ENV['LANG']
31
+ ENV['LANG'] = 'en_US.UTF-8'
32
+ $DEBUG = true if ENV['DEBUG']
33
+ end
34
+
35
+ after( :all ) do
36
+ ENV['LANG'] = $LANG
37
+ end
38
+
39
+
25
40
  it "can be instantiated using all default values" do
26
- lambda { LinkParser::Dictionary.new }.should_not raise_error()
41
+ LinkParser::Dictionary.new.should be_an_instance_of( LinkParser::Dictionary )
27
42
  end
28
43
 
29
44
  it "can be instantiated with an options hash" do
@@ -56,35 +71,36 @@ describe LinkParser::Dictionary do
56
71
  }.should raise_error( LinkParser::Error )
57
72
  end
58
73
 
59
- end
74
+ context "instance" do
60
75
 
61
- describe "An instance of LinkParser::Dictionary" do
76
+ TEST_SENTENCE = "The dog plays with the ball."
62
77
 
63
- TEST_SENTENCE = "The dog plays with the ball."
78
+ before( :each ) do
79
+ @dict = LinkParser::Dictionary.new(
80
+ :verbosity => 0,
81
+ :max_null_count => 18,
82
+ :echo_on => true
83
+ )
84
+ end
64
85
 
65
- before( :each ) do
66
- @dict = LinkParser::Dictionary.new(
67
- :verbosity => 0,
68
- :max_null_count => 18,
69
- :echo_on => true
70
- )
71
- end
72
-
73
86
 
74
- it "knows what the total cost of its linkages are" do
75
- @dict.max_cost.should be_an_instance_of(Fixnum)
76
- end
87
+ it "knows what the total cost of its linkages are" do
88
+ @dict.max_cost.should be_an_instance_of(Fixnum)
89
+ end
77
90
 
78
- it "can parse a sentence" do
79
- @dict.parse( TEST_SENTENCE ).
80
- should be_an_instance_of( LinkParser::Sentence )
81
- end
82
-
83
- it "passes on its options to the sentences it parses" do
84
- sentence = @dict.parse( TEST_SENTENCE )
85
- sentence.options.max_null_count.should == 18
86
- sentence.options.verbosity.should == 0
87
- sentence.options.echo_on?.should == true
91
+ it "can parse a sentence" do
92
+ @dict.parse( TEST_SENTENCE ).
93
+ should be_an_instance_of( LinkParser::Sentence )
94
+ end
95
+
96
+ it "passes on its options to the sentences it parses" do
97
+ sentence = @dict.parse( TEST_SENTENCE )
98
+ sentence.options.max_null_count.should == 18
99
+ sentence.options.verbosity.should == 0
100
+ sentence.options.echo_on?.should == true
101
+ end
88
102
  end
103
+
89
104
  end
90
105
 
106
+
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/ruby -w
2
2
  #
3
3
  # Specification for the LinkParser::Linkage class
4
- # $Id: linkage_spec.rb 48 2008-12-19 18:30:33Z deveiant $
4
+ # $Id: linkage_spec.rb,v a5e7d9e3cf5c 2010/11/25 00:50:55 ged $
5
5
  #
6
6
  # See the LICENSE file in the distribution for information about copyright and licensing.
7
7
  #
@@ -9,29 +9,32 @@
9
9
  BEGIN {
10
10
  require 'pathname'
11
11
  basedir = Pathname.new( __FILE__ ).dirname.parent.parent
12
-
12
+
13
13
  libdir = basedir + 'lib'
14
14
  extdir = basedir + 'ext'
15
-
15
+
16
+ $LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
16
17
  $LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
17
18
  $LOAD_PATH.unshift( extdir.to_s ) unless $LOAD_PATH.include?( extdir.to_s )
18
19
  }
19
20
 
20
- require 'spec/runner'
21
+ require 'rspec'
22
+
21
23
  require 'linkparser'
22
24
 
23
25
 
24
26
  describe LinkParser::Linkage do
25
27
 
26
28
  before( :all ) do
27
- @dict = LinkParser::Dictionary.new( :verbosity => 0 )
29
+ @dict = LinkParser::Dictionary.new( 'en', :verbosity => 0 )
30
+ $DEBUG = true if ENV['DEBUG']
28
31
  end
29
32
 
30
33
  before( :each ) do
31
34
  @sentence = @dict.parse( "The flag was wet." )
32
35
  @linkage = @sentence.linkages.first
33
36
  end
34
-
37
+
35
38
 
36
39
  # +-------------Xp-------------+
37
40
  # +-----Wd-----+ |
@@ -44,14 +47,14 @@ describe LinkParser::Linkage do
44
47
  @linkage.diagram.should =~ /flag\.n/
45
48
  @linkage.diagram.should =~ /was\.v/
46
49
  @linkage.diagram.should =~ /wet\.a/
47
-
50
+
48
51
  @linkage.diagram.should =~ /-Xp-/
49
52
  @linkage.diagram.should =~ /-Wd-/
50
53
  @linkage.diagram.should =~ /-Ds-/
51
54
  @linkage.diagram.should =~ /-Ss-/
52
55
  @linkage.diagram.should =~ /-Pa-/
53
56
  end
54
-
57
+
55
58
 
56
59
  # LEFT-WALL Xp <---Xp----> Xp .
57
60
  # (m) LEFT-WALL Wd <---Wd----> Wd flag.n
@@ -84,13 +87,13 @@ describe LinkParser::Linkage do
84
87
  @linkage.words.should include("LEFT-WALL")
85
88
  @linkage.words.should include("the")
86
89
  @linkage.words.should include("flag.n")
87
- @linkage.words.should include("was.v")
90
+ @linkage.words.should include("was.v-d")
88
91
  @linkage.words.should include("wet.a")
89
92
  @linkage.words.should include(".")
90
93
  @linkage.words.should include("RIGHT-WALL")
91
94
  end
92
-
93
-
95
+
96
+
94
97
  it "knows how many links are in the sentence" do
95
98
  @linkage.num_links.should == 6
96
99
  end
@@ -110,13 +113,13 @@ describe LinkParser::Linkage do
110
113
  @linkage.link_lword( 3 ).should == @linkage.words.index('flag.n')
111
114
 
112
115
  # (m) was.v Pa <---Pa----> Pa wet.a
113
- @linkage.link_lword( 4 ).should == @linkage.words.index('was.v')
116
+ @linkage.link_lword( 4 ).should == @linkage.words.index('was.v-d')
114
117
 
115
118
  # . RW <---RW----> RW RIGHT-WALL
116
119
  @linkage.link_lword( 5 ).should == @linkage.words.index('.')
117
120
 
118
121
  end
119
-
122
+
120
123
  it "can return the right word for any of its links" do
121
124
  # LEFT-WALL Xp <---Xp----> Xp .
122
125
  @linkage.link_rword( 0 ).should == @linkage.words.index('.')
@@ -128,7 +131,7 @@ describe LinkParser::Linkage do
128
131
  @linkage.link_rword( 2 ).should == @linkage.words.index('flag.n')
129
132
 
130
133
  # (m) flag.n Ss <---Ss----> Ss was.v
131
- @linkage.link_rword( 3 ).should == @linkage.words.index('was.v')
134
+ @linkage.link_rword( 3 ).should == @linkage.words.index('was.v-d')
132
135
 
133
136
  # (m) was.v Pa <---Pa----> Pa wet.a
134
137
  @linkage.link_rword( 4 ).should == @linkage.words.index('wet.a')
@@ -150,8 +153,8 @@ describe LinkParser::Linkage do
150
153
  # Out-of-bounds just returns -1
151
154
  @linkage.link_length( 7 ).should == -1
152
155
  end
153
-
154
-
156
+
157
+
155
158
  it "can return labels for any of its links" do
156
159
  @linkage.link_label( 0 ).should == "Xp"
157
160
  @linkage.link_label( 1 ).should == "Wd"
@@ -162,7 +165,7 @@ describe LinkParser::Linkage do
162
165
 
163
166
  @linkage.link_label( 7 ).should be_nil
164
167
  end
165
-
168
+
166
169
 
167
170
  it "can return left labels for any of its links" do
168
171
  @linkage.link_llabel( 0 ).should == "Xp"
@@ -174,7 +177,7 @@ describe LinkParser::Linkage do
174
177
 
175
178
  @linkage.link_llabel( 7 ).should be_nil
176
179
  end
177
-
180
+
178
181
 
179
182
  it "can return labels for any of its links" do
180
183
  @linkage.link_rlabel( 0 ).should == "Xp"
@@ -186,8 +189,8 @@ describe LinkParser::Linkage do
186
189
 
187
190
  @linkage.link_rlabel( 7 ).should be_nil
188
191
  end
189
-
190
-
192
+
193
+
191
194
  it "can return the number of domains for any link" do
192
195
  @linkage.link_num_domains( 0 ).should == 0
193
196
  1.upto(4) do |i|
@@ -197,25 +200,35 @@ describe LinkParser::Linkage do
197
200
 
198
201
  @linkage.link_num_domains( 112 ).should == -1
199
202
  end
200
-
201
-
203
+
204
+
202
205
  it "can return the names of the domains of any of its links" do
203
206
  @linkage.link_domain_names( 0 ).should be_an_instance_of( Array )
204
207
  @linkage.link_domain_names( 0 ).should be_empty
205
-
208
+
206
209
  1.upto(4) do |i|
207
210
  @linkage.link_domain_names( i ).should be_an_instance_of( Array )
208
211
  @linkage.link_domain_names( i ).should == ["m"]
209
212
  end
210
-
213
+
211
214
  @linkage.link_domain_names( 5 ).should be_an_instance_of( Array )
212
215
  @linkage.link_domain_names( 5 ).should be_empty
213
-
216
+
214
217
  @linkage.link_domain_names( 12 ).should be_an_instance_of( Array )
215
218
  @linkage.link_domain_names( 12 ).should be_empty
216
219
  end
217
220
 
218
-
221
+
222
+ it "can return the disjunct strings for any of its words" do
223
+ @linkage.disjunct_strings.should have( @linkage.num_words ).members
224
+ end
225
+
226
+
227
+ it "can return parsed disjuncts for any of its words" do
228
+ @linkage.disjuncts.should have( @linkage.num_words ).members
229
+ end
230
+
231
+
219
232
  it "can report on the various cost metrics of the parse" do
220
233
  @linkage.unused_word_cost.should be_an_instance_of( Fixnum )
221
234
  @linkage.disjunct_cost.should be_an_instance_of( Fixnum )
@@ -244,7 +257,7 @@ describe LinkParser::Linkage do
244
257
  it "contains link structs describing the linkage" do
245
258
  @linkage.should have(6).links
246
259
  @linkage.links.should be_an_instance_of( Array )
247
-
260
+
248
261
  @linkage.links.each do |link|
249
262
  link.should be_a_kind_of( Struct )
250
263
  end
@@ -254,7 +267,7 @@ describe LinkParser::Linkage do
254
267
  @linkage.links.last.rword.should == 'RIGHT-WALL'
255
268
  @linkage.links.last.label.should == 'RW'
256
269
  @linkage.links[3].lword.should == 'flag.n'
257
- @linkage.links[3].rword.should == 'was.v'
270
+ @linkage.links[3].rword.should == 'was.v-d'
258
271
  @linkage.links[3].label.should == 'Ss'
259
272
  end
260
273
 
@@ -267,7 +280,13 @@ describe LinkParser::Linkage do
267
280
  it "knows when the sentence doesn't have a direct object" do
268
281
  @linkage.object.should be_nil()
269
282
  end
270
-
283
+
284
+
285
+ it "knows which of its words are nouns" do
286
+ @linkage.nouns.should have(1).member
287
+ @linkage.nouns.should include( "flag" )
288
+ end
289
+
271
290
 
272
291
  MODE1_C_TREE_STRING = "(S (NP The flag)\n (VP was\n (ADJP wet))\n .)\n"
273
292
  MODE2_C_TREE_STRING = "[S [NP The flag NP] [VP was [ADJP wet ADJP] VP] . S] \n"
@@ -276,27 +295,27 @@ describe LinkParser::Linkage do
276
295
  it "returns an indented sexps for the constituent tree string by default (mode 1)" do
277
296
  @linkage.constituent_tree_string.should == MODE1_C_TREE_STRING
278
297
  end
279
-
298
+
280
299
 
281
300
  it "returns indented sexps for the constituent tree string if fetched with explicit mode '1'" do
282
301
  @linkage.constituent_tree_string( 1 ).should == MODE1_C_TREE_STRING
283
302
  end
284
-
303
+
285
304
  it "returns bracketed constituents if constituent tree string is fetched in mode 2" do
286
305
  @linkage.constituent_tree_string( 2 ).should == MODE2_C_TREE_STRING
287
306
  end
288
-
307
+
289
308
  it "returns unindented sexps for the constituent tree string if constituent tree string " +
290
309
  "is fetched in mode 3" do
291
310
  @linkage.constituent_tree_string( 3 ).should == MODE3_C_TREE_STRING
292
311
  end
293
-
312
+
294
313
  it "raises an exception for any numeric constituent tree string mode greater than 3" do
295
314
  lambda {
296
315
  @linkage.constituent_tree_string( 4 )
297
316
  }.should raise_error( ArgumentError, /illegal mode 4/i )
298
317
  end
299
-
318
+
300
319
  it "raises an exception for any numeric constituent tree string mode less than 1" do
301
320
  lambda {
302
321
  @linkage.constituent_tree_string( 0 )
@@ -309,10 +328,10 @@ describe LinkParser::Linkage do
309
328
  @linkage.constituent_tree_string( 'glarg' )
310
329
  }.should raise_error( TypeError )
311
330
  end
312
-
331
+
313
332
  it "returns an Array of CTree structs for its constituent tree" do
314
333
  rval = @linkage.constituent_tree
315
-
334
+
316
335
  rval.should be_an_instance_of( Array )
317
336
  rval.should have(1).members
318
337
  rval.first.should be_a_kind_of( Struct )
@@ -320,93 +339,70 @@ describe LinkParser::Linkage do
320
339
  rval.first.children.should have(3).members
321
340
  rval.first.children.collect {|n| n.label }.should include( 'NP', 'VP', '.' )
322
341
  end
323
-
324
- it "returns 0 as the number of the current sublinkage since it has no conjunctions" do
325
- @linkage.current_sublinkage.should == 0
326
- end
327
-
328
342
 
329
343
  it "returns an informational string when inspected" do
330
- @linkage.inspect.should =~ /Linkage:0x[[:xdigit:]]+: sublinkage 0: \[\d+ links\]/
344
+ @linkage.inspect.should =~ /Linkage:0x[[:xdigit:]]+: \[\d+ links\]/
331
345
  end
332
-
333
-
334
- describe "from a simple sentence with a direct object" do
346
+
347
+
348
+ context "from a simple sentence with a direct object" do
335
349
  before( :each ) do
336
350
  @sentence = @dict.parse( "The dog ran home." )
337
351
  @linkage = @sentence.linkages.first
338
352
  end
339
353
 
340
354
 
341
- it "doesn't have any sublinkages" do
342
- @linkage.num_sublinkages.should == 1
343
- end
344
-
345
- it "doesn't change after computing its union" do
346
- lambda {
347
- @linkage.compute_union
348
- }.should_not change( @linkage, :num_sublinkages )
349
- end
350
-
351
-
352
355
  it "knows what word is the object in the sentence" do
353
- @linkage.object.should == 'home'
356
+ # This depends on the linkage:
357
+ # +---------------Xp---------------+
358
+ # +-----Wd----+ |
359
+ # | +-Ds-+--Ss--+---Ou---+ |
360
+ # | | | | | |
361
+ # LEFT-WALL the dog.n ran.v-d home.n-u .
362
+ # ...but it might not be the first one, so check them all.
363
+ @sentence.linkages.find {|linkage| linkage.object == 'home' }
364
+
354
365
  end
355
-
366
+
356
367
  end
357
368
 
358
369
 
359
- it "knows that it doesn't have any conjunctions" do
360
- @linkage.should_not have_conjunction()
361
- end
362
-
370
+ context "deprecated sublinkage API" do
363
371
 
364
- describe "from a sentence with a conjunction" do
365
372
  before( :each ) do
366
- @sentence =
367
- @dict.parse( "The ball rolled down the hill and bumped the curb." )
373
+ @sentence = @dict.parse( "The ball rolled down the hill and bumped the curb." )
368
374
  @linkage = @sentence.linkages.first
369
375
  end
370
376
 
371
-
372
- it "knows that it has a conjunction" do
373
- @linkage.should have_conjunction()
377
+ it "warns about deprecation if #num_sublinkages is called" do
378
+ @linkage.should_receive( :warn ).with( /deprecated/i )
379
+ @linkage.num_sublinkages
374
380
  end
375
-
376
- it "has two sublinkages" do
377
- @linkage.num_sublinkages.should == 2
378
- end
379
-
380
381
 
381
- it "adds a sublinkage after computing its union" do
382
- lambda {
383
- @linkage.compute_union
384
- }.should change( @linkage, :num_sublinkages ).from(2).to(3)
382
+ it "warns about deprecation if #compute_union is called" do
383
+ @linkage.should_receive( :warn ).with( /deprecated/i )
384
+ @linkage.compute_union
385
385
  end
386
386
 
387
-
388
- it "knows what word is the verb in the current sublinkage" do
389
- @linkage.verb.should == 'rolled'
387
+ it "warn about deprecation if #current_sublinkage= is called" do
388
+ @linkage.should_receive( :warn ).with( /deprecated/i )
390
389
  @linkage.current_sublinkage = 1
391
- @linkage.verb.should == 'bumped'
392
390
  end
393
-
394
391
 
395
- it "knows what word is the object in the current sublinkage" do
396
- @linkage.object.should == 'hill'
397
- @linkage.current_sublinkage = 1
398
- @linkage.object.should == 'curb'
392
+ it "warn about deprecation if #current_sublinkage is called" do
393
+ @linkage.should_receive( :warn ).with( /deprecated/i )
394
+ @linkage.current_sublinkage
399
395
  end
400
-
396
+
401
397
  end
402
398
 
403
399
 
404
400
  it "should know that it's not an imperative sentence" do
405
401
  @linkage.imperative?.should be_false()
406
402
  end
407
-
408
403
 
409
- describe "from an imperative sentence" do
404
+
405
+ context "from an imperative sentence" do
410
406
  before( :each ) do
411
407
  @sentence = @dict.parse( "Go to the store!" )
412
408
  @linkage = @sentence.linkages.first
@@ -416,19 +412,19 @@ describe LinkParser::Linkage do
416
412
  it "knows that it's an imperative sentence" do
417
413
  @linkage.imperative?.should be_true()
418
414
  end
419
-
420
-
415
+
416
+
421
417
  end
422
418
 
423
419
 
424
- describe "bugfixes" do
425
-
420
+ context "bugfixes" do
421
+
426
422
  it "also strips off the '.p' from the subject and object when they are plural" do
427
423
  sent = @dict.parse( 'People like goats.' )
428
424
  sent.subject.should_not =~ /people\.p/i
429
425
  sent.object.should_not =~ /goats\.p/i
430
426
  end
431
-
427
+
432
428
  end
433
429
 
434
430
  end