Changeset 93
- Timestamp:
- 07/11/08 17:56:49 (7 weeks ago)
- Location:
- branches/rakefile-work
- Files:
-
- 3 modified
- 1 moved
-
Rakefile (modified) (2 diffs)
-
lib/wordnet/lexicon.rb (modified) (3 diffs)
-
spec/wordnet/lexicon_spec.rb (modified) (7 diffs)
-
spec/wordnet/synset_spec.rb (moved) (moved from branches/rakefile-work/spec/wordnet/synset.tests.rb) (2 diffs, 1 prop)
Legend:
- Unmodified
- Added
- Removed
-
branches/rakefile-work/Rakefile
r92 r93 60 60 SPEC_EXCLUDES = 'spec,/Library/Ruby,/var/lib,/usr/local/lib' 61 61 62 COVERAGE_MINIMUM = 83.0 63 64 RELEASE_FILES = FileList[ TEXT_FILES + SPEC_FILES + LIB_FILES + EXT_FILES ] 62 TESTDIR = BASEDIR + 'tests' 63 TEST_FILES = Pathname.glob( TESTDIR + '**/*.tests.rb' ) 64 65 RELEASE_FILES = FileList[ TEXT_FILES + SPEC_FILES + TEST_FILES + LIB_FILES + EXT_FILES ] 65 66 66 67 … … 192 193 ### Cruisecontrol task 193 194 desc "Cruisecontrol build" 194 task :cruise => [:clean, 'coverage:verify', :package] do |task|195 task :cruise => [:clean, :spec, :package] do |task| 195 196 raise "Artifacts dir not set." if ARTIFACTS_DIR.to_s.empty? 196 197 artifact_dir = ARTIFACTS_DIR.cleanpath -
branches/rakefile-work/lib/wordnet/lexicon.rb
r87 r93 161 161 def checkpoint( bytes=0, minutes=0 ) 162 162 @env.checkpoint 163 end164 165 166 ### Return a list of archival logfiles that can be removed167 ### safely. (BerkeleyDB-specific).168 def archlogs169 return @env.log_archive( BDB::ARCH_ABS )170 163 end 171 164 … … 206 199 # that fails, trying morphological conversion. 207 200 entry = @index_db[ wordkey ] 201 208 202 if entry.nil? && (word = self.morph( word, part_of_speech )) 203 wordkey = self.make_word_key( word, part_of_speech ) 209 204 entry = @index_db[ wordkey ] 210 205 end … … 396 391 word = word.gsub( /\s+/, '_' ) 397 392 return "#{word}%#{pos}" 393 end 394 395 396 ### Return a list of archival logfiles that can be removed 397 ### safely. (BerkeleyDB-specific). 398 def archlogs 399 return @env.log_archive( BDB::ARCH_ABS ) 398 400 end 399 401 -
branches/rakefile-work/spec/wordnet/lexicon_spec.rb
r87 r93 63 63 ################################################################# 64 64 65 it " passes a read-only flagset to BDB when createdin :readonly mode" do65 it "defaults to being in :readonly mode" do 66 66 env = stub( "bdb environment handle", :open_db => nil ) 67 67 BDB::Env.should_receive( :new ). … … 69 69 and_return( env ) 70 70 71 WordNet::Lexicon.new( @path.to_s ) 72 end 73 74 it "passes a read/write flagset to BDB when created in :writable mode" do 71 lex = WordNet::Lexicon.new( @path.to_s ) 72 73 lex.should be_readonly() 74 lex.should_not be_readwrite() 75 end 76 77 it "can be created in :writable mode" do 75 78 env = stub( "bdb environment handle", :open_db => nil ) 76 79 BDB::Env.should_receive( :new ). … … 78 81 and_return( env ) 79 82 80 WordNet::Lexicon.new( @path.to_s, :writable ) 83 lex = WordNet::Lexicon.new( @path.to_s, :writable ) 84 85 lex.should_not be_readonly() 86 lex.should be_readwrite() 81 87 end 82 88 … … 87 93 and_return( env ) 88 94 89 WordNet::Lexicon.new( @path.to_s, :readwrite ) 90 end 91 92 93 describe "created in the default configuration" do 95 lex = WordNet::Lexicon.new( @path.to_s, :readwrite ) 96 97 lex.should_not be_readonly() 98 lex.should be_readwrite() 99 end 100 101 102 describe "created in readonly mode" do 103 104 before( :each ) do 105 @env = mock( "bdb environment handle" ) 106 BDB::Env.stub!( :new ).and_return( @env ) 107 @env.stub!( :open_db ) 108 109 @lexicon = WordNet::Lexicon.new( @path.to_s, :readonly ) 110 end 111 112 113 it "doesn't try to remove logs" do 114 @env.should_not_receive( :log_archive ) 115 @lexicon.clean_logs 116 end 117 118 119 end 120 121 122 describe "created in readwrite mode" do 123 124 before( :each ) do 125 @env = mock( "bdb environment handle" ) 126 BDB::Env.stub!( :new ).and_return( @env ) 127 @env.stub!( :open_db ) 128 129 @lexicon = WordNet::Lexicon.new( @path.to_s, :readwrite ) 130 end 131 132 133 it "can be closed" do 134 @env.should_receive( :close ) 135 @lexicon.close 136 end 137 138 it "provides a delegator for the checkpoint method of the underlying database" do 139 @env.should_receive( :checkpoint ) 140 @lexicon.checkpoint 141 end 142 143 it "provides an interface to clean up database transaction logs" do 144 @env.should_receive( :log_archive ).with( BDB::ARCH_ABS ). 145 and_return([ :log1, :log2 ]) 146 File.should_receive( :chmod ).with( 0777, :log1 ) 147 File.should_receive( :delete ).with( :log1 ) 148 File.should_receive( :chmod ).with( 0777, :log2 ) 149 File.should_receive( :delete ).with( :log2 ) 150 151 @lexicon.clean_logs 152 end 153 154 155 end 156 157 158 describe "with a converted WordNet database" do 94 159 95 160 before( :all ) do … … 113 178 114 179 115 it "returns the root word as the morpholog yof a dictionary word it knows about" do180 it "returns the root word as the morphological conversion of a dictionary word it knows about" do 116 181 @lexicon.morph( "angriest", WordNet::Adjective ).should == 'angry' 117 182 end 118 183 119 184 120 it "returns nil as the morpholog yof a dictionary word it doesn't know about" do185 it "returns nil as the morphological conversion of a dictionary word it doesn't know about" do 121 186 @lexicon.morph( "Passomoquoddy", WordNet::Noun ).should be_nil() 122 187 end … … 125 190 it "returns the 'reverse morph' of dictionary words it knows about" do 126 191 @lexicon.reverse_morph( "angry" ).should == 'angriest%a' 192 end 193 194 195 it "tries looking up a failing via its morphological conversion if the original fails" do 196 synsets = @lexicon.lookup_synsets( 'angriest', WordNet::Adjective ) 197 198 synsets.should_not be_nil() 199 synsets.first.should be_an_instance_of( WordNet::Synset ) 200 synsets.first.words.should include( 'angry' ) 201 end 202 203 204 it "returns only the requested sense if a sense is specified" do 205 synset = @lexicon.lookup_synsets( 'run', WordNet::Verb, 4 ) 206 synset.should be_an_instance_of( WordNet::Synset ) 207 synset.words.first.should =~ /operate/i 127 208 end 128 209 … … 161 242 should be_an_instance_of( WordNet::Synset ) 162 243 end 163 164 end 165 166 167 ### Test synset creation via factory method 168 def test_lexicon_create_synset_should_create_a_new_synset 169 synset = nil 170 171 assert_nothing_raised do 172 synset = @lexicon.create_synset( "Ruby", WordNet::Noun ) 173 end 174 assert_instance_of WordNet::Synset, synset 175 end 176 177 178 def test_lexicon_should_be_readonly_if_opened_in_readonly_mode 179 make_testing_directory do |path| 180 lex = WordNet::Lexicon::new( path, :readwrite ).checkpoint 181 lex = nil 182 183 lex = WordNet::Lexicon.new( path, :readonly ) 184 assert_equal true, lex.readonly? 185 assert_equal false, lex.readwrite? 186 end 187 end 188 189 190 def test_lexicon_should_be_readwrite_if_opened_in_readwrite_mode 191 make_testing_directory do |path| 192 lex = WordNet::Lexicon::new( path, :readwrite ) 193 194 assert_equal false, lex.readonly? 195 assert_equal true, lex.readwrite? 196 end 197 end 198 199 200 201 # :TODO: Test store_synset()? 202 244 245 end 203 246 204 247 end -
branches/rakefile-work/spec/wordnet/synset_spec.rb
r87 r93 1 #!/usr/bin/ruby 2 3 require "wntestcase" 4 require "bdb" 5 6 class SynsetTests < WordNet::TestCase 1 #!/usr/bin/env ruby 2 3 BEGIN { 4 require 'pathname' 5 basedir = Pathname.new( __FILE__ ).dirname.parent.parent 6 7 libdir = basedir + 'lib' 8 9 $LOAD_PATH.unshift( libdir ) unless $LOAD_PATH.include?( libdir ) 10 } 11 12 begin 13 require 'fileutils' 14 require 'tmpdir' 15 require 'bdb' 16 require 'spec/runner' 17 require 'spec/lib/helpers' 18 19 require 'wordnet/lexicon' 20 require 'wordnet/synset' 21 rescue LoadError 22 unless Object.const_defined?( :Gem ) 23 require 'rubygems' 24 retry 25 end 26 raise 27 end 28 29 30 ##################################################################### 31 ### C O N T E X T S 32 ##################################################################### 33 34 describe WordNet::Synset do 7 35 8 36 Accessors = [ … … 68 96 69 97 70 ### Make sure the Lexicon's loaded 71 def setup 72 super 73 74 @blankSyn = WordNet::Synset::new( @lexicon, "1%n", WordNet::Noun ) 75 @traversalSyn = @lexicon.lookup_synsets( 'linguistics', :noun, 1 ) 76 end 77 98 before( :each ) do 99 @blank_syn = WordNet::Synset::new( @lexicon, "1%n", WordNet::Noun ) 100 @traversal_syn = @lexicon.lookup_synsets( 'linguistics', :noun, 1 ) 101 end 102 78 103 79 104 #################################################################
