wordnet 0.0.5 → 1.0.0.pre.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gemtest +0 -0
- data/History.rdoc +5 -0
- data/LICENSE +9 -9
- data/Manifest.txt +39 -0
- data/README.rdoc +60 -0
- data/Rakefile +47 -267
- data/TODO +9 -0
- data/WordNet30-license.txt +31 -0
- data/examples/add-laced-boots.rb +35 -0
- data/examples/clothes-with-collars.rb +42 -0
- data/examples/clothesWithTongues.rb +0 -0
- data/examples/domainTree.rb +0 -0
- data/examples/memberTree.rb +0 -0
- data/lib/wordnet/constants.rb +259 -296
- data/lib/wordnet/lexicallink.rb +34 -0
- data/lib/wordnet/lexicon.rb +158 -386
- data/lib/wordnet/mixins.rb +62 -0
- data/lib/wordnet/model.rb +78 -0
- data/lib/wordnet/morph.rb +25 -0
- data/lib/wordnet/semanticlink.rb +52 -0
- data/lib/wordnet/sense.rb +55 -0
- data/lib/wordnet/sumoterm.rb +21 -0
- data/lib/wordnet/synset.rb +404 -859
- data/lib/wordnet/utils.rb +126 -0
- data/lib/wordnet/word.rb +119 -0
- data/lib/wordnet.rb +113 -76
- data/spec/lib/helpers.rb +102 -133
- data/spec/linguawordnet.tests.rb +38 -0
- data/spec/wordnet/lexicon_spec.rb +96 -186
- data/spec/wordnet/model_spec.rb +59 -0
- data/spec/wordnet/semanticlink_spec.rb +42 -0
- data/spec/wordnet/synset_spec.rb +27 -256
- data/spec/wordnet/word_spec.rb +58 -0
- data/spec/wordnet_spec.rb +52 -0
- data.tar.gz.sig +0 -0
- metadata +227 -188
- metadata.gz.sig +0 -0
- data/ChangeLog +0 -720
- data/README +0 -93
- data/Rakefile.local +0 -46
- data/convertdb.rb +0 -417
- data/examples/addLacedBoots.rb +0 -27
- data/examples/clothesWithCollars.rb +0 -36
- data/rake/dependencies.rb +0 -76
- data/rake/helpers.rb +0 -384
- data/rake/manual.rb +0 -755
- data/rake/packaging.rb +0 -112
- data/rake/publishing.rb +0 -303
- data/rake/rdoc.rb +0 -35
- data/rake/style.rb +0 -62
- data/rake/svn.rb +0 -469
- data/rake/testing.rb +0 -192
- data/rake/verifytask.rb +0 -64
- data/utils.rb +0 -838
@@ -0,0 +1,38 @@
|
|
1
|
+
#!/usr/bin/ruby
|
2
|
+
|
3
|
+
require "wntestcase"
|
4
|
+
|
5
|
+
class LexiconTests < WordNet::TestCase
|
6
|
+
|
7
|
+
OldBaseballOffset = '00466621%n'
|
8
|
+
BaseballOffset = '00471613%n'
|
9
|
+
|
10
|
+
def test_perl_tests
|
11
|
+
synset = nil
|
12
|
+
synset2 = nil
|
13
|
+
|
14
|
+
begin
|
15
|
+
synset = @lexicon.lookup_synsets_by_key( BaseballOffset )
|
16
|
+
rescue WordNet::LookupError
|
17
|
+
synset = @lexicon.lookup_synsets_by_key( OldBaseballOffset )
|
18
|
+
end
|
19
|
+
|
20
|
+
assert_instance_of WordNet::Synset, synset
|
21
|
+
|
22
|
+
words = ''
|
23
|
+
synset.hyponyms.each do |bb_synset|
|
24
|
+
bb_synset.words += ["ballser"]
|
25
|
+
bb_synset.words.each {|word| words += "#{word}, "}
|
26
|
+
end
|
27
|
+
assert_match( /hardball/, words )
|
28
|
+
|
29
|
+
words = ''
|
30
|
+
synset2 = @lexicon.lookup_synsets( "travel", WordNet::Verb, 2 )
|
31
|
+
synset2.words.each {|word| words += "#{word}, "}
|
32
|
+
assert_match( /journey/, words )
|
33
|
+
|
34
|
+
assert_equal 4, @lexicon.familiarity( "boy", WordNet::Noun )
|
35
|
+
assert_equal "blue", @lexicon.morph( "bluest", WordNet::Adjective )
|
36
|
+
assert_match( /baseball/, "#{synset}" )
|
37
|
+
end
|
38
|
+
end
|
@@ -6,25 +6,15 @@ BEGIN {
|
|
6
6
|
|
7
7
|
libdir = basedir + 'lib'
|
8
8
|
|
9
|
-
$LOAD_PATH.unshift(
|
9
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
10
11
|
}
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
require 'tmpdir'
|
15
|
-
require 'bdb'
|
16
|
-
require 'spec/runner'
|
17
|
-
require 'spec/lib/helpers'
|
18
|
-
|
19
|
-
require 'wordnet/lexicon'
|
20
|
-
rescue LoadError
|
21
|
-
unless Object.const_defined?( :Gem )
|
22
|
-
require 'rubygems'
|
23
|
-
retry
|
24
|
-
end
|
25
|
-
raise
|
26
|
-
end
|
13
|
+
require 'rspec'
|
14
|
+
require 'sequel'
|
27
15
|
|
16
|
+
require 'spec/lib/helpers'
|
17
|
+
require 'wordnet'
|
28
18
|
|
29
19
|
|
30
20
|
#####################################################################
|
@@ -32,216 +22,136 @@ end
|
|
32
22
|
#####################################################################
|
33
23
|
|
34
24
|
describe WordNet::Lexicon do
|
35
|
-
include WordNet::SpecHelpers
|
36
|
-
|
37
|
-
TEST_WORDS = {
|
38
|
-
'activity' => WordNet::Noun,
|
39
|
-
'sword' => WordNet::Noun,
|
40
|
-
'density' => WordNet::Noun,
|
41
|
-
'burly' => WordNet::Adjective,
|
42
|
-
'wispy' => WordNet::Adjective,
|
43
|
-
'traditional' => WordNet::Adjective,
|
44
|
-
'sit' => WordNet::Verb,
|
45
|
-
'take' => WordNet::Verb,
|
46
|
-
'joust' => WordNet::Verb,
|
47
|
-
}
|
48
|
-
|
49
|
-
|
50
|
-
before( :each ) do
|
51
|
-
@path = make_tempdir()
|
52
|
-
end
|
53
25
|
|
54
|
-
|
55
|
-
|
56
|
-
|
26
|
+
before( :all ) do
|
27
|
+
setup_logging( :fatal )
|
28
|
+
@devdb = Pathname( 'wordnet-defaultdb/data/wordnet-defaultdb/wordnet30.sqlite' ).
|
29
|
+
expand_path
|
57
30
|
end
|
58
31
|
|
59
|
-
|
60
|
-
|
61
|
-
#################################################################
|
62
|
-
### T E S T S
|
63
|
-
#################################################################
|
64
|
-
|
65
|
-
it "defaults to being in :readonly mode" do
|
66
|
-
env = stub( "bdb environment handle", :open_db => nil )
|
67
|
-
BDB::Env.should_receive( :new ).
|
68
|
-
with( @path.to_s, WordNet::Lexicon::ENV_FLAGS_RO, WordNet::Lexicon::ENV_OPTIONS ).
|
69
|
-
and_return( env )
|
70
|
-
|
71
|
-
lex = WordNet::Lexicon.new( @path.to_s )
|
72
|
-
|
73
|
-
lex.should be_readonly()
|
74
|
-
lex.should_not be_readwrite()
|
32
|
+
after( :all ) do
|
33
|
+
reset_logging()
|
75
34
|
end
|
76
|
-
|
77
|
-
it "can be created in :writable mode" do
|
78
|
-
env = stub( "bdb environment handle", :open_db => nil )
|
79
|
-
BDB::Env.should_receive( :new ).
|
80
|
-
with( @path.to_s, WordNet::Lexicon::ENV_FLAGS_RW, WordNet::Lexicon::ENV_OPTIONS ).
|
81
|
-
and_return( env )
|
82
35
|
|
83
|
-
|
36
|
+
context "the default_db_uri method" do
|
84
37
|
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
env = stub( "bdb environment handle", :open_db => nil )
|
91
|
-
BDB::Env.should_receive( :new ).
|
92
|
-
with( @path.to_s, WordNet::Lexicon::ENV_FLAGS_RW, WordNet::Lexicon::ENV_OPTIONS ).
|
93
|
-
and_return( env )
|
38
|
+
it "uses the wordnet-defaultdb database gem (if available)" do
|
39
|
+
Gem.should_receive( :datadir ).with( 'wordnet-defaultdb' ).at_least( :once ).
|
40
|
+
and_return( '/tmp/foo' )
|
41
|
+
FileTest.should_receive( :exist? ).with( '/tmp/foo/wordnet30.sqlite' ).
|
42
|
+
and_return( true )
|
94
43
|
|
95
|
-
|
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 )
|
44
|
+
WordNet::Lexicon.default_db_uri.should == "sqlite:/tmp/foo/wordnet30.sqlite"
|
110
45
|
end
|
111
46
|
|
47
|
+
it "uses the development version of the wordnet-defaultdb database gem if it's " +
|
48
|
+
"not installed" do
|
49
|
+
Gem.should_receive( :datadir ).with( 'wordnet-defaultdb' ).
|
50
|
+
and_return( nil )
|
51
|
+
FileTest.should_receive( :exist? ).with( @devdb.to_s ).
|
52
|
+
and_return( true )
|
112
53
|
|
113
|
-
|
114
|
-
@env.should_not_receive( :log_archive )
|
115
|
-
@lexicon.clean_logs
|
54
|
+
WordNet::Lexicon.default_db_uri.should == "sqlite:#{@devdb}"
|
116
55
|
end
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
56
|
|
57
|
+
it "returns nil if there is no default database" do
|
58
|
+
Gem.should_receive( :datadir ).with( 'wordnet-defaultdb' ).
|
59
|
+
and_return( nil )
|
60
|
+
FileTest.should_receive( :exist? ).with( @devdb.to_s ).
|
61
|
+
and_return( false )
|
121
62
|
|
122
|
-
|
63
|
+
WordNet::Lexicon.default_db_uri.should be_nil()
|
64
|
+
end
|
123
65
|
|
124
|
-
|
125
|
-
@env = mock( "bdb environment handle" )
|
126
|
-
BDB::Env.stub!( :new ).and_return( @env )
|
127
|
-
@env.stub!( :open_db )
|
66
|
+
end
|
128
67
|
|
129
|
-
@lexicon = WordNet::Lexicon.new( @path.to_s, :readwrite )
|
130
|
-
end
|
131
|
-
|
132
68
|
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
69
|
+
it "raises an exception if created with no arguments and no defaultdb is available" do
|
70
|
+
Gem.should_receive( :datadir ).with( 'wordnet-defaultdb' ).at_least( :once ).
|
71
|
+
and_return( nil )
|
72
|
+
FileTest.should_receive( :exist? ).with( @devdb.to_s ).
|
73
|
+
and_return( false )
|
137
74
|
|
138
|
-
|
139
|
-
|
140
|
-
|
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
|
-
|
75
|
+
expect {
|
76
|
+
WordNet::Lexicon.new
|
77
|
+
}.to raise_error( WordNet::LexiconError, /no default wordnetsql/i )
|
155
78
|
end
|
156
|
-
|
157
79
|
|
158
|
-
|
80
|
+
|
81
|
+
context "with the default database", :requires_database => true do
|
159
82
|
|
160
83
|
before( :all ) do
|
161
|
-
@
|
162
|
-
@datadir = @basedir + 'ruby-wordnet'
|
84
|
+
@lexicon = WordNet::Lexicon.new
|
163
85
|
end
|
164
86
|
|
165
|
-
|
166
|
-
pending "you haven't converted the WordNet datafiles yet -- try 'rake convert'" unless
|
167
|
-
@datadir.directory?
|
168
|
-
|
169
|
-
@lexicon = WordNet::Lexicon.new( @datadir.to_s )
|
170
|
-
end
|
87
|
+
context "via its index operator" do
|
171
88
|
|
89
|
+
it "can look up a Synset by ID" do
|
90
|
+
rval = @lexicon[ 101219722 ]
|
91
|
+
rval.should be_a( WordNet::Synset )
|
92
|
+
rval.words.map( &:to_s ).should include( 'carrot' )
|
93
|
+
end
|
172
94
|
|
173
|
-
|
174
|
-
|
175
|
-
|
95
|
+
it "can look up a Word by ID" do
|
96
|
+
rval = @lexicon[ 21338 ]
|
97
|
+
rval.should be_a( WordNet::Word )
|
98
|
+
rval.lemma.should == 'carrot'
|
176
99
|
end
|
177
|
-
end
|
178
|
-
|
179
|
-
|
180
|
-
it "returns the root word as the morphological conversion of a dictionary word it knows about" do
|
181
|
-
@lexicon.morph( "angriest", WordNet::Adjective ).should == 'angry'
|
182
|
-
end
|
183
100
|
|
101
|
+
it "can look up the synset for a word and a sense" do
|
102
|
+
ss = @lexicon[ :boot, 3 ]
|
103
|
+
ss.should be_a( WordNet::Synset )
|
104
|
+
ss.definition.should == 'footwear that covers the whole foot and lower leg'
|
105
|
+
end
|
184
106
|
|
185
|
-
it "returns nil as the morphological conversion of a dictionary word it doesn't know about" do
|
186
|
-
@lexicon.morph( "Passomoquoddy", WordNet::Noun ).should be_nil()
|
187
107
|
end
|
188
108
|
|
109
|
+
end
|
110
|
+
|
111
|
+
context "with a PostgreSQL database", :requires_pg do
|
189
112
|
|
190
|
-
|
191
|
-
@lexicon
|
113
|
+
before( :all ) do
|
114
|
+
@lexicon = WordNet::Lexicon.new( 'postgres://localhost/wordnet30' )
|
192
115
|
end
|
193
116
|
|
117
|
+
context "via its index operator" do
|
194
118
|
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
synsets.first.words.should include( 'angry' )
|
201
|
-
end
|
119
|
+
it "can look up a Synset by ID" do
|
120
|
+
rval = @lexicon[ 101219722 ]
|
121
|
+
rval.should be_a( WordNet::Synset )
|
122
|
+
rval.words.map( &:to_s ).should include( 'carrot' )
|
123
|
+
end
|
202
124
|
|
125
|
+
it "can look up a Word by ID" do
|
126
|
+
rval = @lexicon[ 21338 ]
|
127
|
+
rval.should be_a( WordNet::Word )
|
128
|
+
rval.lemma.should == 'carrot'
|
129
|
+
end
|
203
130
|
|
204
|
-
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
end
|
209
|
-
|
210
|
-
|
211
|
-
it "can find every compound sense of a word in its dictionary" do
|
212
|
-
words = @lexicon.grep( 'thing' )
|
213
|
-
|
214
|
-
words.should have(10).members
|
215
|
-
words.should include( 'thing%n' )
|
216
|
-
words.should include( 'thing-in-itself%n' )
|
217
|
-
words.should include( 'thingamabob%n' )
|
218
|
-
words.should include( 'thingamajig%n' )
|
219
|
-
words.should include( 'thingmabob%n' )
|
220
|
-
words.should include( 'thingmajig%n' )
|
221
|
-
words.should include( 'things%n' )
|
222
|
-
words.should include( 'thingumabob%n' )
|
223
|
-
words.should include( 'thingumajig%n' )
|
224
|
-
words.should include( 'thingummy%n' )
|
225
|
-
end
|
226
|
-
|
227
|
-
|
228
|
-
TEST_WORDS.each do |word, pos|
|
229
|
-
it "can look up the synset #{word}(#{pos}) by word and part-of-speech" do
|
230
|
-
synsets = @lexicon.lookup_synsets( word, pos )
|
231
|
-
|
232
|
-
synsets.should have_at_least(1).members
|
233
|
-
synsets.each do |ss|
|
234
|
-
ss.should be_an_instance_of( WordNet::Synset )
|
235
|
-
end
|
131
|
+
it "can look up the synset for a word and a sense" do
|
132
|
+
ss = @lexicon[ :boot, 3 ]
|
133
|
+
ss.should be_a( WordNet::Synset )
|
134
|
+
ss.definition.should == 'footwear that covers the whole foot and lower leg'
|
236
135
|
end
|
237
|
-
end
|
238
136
|
|
137
|
+
it "can look up a synset for a word and a substring of its definition" do
|
138
|
+
ss = @lexicon[ :boot, 'kick' ]
|
139
|
+
ss.should be_a( WordNet::Synset )
|
140
|
+
ss.definition.should =~ /kick/i
|
141
|
+
end
|
239
142
|
|
240
|
-
|
241
|
-
|
242
|
-
should
|
243
|
-
|
143
|
+
it "can look up a synset for a word and a part of speech" do
|
144
|
+
ss = @lexicon[ :boot, :verb ]
|
145
|
+
ss.should be_a( WordNet::Synset )
|
146
|
+
ss.definition.should =~ /cause to load/i
|
147
|
+
end
|
244
148
|
|
149
|
+
it "can look up a synset for a word and an abbreviated part of speech" do
|
150
|
+
ss = @lexicon[ :boot, :n ]
|
151
|
+
ss.should be_a( WordNet::Synset )
|
152
|
+
ss.definition.should =~ /act of delivering/i
|
153
|
+
end
|
154
|
+
end
|
245
155
|
end
|
246
156
|
|
247
157
|
end
|
@@ -0,0 +1,59 @@
|
|
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( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
|
+
}
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'sequel'
|
15
|
+
|
16
|
+
# Use Sequel's own spec helpers
|
17
|
+
if Gem::Specification.respond_to?( :find_by_name )
|
18
|
+
sequel_spec = Gem::Specification.find_by_name( 'sequel' )
|
19
|
+
gem_basedir = sequel_spec.full_gem_path
|
20
|
+
$LOAD_PATH.unshift( gem_basedir ) unless $LOAD_PATH.include?( gem_basedir )
|
21
|
+
else
|
22
|
+
gem_basedir = Pathname( Gem.required_location('sequel', 'sequel.rb') ).dirname.parent.to_s
|
23
|
+
$LOAD_PATH.unshift( gem_basedir ) unless $LOAD_PATH.include?( gem_basedir )
|
24
|
+
end
|
25
|
+
require 'spec/model/spec_helper'
|
26
|
+
|
27
|
+
require 'spec/lib/helpers'
|
28
|
+
require 'wordnet'
|
29
|
+
require 'wordnet/model'
|
30
|
+
|
31
|
+
|
32
|
+
#####################################################################
|
33
|
+
### C O N T E X T S
|
34
|
+
#####################################################################
|
35
|
+
|
36
|
+
describe WordNet::Model do
|
37
|
+
|
38
|
+
before( :all ) do
|
39
|
+
setup_logging( :fatal )
|
40
|
+
end
|
41
|
+
|
42
|
+
before( :each ) do
|
43
|
+
MODEL_DB.reset
|
44
|
+
end
|
45
|
+
|
46
|
+
after( :all ) do
|
47
|
+
reset_logging()
|
48
|
+
end
|
49
|
+
|
50
|
+
it "propagates database handle changes to all of its subclasses" do
|
51
|
+
subclass = WordNet::Model( :tests )
|
52
|
+
newdb = Sequel.mock
|
53
|
+
WordNet::Model.db = newdb
|
54
|
+
subclass.db.should equal( newdb )
|
55
|
+
end
|
56
|
+
|
57
|
+
|
58
|
+
end
|
59
|
+
|
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
BEGIN {
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent
|
7
|
+
libdir = basedir + 'lib'
|
8
|
+
|
9
|
+
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
10
|
+
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
11
|
+
}
|
12
|
+
|
13
|
+
require 'rspec'
|
14
|
+
require 'spec/lib/helpers'
|
15
|
+
require 'wordnet/semanticlink'
|
16
|
+
|
17
|
+
|
18
|
+
#####################################################################
|
19
|
+
### C O N T E X T S
|
20
|
+
#####################################################################
|
21
|
+
|
22
|
+
describe WordNet::SemanticLink, :requires_database => true do
|
23
|
+
include WordNet::SpecHelpers
|
24
|
+
|
25
|
+
before( :all ) do
|
26
|
+
setup_logging( :fatal )
|
27
|
+
@lexicon = WordNet::Lexicon.new
|
28
|
+
end
|
29
|
+
|
30
|
+
before( :each ) do
|
31
|
+
@word = @lexicon[ :parody ]
|
32
|
+
@synset = @word.synsets.first
|
33
|
+
end
|
34
|
+
|
35
|
+
after( :all ) do
|
36
|
+
reset_logging()
|
37
|
+
end
|
38
|
+
|
39
|
+
|
40
|
+
end
|
41
|
+
|
42
|
+
|