| 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 |
| | 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 |
| 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 |