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
data/spec/wordnet/synset_spec.rb
CHANGED
@@ -2,287 +2,58 @@
|
|
2
2
|
|
3
3
|
BEGIN {
|
4
4
|
require 'pathname'
|
5
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
6
5
|
|
6
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
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
|
-
|
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
|
13
|
+
require 'rspec'
|
14
|
+
require 'spec/lib/helpers'
|
15
|
+
require 'wordnet/synset'
|
28
16
|
|
29
17
|
|
30
18
|
#####################################################################
|
31
19
|
### C O N T E X T S
|
32
20
|
#####################################################################
|
33
21
|
|
34
|
-
describe WordNet::Synset do
|
35
|
-
|
36
|
-
Accessors = [
|
37
|
-
:part_of_speech,
|
38
|
-
:offset,
|
39
|
-
:filenum,
|
40
|
-
:wordlist,
|
41
|
-
:pointerlist,
|
42
|
-
:frameslist,
|
43
|
-
:gloss,
|
44
|
-
]
|
45
|
-
|
46
|
-
RelationMethods = [
|
47
|
-
:antonyms,
|
48
|
-
:hypernyms,
|
49
|
-
:entailment,
|
50
|
-
:hyponyms,
|
51
|
-
:causes,
|
52
|
-
:verb_groups,
|
53
|
-
:similar_to,
|
54
|
-
:participles,
|
55
|
-
:pertainyms,
|
56
|
-
:attributes,
|
57
|
-
:derived_from,
|
58
|
-
:derivations,
|
59
|
-
:see_also,
|
60
|
-
|
61
|
-
:instance_hyponyms,
|
62
|
-
|
63
|
-
:instance_hypernyms,
|
64
|
-
|
65
|
-
:member_meronyms,
|
66
|
-
:stuff_meronyms,
|
67
|
-
:portion_meronyms,
|
68
|
-
:component_meronyms,
|
69
|
-
:feature_meronyms,
|
70
|
-
:phase_meronyms,
|
71
|
-
:place_meronyms,
|
72
|
-
|
73
|
-
:member_holonyms,
|
74
|
-
:stuff_holonyms,
|
75
|
-
:portion_holonyms,
|
76
|
-
:component_holonyms,
|
77
|
-
:feature_holonyms,
|
78
|
-
:phase_holonyms,
|
79
|
-
:place_holonyms,
|
80
|
-
|
81
|
-
:category_domains,
|
82
|
-
:region_domains,
|
83
|
-
:usage_domains,
|
22
|
+
describe WordNet::Synset, :requires_database => true do
|
23
|
+
include WordNet::SpecHelpers
|
84
24
|
|
85
|
-
|
86
|
-
:
|
87
|
-
|
88
|
-
]
|
89
|
-
|
90
|
-
AggregateRelationMethods = [
|
91
|
-
:meronyms,
|
92
|
-
:holonyms,
|
93
|
-
:domains,
|
94
|
-
:members,
|
95
|
-
]
|
96
|
-
|
97
|
-
|
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
|
-
|
103
|
-
|
104
|
-
#################################################################
|
105
|
-
### T E S T S
|
106
|
-
#################################################################
|
107
|
-
|
108
|
-
### Accessors
|
109
|
-
def test_accessors
|
110
|
-
printTestHeader "Synset: Accessors"
|
111
|
-
rval = nil
|
112
|
-
|
113
|
-
assert_respond_to @blankSyn, :lexicon
|
114
|
-
|
115
|
-
Accessors.each do |meth|
|
116
|
-
assert_respond_to @blankSyn, meth
|
117
|
-
assert_respond_to @blankSyn, "#{meth}="
|
118
|
-
|
119
|
-
assert_nothing_raised do
|
120
|
-
rval = @blankSyn.send( meth )
|
121
|
-
end
|
122
|
-
end
|
25
|
+
before( :all ) do
|
26
|
+
setup_logging( :fatal )
|
27
|
+
@lexicon = WordNet::Lexicon.new
|
123
28
|
end
|
124
29
|
|
125
|
-
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
RelationMethods.each do |meth|
|
131
|
-
casemeth = meth.to_s.sub( /^(\w)/ ) {|char| char.upcase }.intern
|
132
|
-
|
133
|
-
assert_respond_to @blankSyn, meth
|
134
|
-
assert_respond_to @blankSyn, "#{meth}="
|
135
|
-
|
136
|
-
assert_nothing_raised {
|
137
|
-
rval = @blankSyn.send( meth )
|
138
|
-
}
|
139
|
-
|
140
|
-
assert_instance_of Array, rval
|
141
|
-
end
|
142
|
-
end
|
143
|
-
|
144
|
-
### Aggregate relation methods
|
145
|
-
def test_aggregate_relations
|
146
|
-
printTestHeader "Synset: Aggregate relations"
|
147
|
-
rval = nil
|
148
|
-
|
149
|
-
AggregateRelationMethods.each {|meth|
|
150
|
-
assert_respond_to @blankSyn, meth
|
151
|
-
|
152
|
-
assert_nothing_raised {
|
153
|
-
rval = @blankSyn.send( meth )
|
154
|
-
}
|
155
|
-
|
156
|
-
assert_instance_of Array, rval
|
157
|
-
}
|
158
|
-
end
|
159
|
-
|
160
|
-
### Traversal method
|
161
|
-
def test_synset_should_respond_to_traverse_method
|
162
|
-
printTestHeader "Synset: Traversal method"
|
163
|
-
assert_respond_to @traversalSyn, :traverse
|
164
|
-
end
|
165
|
-
|
166
|
-
### :TODO: This should really be split into two tests.
|
167
|
-
### Traversal: include origin, break loop
|
168
|
-
def test_traversal_with_true_second_arg_should_include_origin
|
169
|
-
printTestHeader "Synset: Traversal, including origin, break"
|
170
|
-
rval = nil
|
171
|
-
count = depth = 0
|
172
|
-
sets = []
|
173
|
-
|
174
|
-
assert_nothing_raised {
|
175
|
-
rval = @traversalSyn.traverse( :hyponyms, true ) {|tsyn,tdepth|
|
176
|
-
sets << tsyn
|
177
|
-
depth = tdepth
|
178
|
-
count += 1
|
179
|
-
return true
|
180
|
-
}
|
181
|
-
}
|
182
|
-
assert_equal true, rval
|
183
|
-
assert_equal 1, sets.length
|
184
|
-
assert_equal @traversalSyn, sets[0]
|
185
|
-
assert_equal 0, depth
|
186
|
-
assert_equal 1, count
|
187
|
-
end
|
188
|
-
|
189
|
-
### :TODO: This should really be split into two tests.
|
190
|
-
### Traversal: exclude origin, break loop
|
191
|
-
def test_traversal_with_false_second_arg_should_not_include_origin
|
192
|
-
printTestHeader "Synset: Traversal, excluding origin, break"
|
193
|
-
rval = nil
|
194
|
-
count = depth = 0
|
195
|
-
sets = []
|
196
|
-
|
197
|
-
assert_nothing_raised {
|
198
|
-
rval = @traversalSyn.traverse( :hyponyms, false ) {|tsyn,tdepth|
|
199
|
-
sets << tsyn
|
200
|
-
depth = tdepth
|
201
|
-
count += 1
|
202
|
-
return true
|
203
|
-
}
|
204
|
-
}
|
205
|
-
assert_equal true, rval
|
206
|
-
assert_equal 1, sets.length
|
207
|
-
assert_not_equal @traversalSyn, sets[0]
|
208
|
-
assert_equal 1, depth
|
209
|
-
assert_equal 1, count
|
210
|
-
end
|
211
|
-
|
212
|
-
### Traversal: include origin, nobreak, noblock
|
213
|
-
def test_hyponym_traversal_with_no_block_should_return_appropriate_hyponyms
|
214
|
-
printTestHeader "Synset: Traversal, include origin, nobreak, noblock"
|
215
|
-
sets = []
|
216
|
-
|
217
|
-
assert_nothing_raised {
|
218
|
-
sets = @traversalSyn.traverse( :hyponyms )
|
219
|
-
}
|
220
|
-
assert_block { sets.length > 1 }
|
221
|
-
assert_equal @traversalSyn, sets[0]
|
222
|
-
assert_block { sets.find {|hsyn| hsyn.words.include?( "grammar" )} }
|
223
|
-
assert_block { sets.find {|hsyn| hsyn.words.include?( "syntax" )} }
|
224
|
-
assert_block { sets.find {|hsyn| hsyn.words.include?( "computational linguistics" )} }
|
30
|
+
before( :each ) do
|
31
|
+
# floor, level, storey, story (noun): [noun.artifact] a structure
|
32
|
+
# consisting of a room or set of rooms at a single position along a
|
33
|
+
# vertical scale (hypernym: 1, hyponym: 5, part meronym: 1)
|
34
|
+
@synset = WordNet::Synset[ 103365991 ]
|
225
35
|
end
|
226
|
-
|
227
36
|
|
228
|
-
|
229
|
-
|
230
|
-
printTestHeader "Synset: Traversal, exclude origin, nobreak, noblock"
|
231
|
-
sets = []
|
232
|
-
|
233
|
-
assert_nothing_raised {
|
234
|
-
sets = @traversalSyn.traverse( :hyponyms, false )
|
235
|
-
}
|
236
|
-
assert_block { sets.length > 1 }
|
237
|
-
assert_not_equal @traversalSyn, sets[0]
|
238
|
-
assert_block { sets.find {|hsyn| hsyn.words.include?( "grammar" )} }
|
239
|
-
assert_block { sets.find {|hsyn| hsyn.words.include?( "syntax" )} }
|
240
|
-
assert_block { sets.find {|hsyn| hsyn.words.include?( "computational linguistics" )} }
|
37
|
+
after( :all ) do
|
38
|
+
reset_logging()
|
241
39
|
end
|
242
|
-
|
243
40
|
|
244
|
-
### Traversal: include origin, nobreak, noblock
|
245
|
-
def test_traversal_break_after_3_should_include_three_sets_plus_origin
|
246
|
-
printTestHeader "Synset: Traversal, break after 3"
|
247
|
-
rval = nil
|
248
|
-
sets = Hash::new {|hsh,key| hsh[key] = []}
|
249
41
|
|
250
|
-
|
251
|
-
|
252
|
-
sets[tdepth] << tsyn
|
253
|
-
tdepth == 3
|
254
|
-
}
|
255
|
-
}
|
256
|
-
assert_equal 4, sets.keys.length
|
257
|
-
assert_equal [0,1,2,3], sets.keys.sort
|
258
|
-
assert_equal 1, sets[3].length
|
259
|
-
assert rval, "Break early flag expected to be set"
|
42
|
+
it "knows what lexical domain it's from" do
|
43
|
+
@synset.lexical_domain.should == 'noun.artifact'
|
260
44
|
end
|
261
45
|
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
rval = nil
|
267
|
-
|
268
|
-
assert_nothing_raised { rval = @traversalSyn.part_of_speech }
|
269
|
-
assert_equal :noun, rval
|
46
|
+
it "can make a Sequel dataset for any of its semantic link relationships" do
|
47
|
+
ds = @synset.semanticlink_dataset( :member_meronyms )
|
48
|
+
ds.should be_a( Sequel::Dataset )
|
49
|
+
ds.first_source_table.should == :synsets
|
270
50
|
end
|
271
51
|
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
printTestHeader "Synset: pos"
|
276
|
-
rval = nil
|
277
|
-
|
278
|
-
assert_nothing_raised { rval = @traversalSyn.pos }
|
279
|
-
assert_equal "n", rval
|
52
|
+
it "can make an Enumerator for any of its semantic link relationships" do
|
53
|
+
enum = @synset.semanticlink_enum( :member_meronyms )
|
54
|
+
enum.should be_a( Enumerator )
|
280
55
|
end
|
281
56
|
|
282
|
-
|
283
|
-
### :TODO: Test traversal, content, storing, higher-order functions
|
284
|
-
|
285
|
-
|
286
57
|
end
|
287
58
|
|
288
59
|
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
BEGIN {
|
4
|
+
require 'pathname'
|
5
|
+
|
6
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.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'
|
16
|
+
require 'wordnet/word'
|
17
|
+
|
18
|
+
|
19
|
+
#####################################################################
|
20
|
+
### C O N T E X T S
|
21
|
+
#####################################################################
|
22
|
+
|
23
|
+
describe WordNet::Word, :requires_database => true do
|
24
|
+
include WordNet::SpecHelpers
|
25
|
+
|
26
|
+
before( :all ) do
|
27
|
+
setup_logging( :fatal )
|
28
|
+
@lexicon = WordNet::Lexicon.new
|
29
|
+
end
|
30
|
+
|
31
|
+
before( :each ) do
|
32
|
+
# 'run'
|
33
|
+
@word = @lexicon[ 113377 ]
|
34
|
+
end
|
35
|
+
|
36
|
+
after( :all ) do
|
37
|
+
reset_logging()
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "knows what senses it has" do
|
42
|
+
senses = @word.senses
|
43
|
+
senses.should be_an( Array )
|
44
|
+
senses.should have( 57 ).members
|
45
|
+
senses.first.should be_a( WordNet::Sense )
|
46
|
+
end
|
47
|
+
|
48
|
+
it "knows what synsets it has" do
|
49
|
+
senses = @word.senses
|
50
|
+
synsets = @word.synsets
|
51
|
+
|
52
|
+
synsets.should have( senses.length ).members
|
53
|
+
synsets.first.senses.should include( senses.first )
|
54
|
+
end
|
55
|
+
|
56
|
+
end
|
57
|
+
|
58
|
+
|
@@ -0,0 +1,52 @@
|
|
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/lexicon'
|
16
|
+
|
17
|
+
|
18
|
+
#####################################################################
|
19
|
+
### C O N T E X T S
|
20
|
+
#####################################################################
|
21
|
+
|
22
|
+
describe WordNet do
|
23
|
+
include WordNet::SpecHelpers
|
24
|
+
|
25
|
+
before( :all ) do
|
26
|
+
setup_logging( :fatal )
|
27
|
+
end
|
28
|
+
|
29
|
+
after( :all ) do
|
30
|
+
reset_logging()
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should know if its default logger is replaced" do
|
34
|
+
WordNet.reset_logger
|
35
|
+
WordNet.should be_using_default_logger
|
36
|
+
WordNet.logger = Logger.new( $stderr )
|
37
|
+
WordNet.should_not be_using_default_logger
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
it "returns a version string if asked" do
|
42
|
+
WordNet.version_string.should =~ /\w+ [\d.]+/
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
it "returns a version string with a build number if asked" do
|
47
|
+
WordNet.version_string(true).should =~ /\w+ [\d.]+ \(build [[:xdigit:]]+\)/
|
48
|
+
end
|
49
|
+
|
50
|
+
|
51
|
+
end
|
52
|
+
|
data.tar.gz.sig
ADDED
Binary file
|