wordnet 1.0.1 → 1.1.0
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.
- checksums.yaml +5 -5
- checksums.yaml.gz.sig +0 -0
- data.tar.gz.sig +0 -0
- data/.gems +6 -5
- data/.ruby-version +1 -1
- data/History.rdoc +9 -0
- data/README.md +1 -1
- data/README.rdoc +20 -19
- data/Rakefile +5 -5
- data/certs/ged.pem +11 -11
- data/lib/wordnet.rb +12 -18
- data/lib/wordnet/constants.rb +51 -51
- data/lib/wordnet/lexicallink.rb +6 -6
- data/lib/wordnet/lexicon.rb +26 -39
- data/lib/wordnet/model.rb +31 -39
- data/lib/wordnet/morph.rb +3 -3
- data/lib/wordnet/semanticlink.rb +7 -7
- data/lib/wordnet/sense.rb +7 -7
- data/lib/wordnet/sumoterm.rb +5 -5
- data/lib/wordnet/synset.rb +58 -45
- data/lib/wordnet/word.rb +16 -11
- data/spec/helpers.rb +11 -7
- data/spec/wordnet/lexicon_spec.rb +80 -148
- data/spec/wordnet/model_spec.rb +0 -7
- data/spec/wordnet/semanticlink_spec.rb +5 -3
- data/spec/wordnet/sense_spec.rb +5 -3
- data/spec/wordnet/synset_spec.rb +14 -26
- data/spec/wordnet/word_spec.rb +14 -6
- data/wordnet.gemspec +49 -49
- metadata +49 -57
- metadata.gz.sig +0 -0
@@ -11,50 +11,14 @@ require 'wordnet/lexicon'
|
|
11
11
|
|
12
12
|
describe WordNet::Lexicon do
|
13
13
|
|
14
|
-
|
15
|
-
|
16
|
-
expand_path
|
17
|
-
end
|
18
|
-
|
19
|
-
|
20
|
-
context "the default_db_uri method" do
|
21
|
-
|
22
|
-
it "uses the wordnet-defaultdb database gem (if available)" do
|
23
|
-
expect( Gem ).to receive( :datadir ).with( 'wordnet-defaultdb' ).at_least( :once ).
|
24
|
-
and_return( '/tmp/foo' )
|
25
|
-
expect( FileTest ).to receive( :exist? ).with( '/tmp/foo/wordnet30.sqlite' ).
|
26
|
-
and_return( true )
|
27
|
-
|
28
|
-
expect( WordNet::Lexicon.default_db_uri ).to eq( "sqlite:/tmp/foo/wordnet30.sqlite" )
|
29
|
-
end
|
30
|
-
|
31
|
-
it "uses the development version of the wordnet-defaultdb database gem if it's " +
|
32
|
-
"not installed" do
|
33
|
-
expect( Gem ).to receive( :datadir ).with( 'wordnet-defaultdb' ).
|
34
|
-
and_return( nil )
|
35
|
-
expect( FileTest ).to receive( :exist? ).with( @devdb.to_s ).
|
36
|
-
and_return( true )
|
37
|
-
|
38
|
-
expect( WordNet::Lexicon.default_db_uri ).to eq( "sqlite:#{@devdb}" )
|
39
|
-
end
|
40
|
-
|
41
|
-
it "returns nil if there is no default database" do
|
42
|
-
expect( Gem ).to receive( :datadir ).with( 'wordnet-defaultdb' ).
|
43
|
-
and_return( nil )
|
44
|
-
expect( FileTest ).to receive( :exist? ).with( @devdb.to_s ).
|
45
|
-
and_return( false )
|
46
|
-
|
47
|
-
expect( WordNet::Lexicon.default_db_uri ).to be_nil()
|
48
|
-
end
|
49
|
-
|
14
|
+
let( :devdb ) do
|
15
|
+
Pathname( 'wordnet-defaultdb/data/wordnet-defaultdb/wordnet31.sqlite' ).expand_path
|
50
16
|
end
|
51
17
|
|
52
18
|
|
53
19
|
it "raises an exception if created with no arguments and no defaultdb is available" do
|
54
|
-
expect(
|
20
|
+
expect( WordNet::DefaultDB ).to receive( :uri ).at_least( :once ).
|
55
21
|
and_return( nil )
|
56
|
-
expect( FileTest ).to receive( :exist? ).with( @devdb.to_s ).
|
57
|
-
and_return( false )
|
58
22
|
|
59
23
|
expect {
|
60
24
|
WordNet::Lexicon.new
|
@@ -62,129 +26,97 @@ describe WordNet::Lexicon do
|
|
62
26
|
end
|
63
27
|
|
64
28
|
|
65
|
-
context "
|
29
|
+
context "via its index operator" do
|
66
30
|
|
67
|
-
let( :lexicon ) { WordNet::Lexicon.new }
|
31
|
+
let( :lexicon ) { WordNet::Lexicon.new($dburi) }
|
68
32
|
|
69
|
-
context "via its index operator" do
|
70
33
|
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
34
|
+
it "can look up a Synset by ID" do
|
35
|
+
rval = lexicon[ 101222212 ]
|
36
|
+
# Can't use "be_a", as on failure it does Array(WordNet::Synset), which explodes to
|
37
|
+
# all synsets in the database
|
38
|
+
expect( rval.class ).to eq( WordNet::Synset )
|
39
|
+
expect( rval.words.map( &:to_s ) ).to include( 'carrot' )
|
40
|
+
end
|
76
41
|
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
42
|
+
it "can look up a Word by ID" do
|
43
|
+
rval = lexicon[ 21346 ]
|
44
|
+
expect( rval.class ).to eq( WordNet::Word )
|
45
|
+
expect( rval.lemma ).to eq( 'carrot' )
|
46
|
+
end
|
82
47
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
48
|
+
it "can look up the synset for a word and a sense" do
|
49
|
+
ss = lexicon[ :boot, 3 ]
|
50
|
+
expect( ss.class ).to eq( WordNet::Synset )
|
51
|
+
expect( ss.definition ).to eq( 'footwear that covers the whole foot and lower leg' )
|
52
|
+
end
|
88
53
|
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
54
|
+
it "can look up all synsets for a particular word" do
|
55
|
+
sss = lexicon.lookup_synsets( :tree )
|
56
|
+
expect( sss.size ).to eq( 7 )
|
57
|
+
expect( sss ).to all( be_a(WordNet::Synset) )
|
58
|
+
end
|
94
59
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
60
|
+
it "can constrain fetched synsets to a certain range of results" do
|
61
|
+
sss = lexicon.lookup_synsets( :tree, 1..4 )
|
62
|
+
expect( sss.size ).to eq( 4 )
|
63
|
+
end
|
99
64
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
65
|
+
it "can constrain fetched synsets to a certain (exclusive) range of results" do
|
66
|
+
sss = lexicon.lookup_synsets( :tree, 1...4 )
|
67
|
+
expect( sss.size ).to eq( 3 )
|
68
|
+
end
|
104
69
|
|
70
|
+
it "can look up a synset for a word and a substring of its definition" do
|
71
|
+
ss = lexicon[ :boot, 'kick' ]
|
72
|
+
expect( ss.class ).to eq( WordNet::Synset )
|
73
|
+
expect( ss.definition ).to match( /kick/i )
|
105
74
|
end
|
106
75
|
|
107
|
-
|
76
|
+
it "can look up a synset for a word and a part of speech" do
|
77
|
+
ss = lexicon[ :boot, :verb ]
|
78
|
+
expect( ss.class ).to eq( WordNet::Synset )
|
79
|
+
expect( ss.definition ).to match( /cause to load/i )
|
80
|
+
end
|
81
|
+
|
82
|
+
it "can look up a synset for a word and an abbreviated part of speech" do
|
83
|
+
ss = lexicon[ :boot, :n ]
|
84
|
+
expect( ss.class ).to eq( WordNet::Synset )
|
85
|
+
expect( ss.definition ).to match( /delivering a blow with the foot/i )
|
86
|
+
end
|
87
|
+
|
88
|
+
it "can constrain fetched synsets with a Regexp match against its definition", :requires_pg do
|
89
|
+
sss = lexicon.lookup_synsets( :tree, /plant/ )
|
90
|
+
expect( sss.size ).to eq( 2 )
|
91
|
+
end
|
108
92
|
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
it "can look up a Synset by ID" do
|
116
|
-
rval = lexicon[ 101219722 ]
|
117
|
-
expect( rval ).to be_a( WordNet::Synset )
|
118
|
-
expect( rval.words.map(&:to_s) ).to include( 'carrot' )
|
119
|
-
end
|
120
|
-
|
121
|
-
it "can look up a Word by ID" do
|
122
|
-
rval = lexicon[ 21338 ]
|
123
|
-
expect( rval ).to be_a( WordNet::Word )
|
124
|
-
expect( rval.lemma ).to eq( 'carrot' )
|
125
|
-
end
|
126
|
-
|
127
|
-
it "can look up the synset for a word and a sense" do
|
128
|
-
ss = lexicon[ :boot, 3 ]
|
129
|
-
expect( ss ).to be_a( WordNet::Synset )
|
130
|
-
expect( ss.definition ).to eq( 'footwear that covers the whole foot and lower leg' )
|
131
|
-
end
|
132
|
-
|
133
|
-
it "can look up a synset for a word and a substring of its definition" do
|
134
|
-
ss = lexicon[ :boot, 'kick' ]
|
135
|
-
expect( ss ).to be_a( WordNet::Synset )
|
136
|
-
expect( ss.definition ).to match( /kick/i )
|
137
|
-
end
|
138
|
-
|
139
|
-
it "can look up a synset for a word and a part of speech" do
|
140
|
-
ss = lexicon[ :boot, :verb ]
|
141
|
-
expect( ss ).to be_a( WordNet::Synset )
|
142
|
-
expect( ss.definition ).to match( /cause to load/i )
|
143
|
-
end
|
144
|
-
|
145
|
-
it "can look up a synset for a word and an abbreviated part of speech" do
|
146
|
-
ss = lexicon[ :boot, :n ]
|
147
|
-
expect( ss ).to be_a( WordNet::Synset )
|
148
|
-
expect( ss.definition ).to match( /act of delivering/i )
|
149
|
-
end
|
150
|
-
|
151
|
-
it "can constrain fetched synsets with a Regexp match against its definition" do
|
152
|
-
sss = lexicon.lookup_synsets( :tree, /plant/ )
|
153
|
-
expect( sss.size ).to eq( 2 )
|
154
|
-
end
|
155
|
-
|
156
|
-
it "can constrain fetched synsets via lexical domain" do
|
157
|
-
sss = lexicon.lookup_synsets( :tree, 'noun.shape' )
|
158
|
-
expect( sss.size ).to eq( 1 )
|
159
|
-
expect( sss.first ).to eq( WordNet::Synset[ 113912260 ] )
|
160
|
-
end
|
161
|
-
|
162
|
-
it "can constrain fetched synsets via part of speech as a single-letter Symbol" do
|
163
|
-
sss = lexicon.lookup_synsets( :tree, :n )
|
164
|
-
expect( sss.size ).to eq( 3 )
|
165
|
-
expect( sss ).to include(
|
166
|
-
WordNet::Synset[ 113912260 ],
|
167
|
-
WordNet::Synset[ 111348160 ],
|
168
|
-
WordNet::Synset[ 113104059 ]
|
169
|
-
)
|
170
|
-
end
|
171
|
-
|
172
|
-
it "can constrain fetched synsets via part of speech as a Symbol word" do
|
173
|
-
sss = lexicon.lookup_synsets( :tree, :verb )
|
174
|
-
expect( sss.size ).to eq( 4 )
|
175
|
-
expect( sss ).to include(
|
176
|
-
WordNet::Synset[ 200319111 ],
|
177
|
-
WordNet::Synset[ 201145163 ],
|
178
|
-
WordNet::Synset[ 201616293 ],
|
179
|
-
WordNet::Synset[ 201934205 ]
|
180
|
-
)
|
181
|
-
end
|
182
|
-
|
183
|
-
it "includes the database adapter name in its inspect output" do
|
184
|
-
expect( lexicon.inspect ).to include( "postgres" )
|
185
|
-
end
|
93
|
+
it "can constrain fetched synsets via lexical domain" do
|
94
|
+
sss = lexicon.lookup_synsets( :tree, 'noun.shape' )
|
95
|
+
expect( sss.size ).to eq( 1 )
|
96
|
+
expect( sss.first ).to eq( WordNet::Synset[113935275 ] )
|
97
|
+
end
|
186
98
|
|
99
|
+
it "can constrain fetched synsets via part of speech as a single-letter Symbol" do
|
100
|
+
sss = lexicon.lookup_synsets( :tree, :n )
|
101
|
+
expect( sss.size ).to eq( 3 )
|
102
|
+
expect( sss ).to include(
|
103
|
+
lexicon[ :tree, 'actor' ],
|
104
|
+
lexicon[ :tree, 'figure' ],
|
105
|
+
lexicon[ :tree, 'plant' ]
|
106
|
+
)
|
187
107
|
end
|
108
|
+
|
109
|
+
it "can constrain fetched synsets via part of speech as a Symbol word" do
|
110
|
+
sss = lexicon.lookup_synsets( :tree, :verb )
|
111
|
+
expect( sss.size ).to eq( 4 )
|
112
|
+
expect( sss ).to include(
|
113
|
+
WordNet::Synset[ 201938064 ],
|
114
|
+
WordNet::Synset[ 201147629 ],
|
115
|
+
WordNet::Synset[ 201619197 ],
|
116
|
+
WordNet::Synset[ 200319912 ]
|
117
|
+
)
|
118
|
+
end
|
119
|
+
|
188
120
|
end
|
189
121
|
|
190
122
|
end
|
data/spec/wordnet/model_spec.rb
CHANGED
@@ -16,12 +16,5 @@ DB = Sequel.connect( 'mock://postgres' )
|
|
16
16
|
|
17
17
|
describe WordNet::Model do
|
18
18
|
|
19
|
-
it "propagates database handle changes to all of its subclasses" do
|
20
|
-
subclass = WordNet::Model( :tests )
|
21
|
-
newdb = Sequel.mock
|
22
|
-
WordNet::Model.db = newdb
|
23
|
-
expect( subclass.db ).to equal( newdb )
|
24
|
-
end
|
25
|
-
|
26
19
|
end
|
27
20
|
|
@@ -2,16 +2,18 @@
|
|
2
2
|
require_relative '../helpers'
|
3
3
|
|
4
4
|
require 'rspec'
|
5
|
-
require 'wordnet
|
5
|
+
require 'wordnet'
|
6
6
|
|
7
7
|
|
8
8
|
#####################################################################
|
9
9
|
### C O N T E X T S
|
10
10
|
#####################################################################
|
11
11
|
|
12
|
-
describe WordNet::SemanticLink, :requires_database
|
12
|
+
describe 'WordNet::SemanticLink', :requires_database do
|
13
13
|
|
14
|
-
let( :
|
14
|
+
let( :described_class ) { WordNet::SemanticLink }
|
15
|
+
|
16
|
+
let( :lexicon ) { WordNet::Lexicon.new($dburi) }
|
15
17
|
let( :word ) { lexicon[96814] } # 'parody'
|
16
18
|
let( :synset ) { word.synsets.first }
|
17
19
|
let( :semlink ) { synset.semlinks.first }
|
data/spec/wordnet/sense_spec.rb
CHANGED
@@ -2,16 +2,18 @@
|
|
2
2
|
|
3
3
|
require_relative '../helpers'
|
4
4
|
|
5
|
-
require 'wordnet
|
5
|
+
require 'wordnet'
|
6
6
|
|
7
7
|
|
8
|
-
describe WordNet::Sense, :requires_database
|
8
|
+
describe 'WordNet::Sense', :requires_database do
|
9
9
|
|
10
10
|
before( :all ) do
|
11
|
-
@lexicon = WordNet::Lexicon.new
|
11
|
+
@lexicon = WordNet::Lexicon.new( $dburi )
|
12
12
|
end
|
13
13
|
|
14
14
|
|
15
|
+
let( :described_class ) { WordNet::Sense }
|
16
|
+
|
15
17
|
let( :sense ) do
|
16
18
|
WordNet::Word[ 79712 ].senses.first
|
17
19
|
end
|
data/spec/wordnet/synset_spec.rb
CHANGED
@@ -2,20 +2,22 @@
|
|
2
2
|
require_relative '../helpers'
|
3
3
|
|
4
4
|
require 'rspec'
|
5
|
-
require 'wordnet/synset'
|
6
5
|
|
7
6
|
|
8
7
|
#####################################################################
|
9
8
|
### C O N T E X T S
|
10
9
|
#####################################################################
|
11
10
|
|
12
|
-
describe WordNet::Synset, :requires_database
|
11
|
+
describe 'WordNet::Synset', :requires_database do
|
13
12
|
|
14
13
|
before( :all ) do
|
15
|
-
@lexicon = WordNet::Lexicon.new
|
14
|
+
@lexicon = WordNet::Lexicon.new( $dburi )
|
16
15
|
end
|
17
16
|
|
18
17
|
|
18
|
+
let( :described_class ) { WordNet::Synset }
|
19
|
+
|
20
|
+
|
19
21
|
it "knows what kinds of lexical domains are available" do
|
20
22
|
expect( described_class.lexdomains ).to be_a( Hash )
|
21
23
|
expect( described_class.lexdomains ).to include( 'noun.cognition' )
|
@@ -42,7 +44,7 @@ describe WordNet::Synset, :requires_database => true do
|
|
42
44
|
# floor, level, storey, story (noun): [noun.artifact] a structure
|
43
45
|
# consisting of a room or set of rooms at a single position along a
|
44
46
|
# vertical scale (hypernym: 1, hyponym: 5, part meronym: 1)
|
45
|
-
let( :synset ) {
|
47
|
+
let( :synset ) { @lexicon['story', :n] }
|
46
48
|
|
47
49
|
|
48
50
|
it "knows what lexical domain it's from" do
|
@@ -60,31 +62,17 @@ describe WordNet::Synset, :requires_database => true do
|
|
60
62
|
expect( enum ).to be_a( Enumerator )
|
61
63
|
end
|
62
64
|
|
63
|
-
it "can recursively traverse its semantic links" do
|
64
|
-
res = synset.traverse( :hypernyms ).to_a
|
65
|
-
expect( res.size ).to eq( 6 )
|
66
|
-
expect( res ).to eq([
|
67
|
-
WordNet::Synset[ 104341686 ],
|
68
|
-
WordNet::Synset[ 100021939 ],
|
69
|
-
WordNet::Synset[ 100003553 ],
|
70
|
-
WordNet::Synset[ 100002684 ],
|
71
|
-
WordNet::Synset[ 100001930 ],
|
72
|
-
WordNet::Synset[ 100001740 ],
|
73
|
-
])
|
74
|
-
end
|
75
|
-
|
76
65
|
it "can return an Enumerator for recursively traversing its semantic links" do
|
77
66
|
enum = synset.traverse( :hypernyms )
|
78
67
|
|
79
|
-
expect( enum
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
}.to raise_error( StopIteration )
|
68
|
+
expect( enum ).to be_a( Enumerator ).and( contain_exactly(
|
69
|
+
@lexicon['artifact', :n],
|
70
|
+
@lexicon['unit', :n],
|
71
|
+
@lexicon['object', :n],
|
72
|
+
@lexicon['physical entity', :n],
|
73
|
+
@lexicon['entity', :n],
|
74
|
+
@lexicon['structure', :n],
|
75
|
+
) )
|
88
76
|
end
|
89
77
|
end
|
90
78
|
|
data/spec/wordnet/word_spec.rb
CHANGED
@@ -3,21 +3,23 @@ require_relative '../helpers'
|
|
3
3
|
|
4
4
|
require 'rspec'
|
5
5
|
require 'wordnet'
|
6
|
-
require 'wordnet/word'
|
7
6
|
|
8
7
|
|
9
8
|
#####################################################################
|
10
9
|
### C O N T E X T S
|
11
10
|
#####################################################################
|
12
11
|
|
13
|
-
describe WordNet::Word, :requires_database
|
12
|
+
describe 'WordNet::Word', :requires_database do
|
14
13
|
|
15
|
-
let( :
|
14
|
+
let( :described_class ) { WordNet::Word }
|
15
|
+
|
16
|
+
let!( :lexicon ) { WordNet::Lexicon.new($dburi) }
|
16
17
|
|
17
18
|
|
18
19
|
context "the Word for 'run'" do
|
19
20
|
|
20
|
-
let( :word ) {
|
21
|
+
let( :word ) { described_class.by_lemma('run').first }
|
22
|
+
|
21
23
|
|
22
24
|
it "knows what senses it has" do
|
23
25
|
senses = word.senses
|
@@ -26,6 +28,7 @@ describe WordNet::Word, :requires_database => true do
|
|
26
28
|
expect( senses.first ).to be_a( WordNet::Sense )
|
27
29
|
end
|
28
30
|
|
31
|
+
|
29
32
|
it "knows what synsets it has" do
|
30
33
|
synsets = word.synsets
|
31
34
|
|
@@ -34,6 +37,7 @@ describe WordNet::Word, :requires_database => true do
|
|
34
37
|
expect( synsets.first.senses ).to include( word.senses.first )
|
35
38
|
end
|
36
39
|
|
40
|
+
|
37
41
|
it "has a dataset for selecting noun synsets" do
|
38
42
|
expect( word.nouns ).to be_a( Sequel::Dataset )
|
39
43
|
expect( word.nouns.count ).to eq( 16 )
|
@@ -46,6 +50,7 @@ describe WordNet::Word, :requires_database => true do
|
|
46
50
|
)
|
47
51
|
end
|
48
52
|
|
53
|
+
|
49
54
|
it "has a dataset for selecting verb synsets" do
|
50
55
|
expect( word.verbs ).to be_a( Sequel::Dataset )
|
51
56
|
expect( word.verbs.count ).to eq( 41 )
|
@@ -63,7 +68,8 @@ describe WordNet::Word, :requires_database => true do
|
|
63
68
|
|
64
69
|
context "the Word for 'light'" do
|
65
70
|
|
66
|
-
let( :word ) {
|
71
|
+
let( :word ) { described_class.by_lemma('light').first }
|
72
|
+
|
67
73
|
|
68
74
|
it "has a dataset for selecting adjective synsets" do
|
69
75
|
expect( word.adjectives ).to be_a( Sequel::Dataset )
|
@@ -76,6 +82,7 @@ describe WordNet::Word, :requires_database => true do
|
|
76
82
|
)
|
77
83
|
end
|
78
84
|
|
85
|
+
|
79
86
|
it "has a dataset for selecting adjective-satellite synsets" do
|
80
87
|
expect( word.adjective_satellites ).to be_a( Sequel::Dataset )
|
81
88
|
expect( word.adjective_satellites.count ).to eq( 17 )
|
@@ -92,7 +99,8 @@ describe WordNet::Word, :requires_database => true do
|
|
92
99
|
|
93
100
|
context "the Word for 'lightly'" do
|
94
101
|
|
95
|
-
let( :word ) {
|
102
|
+
let( :word ) { described_class.by_lemma('lightly').first }
|
103
|
+
|
96
104
|
|
97
105
|
it "has a dataset for selecting adverb synsets" do
|
98
106
|
expect( word.adverbs ).to be_a( Sequel::Dataset )
|