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.
Files changed (54) hide show
  1. data/.gemtest +0 -0
  2. data/History.rdoc +5 -0
  3. data/LICENSE +9 -9
  4. data/Manifest.txt +39 -0
  5. data/README.rdoc +60 -0
  6. data/Rakefile +47 -267
  7. data/TODO +9 -0
  8. data/WordNet30-license.txt +31 -0
  9. data/examples/add-laced-boots.rb +35 -0
  10. data/examples/clothes-with-collars.rb +42 -0
  11. data/examples/clothesWithTongues.rb +0 -0
  12. data/examples/domainTree.rb +0 -0
  13. data/examples/memberTree.rb +0 -0
  14. data/lib/wordnet/constants.rb +259 -296
  15. data/lib/wordnet/lexicallink.rb +34 -0
  16. data/lib/wordnet/lexicon.rb +158 -386
  17. data/lib/wordnet/mixins.rb +62 -0
  18. data/lib/wordnet/model.rb +78 -0
  19. data/lib/wordnet/morph.rb +25 -0
  20. data/lib/wordnet/semanticlink.rb +52 -0
  21. data/lib/wordnet/sense.rb +55 -0
  22. data/lib/wordnet/sumoterm.rb +21 -0
  23. data/lib/wordnet/synset.rb +404 -859
  24. data/lib/wordnet/utils.rb +126 -0
  25. data/lib/wordnet/word.rb +119 -0
  26. data/lib/wordnet.rb +113 -76
  27. data/spec/lib/helpers.rb +102 -133
  28. data/spec/linguawordnet.tests.rb +38 -0
  29. data/spec/wordnet/lexicon_spec.rb +96 -186
  30. data/spec/wordnet/model_spec.rb +59 -0
  31. data/spec/wordnet/semanticlink_spec.rb +42 -0
  32. data/spec/wordnet/synset_spec.rb +27 -256
  33. data/spec/wordnet/word_spec.rb +58 -0
  34. data/spec/wordnet_spec.rb +52 -0
  35. data.tar.gz.sig +0 -0
  36. metadata +227 -188
  37. metadata.gz.sig +0 -0
  38. data/ChangeLog +0 -720
  39. data/README +0 -93
  40. data/Rakefile.local +0 -46
  41. data/convertdb.rb +0 -417
  42. data/examples/addLacedBoots.rb +0 -27
  43. data/examples/clothesWithCollars.rb +0 -36
  44. data/rake/dependencies.rb +0 -76
  45. data/rake/helpers.rb +0 -384
  46. data/rake/manual.rb +0 -755
  47. data/rake/packaging.rb +0 -112
  48. data/rake/publishing.rb +0 -303
  49. data/rake/rdoc.rb +0 -35
  50. data/rake/style.rb +0 -62
  51. data/rake/svn.rb +0 -469
  52. data/rake/testing.rb +0 -192
  53. data/rake/verifytask.rb +0 -64
  54. data/utils.rb +0 -838
@@ -1,301 +1,264 @@
1
1
  #!/usr/bin/ruby
2
- #
2
+
3
+ require 'wordnet' unless defined?( WordNet )
4
+
3
5
  # This is a module containing constants used in the WordNet interface for
4
6
  # Ruby. They are contained in a module to facilitate their easy inclusion in
5
7
  # other namespaces. All constants in this module are also contained in the
6
8
  # WordNet namespace itself.
7
- #
8
- # E.g.,
9
- #
10
- # WordNet::Adjective == WordNet::Constants::Adjective
11
- #
12
- # If you do:
13
- # include WordNet::Constants
14
- #
15
- # then:
16
- # Adjective == WordNet::Adjective
17
- #
18
- # == Synopsis
19
- #
20
- # require 'wordnet'
21
- # include WordNet::Constants
22
- #
23
- # lex = WordNet::Lexicon::new
24
- # origins = lex.lookup_synsets( "shoe", Noun )
25
- #
26
- # == Authors
27
- #
28
- # * Michael Granger <ged@FaerieMUD.org>
29
- #
30
- # == Copyright
31
- #
32
- # Copyright (c) 2003-2008 The FaerieMUD Consortium. All rights reserved.
33
- #
34
- # This module is free software. You may use, modify, and/or redistribute this
35
- # software under the terms of the Perl Artistic License. (See
36
- # http://language.perl.com/misc/Artistic.html)
37
- #
38
- # == Version
39
- #
40
- # $Id: constants.rb 90 2008-07-09 23:02:53Z deveiant $
41
- #
42
- module WordNet
43
-
44
- ### Constant-container module
45
- module Constants
46
-
47
- # Synset syntactic-category names -> indicators
48
- SYNTACTIC_CATEGORIES = {
49
- :noun => "n",
50
- :verb => "v",
51
- :adjective => "a",
52
- :adverb => "r",
53
- :other => "s",
54
- }
55
- # Syntactic-category indicators -> names
56
- SYNTACTIC_SYMBOLS = SYNTACTIC_CATEGORIES.invert
57
-
58
- # Map the categories into their own constants (eg., Noun)
59
- SYNTACTIC_CATEGORIES.each do |sym,val|
60
- cname = sym.to_s.capitalize
61
- const_set( cname, val )
62
- end
63
-
64
- # Information about pointer types is contained in the wninput(5WN)
65
- # manpage.
66
-
67
- # Synset pointer typenames -> indicators
68
- POINTER_TYPES = {
69
- :antonym => '!',
70
- :hypernym => '@',
71
- :entailment => '*',
72
- :hyponym => '~',
73
- :meronym => '%',
74
- :holonym => '#',
75
- :cause => '>',
76
- :verb_group => %{$},
77
- :similar_to => '&',
78
- :participle => '<',
79
- :pertainym => '\\',
80
- :attribute => '=',
81
- :derived_from => '\\',
82
- :see_also => '^',
83
- :derivation => '+',
84
- :domain => ';',
85
- :member => '-',
86
- }
87
-
88
- # Synset pointer indicator -> typename
89
- POINTER_SYMBOLS = POINTER_TYPES.invert
90
-
91
- # Map the pointer types into their own symbols (eg., :verb_group => VerbGroup)
92
- POINTER_TYPES.each do |sym,val|
93
- cname = sym.to_s.gsub( /(?:^|_)(.)/ ) { $1.upcase }
94
- const_set( cname, val )
95
- end
96
-
97
- # Hypernym synset pointer types
98
- HYPERNYM_TYPES = {
99
- nil => '@', # Install non-subtype methods, too
100
- :instance => '@i',
101
- }
102
-
103
- # Hypernym indicator -> type map
104
- HYPERNYM_SYMBOLS = HYPERNYM_TYPES.invert
105
-
106
- # Hyponym synset pointer types
107
- HYPONYM_TYPES = {
108
- nil => '~', # Install non-subtype methods, too
109
- :instance => '~i',
110
- }
111
-
112
- # Hyponym indicator -> type map
113
- HYPONYM_SYMBOLS = HYPONYM_TYPES.invert
114
-
115
- # Meronym synset pointer types
116
- MERONYM_TYPES = {
117
- :member => '%m',
118
- :stuff => '%s',
119
- :portion => '%o',
120
- :component => '%p',
121
- :feature => '%f',
122
- :phase => '%a',
123
- :place => '%l',
124
- }
125
-
126
- # Meronym indicator -> type map
127
- MERONYM_SYMBOLS = MERONYM_TYPES.invert
128
-
129
- # Map the meronym types into their own constants (eg., MemberMeronym)
130
- MERONYM_TYPES.each do |sym,val|
131
- cname = sym.to_s.capitalize + "Meronym"
132
- const_set( cname, val )
133
- end
134
-
135
- # Holonym synset pointer types
136
- HOLONYM_TYPES = {
137
- :member => '#m',
138
- :stuff => '#s',
139
- :portion => '#o',
140
- :component => '#p',
141
- :feature => '#f',
142
- :phase => '#a',
143
- :place => '#l',
144
- }
145
-
146
- # Holonym indicator -> type map
147
- HOLONYM_SYMBOLS = HOLONYM_TYPES.invert
148
-
149
- # Map the holonym types into their own constants (eg., MemberHolonym)
150
- HOLONYM_TYPES.each do |sym,val|
151
- cname = sym.to_s.capitalize + "Holonym"
152
- const_set( cname, val )
153
- end
154
-
155
- # Domain synset pointer types
156
- DOMAIN_TYPES = {
157
- :category => ';c',
158
- :region => ';r',
159
- :usage => ';u',
160
- }
161
-
162
- # Domain indicator -> type map
163
- DomainSymbols = DOMAIN_TYPES.invert
164
-
165
- # Map the domain types into their own constants (eg., CategoryDomain)
166
- DOMAIN_TYPES.each do |sym,val|
167
- cname = sym.to_s.capitalize + "Domain"
168
- const_set( cname, val )
169
- end
170
-
171
- # Member synset pointer types
172
- MEMBER_TYPES = {
173
- :category => '-c',
174
- :region => '-r',
175
- :usage => '-u',
176
- }
177
-
178
- # Member indicator -> type map
179
- MEMBER_SYMBOLS = MEMBER_TYPES.invert
180
-
181
- # Map the member types into their own constants (eg., CategoryMember)
182
- MEMBER_TYPES.each do |sym,val|
183
- cname = sym.to_s.capitalize + "Member"
184
- const_set( cname, val )
185
- end
186
-
187
- # Map of primary types to maps of their subtypes
188
- POINTER_SUBTYPES = {
189
- :hyponym => HYPONYM_TYPES,
190
- :hypernym => HYPERNYM_TYPES,
191
- :meronym => MERONYM_TYPES,
192
- :holonym => HOLONYM_TYPES,
193
- :member => MEMBER_TYPES,
194
- :domain => DOMAIN_TYPES,
195
- }
196
-
197
-
198
- # Record-part delimiter
199
- DELIM = '||'
200
- DELIM_RE = Regexp::new( Regexp::quote(DELIM) )
201
-
202
- # Record-subpart delimiter
203
- SUB_DELIM = '|'
204
- SUB_DELIM_RE = Regexp::new( Regexp::quote(SUB_DELIM) )
205
-
206
- # Lexicographer file index -- from lexnames(5WN)
207
- LEXFILES = [
208
- "adj.all",
209
- "adj.pert",
210
- "adv.all",
211
- "noun.Tops",
212
- "noun.act",
213
- "noun.animal",
214
- "noun.artifact",
215
- "noun.attribute",
216
- "noun.body",
217
- "noun.cognition",
218
- "noun.communication",
219
- "noun.event",
220
- "noun.feeling",
221
- "noun.food",
222
- "noun.group",
223
- "noun.location",
224
- "noun.motive",
225
- "noun.object",
226
- "noun.person",
227
- "noun.phenomenon",
228
- "noun.plant",
229
- "noun.possession",
230
- "noun.process",
231
- "noun.quantity",
232
- "noun.relation",
233
- "noun.shape",
234
- "noun.state",
235
- "noun.substance",
236
- "noun.time",
237
- "verb.body",
238
- "verb.change",
239
- "verb.cognition",
240
- "verb.communication",
241
- "verb.competition",
242
- "verb.consumption",
243
- "verb.contact",
244
- "verb.creation",
245
- "verb.emotion",
246
- "verb.motion",
247
- "verb.perception",
248
- "verb.possession",
249
- "verb.social",
250
- "verb.stative",
251
- "verb.weather",
252
- "adj.ppl"
253
- ]
254
-
255
- # Verb sentences (?) -- used in building verb frames.
256
- VERB_SENTS = [
257
- "",
258
- "Something ----s",
259
- "Somebody ----s",
260
- "It is ----ing",
261
- "Something is ----ing PP",
262
- "Something ----s something Adjective/Noun",
263
- "Something ----s Adjective/Noun",
264
- "Somebody ----s Adjective",
265
- "Somebody ----s something",
266
- "Somebody ----s somebody",
267
- "Something ----s somebody",
268
- "Something ----s something",
269
- "Something ----s to somebody",
270
- "Somebody ----s on something",
271
- "Somebody ----s somebody something",
272
- "Somebody ----s something to somebody",
273
- "Somebody ----s something from somebody",
274
- "Somebody ----s somebody with something",
275
- "Somebody ----s somebody of something",
276
- "Somebody ----s something on somebody",
277
- "Somebody ----s somebody PP",
278
- "Somebody ----s something PP",
279
- "Somebody ----s PP",
280
- "Somebody's (body part) ----s",
281
- "Somebody ----s somebody to INFINITIVE",
282
- "Somebody ----s somebody INFINITIVE",
283
- "Somebody ----s that CLAUSE",
284
- "Somebody ----s to somebody",
285
- "Somebody ----s to INFINITIVE",
286
- "Somebody ----s whether INFINITIVE",
287
- "Somebody ----s somebody into V-ing something",
288
- "Somebody ----s something with something",
289
- "Somebody ----s INFINITIVE",
290
- "Somebody ----s VERB-ing",
291
- "It ----s that CLAUSE",
292
- "Something ----s INFINITIVE"
293
- ]
294
-
295
-
296
- end # module Constants
297
-
298
- # Make the constants available under the WordNet namespace, too.
299
- include Constants
300
-
301
- end # module WordNet
9
+ module WordNet::Constants
10
+
11
+ # The default database options
12
+ DEFAULT_DB_OPTIONS = {}
13
+
14
+ # Synset syntactic-category names -> indicators
15
+ SYNTACTIC_CATEGORIES = {
16
+ :noun => "n",
17
+ :verb => "v",
18
+ :adjective => "a",
19
+ :adverb => "r",
20
+ :other => "s",
21
+ }
22
+ # Syntactic-category indicators -> names
23
+ SYNTACTIC_SYMBOLS = SYNTACTIC_CATEGORIES.invert
24
+
25
+ # Map the categories into their own constants (eg., Noun)
26
+ SYNTACTIC_CATEGORIES.each do |sym,val|
27
+ cname = sym.to_s.capitalize
28
+ const_set( cname, val )
29
+ end
30
+
31
+ # Information about pointer types is contained in the wninput(5WN)
32
+ # manpage.
33
+
34
+ # Synset pointer typenames -> indicators
35
+ POINTER_TYPES = {
36
+ :antonym => '!',
37
+ :hypernym => '@',
38
+ :entailment => '*',
39
+ :hyponym => '~',
40
+ :meronym => '%',
41
+ :holonym => '#',
42
+ :cause => '>',
43
+ :verb_group => '$',
44
+ :similar_to => '&',
45
+ :participle => '<',
46
+ :pertainym => '\\',
47
+ :attribute => '=',
48
+ :derived_from => '\\',
49
+ :see_also => '^',
50
+ :derivation => '+',
51
+ :domain => ';',
52
+ :member => '-',
53
+ }
54
+
55
+ # Synset pointer indicator -> typename
56
+ POINTER_SYMBOLS = POINTER_TYPES.invert
57
+
58
+ # Map the pointer types into their own symbols (eg., :verb_group => VerbGroup)
59
+ POINTER_TYPES.each do |sym,val|
60
+ cname = sym.to_s.gsub( /(?:^|_)(.)/ ) { $1.upcase }
61
+ const_set( cname, val )
62
+ end
63
+
64
+ # Hypernym synset pointer types
65
+ HYPERNYM_TYPES = {
66
+ nil => '@', # Install non-subtype methods, too
67
+ :instance => '@i',
68
+ }
69
+
70
+ # Hypernym indicator -> type map
71
+ HYPERNYM_SYMBOLS = HYPERNYM_TYPES.invert
72
+
73
+ # Hyponym synset pointer types
74
+ HYPONYM_TYPES = {
75
+ nil => '~', # Install non-subtype methods, too
76
+ :instance => '~i',
77
+ }
78
+
79
+ # Hyponym indicator -> type map
80
+ HYPONYM_SYMBOLS = HYPONYM_TYPES.invert
81
+
82
+ # Meronym synset pointer types
83
+ MERONYM_TYPES = {
84
+ :member => '%m',
85
+ :stuff => '%s',
86
+ :portion => '%o',
87
+ :component => '%p',
88
+ :feature => '%f',
89
+ :phase => '%a',
90
+ :place => '%l',
91
+ }
92
+
93
+ # Meronym indicator -> type map
94
+ MERONYM_SYMBOLS = MERONYM_TYPES.invert
95
+
96
+ # Map the meronym types into their own constants (eg., MemberMeronym)
97
+ MERONYM_TYPES.each do |sym,val|
98
+ cname = sym.to_s.capitalize + "Meronym"
99
+ const_set( cname, val )
100
+ end
101
+
102
+ # Holonym synset pointer types
103
+ HOLONYM_TYPES = {
104
+ :member => '#m',
105
+ :stuff => '#s',
106
+ :portion => '#o',
107
+ :component => '#p',
108
+ :feature => '#f',
109
+ :phase => '#a',
110
+ :place => '#l',
111
+ }
112
+
113
+ # Holonym indicator -> type map
114
+ HOLONYM_SYMBOLS = HOLONYM_TYPES.invert
115
+
116
+ # Map the holonym types into their own constants (eg., MemberHolonym)
117
+ HOLONYM_TYPES.each do |sym,val|
118
+ cname = sym.to_s.capitalize + "Holonym"
119
+ const_set( cname, val )
120
+ end
121
+
122
+ # Domain synset pointer types
123
+ DOMAIN_TYPES = {
124
+ :category => ';c',
125
+ :region => ';r',
126
+ :usage => ';u',
127
+ }
128
+
129
+ # Domain indicator -> type map
130
+ DomainSymbols = DOMAIN_TYPES.invert
131
+
132
+ # Map the domain types into their own constants (eg., CategoryDomain)
133
+ DOMAIN_TYPES.each do |sym,val|
134
+ cname = sym.to_s.capitalize + "Domain"
135
+ const_set( cname, val )
136
+ end
137
+
138
+ # Member synset pointer types
139
+ MEMBER_TYPES = {
140
+ :category => '-c',
141
+ :region => '-r',
142
+ :usage => '-u',
143
+ }
144
+
145
+ # Member indicator -> type map
146
+ MEMBER_SYMBOLS = MEMBER_TYPES.invert
147
+
148
+ # Map the member types into their own constants (eg., CategoryMember)
149
+ MEMBER_TYPES.each do |sym,val|
150
+ cname = sym.to_s.capitalize + "Member"
151
+ const_set( cname, val )
152
+ end
153
+
154
+ # Map of primary types to maps of their subtypes
155
+ POINTER_SUBTYPES = {
156
+ :hyponym => HYPONYM_TYPES,
157
+ :hypernym => HYPERNYM_TYPES,
158
+ :meronym => MERONYM_TYPES,
159
+ :holonym => HOLONYM_TYPES,
160
+ :member => MEMBER_TYPES,
161
+ :domain => DOMAIN_TYPES,
162
+ }
163
+
164
+
165
+ # Record-part delimiter
166
+ DELIM = '||'
167
+ DELIM_RE = Regexp::new( Regexp::quote(DELIM) )
168
+
169
+ # Record-subpart delimiter
170
+ SUB_DELIM = '|'
171
+ SUB_DELIM_RE = Regexp::new( Regexp::quote(SUB_DELIM) )
172
+
173
+ # Lexicographer file index -- from lexnames(5WN)
174
+ LEXFILES = [
175
+ "adj.all",
176
+ "adj.pert",
177
+ "adv.all",
178
+ "noun.Tops",
179
+ "noun.act",
180
+ "noun.animal",
181
+ "noun.artifact",
182
+ "noun.attribute",
183
+ "noun.body",
184
+ "noun.cognition",
185
+ "noun.communication",
186
+ "noun.event",
187
+ "noun.feeling",
188
+ "noun.food",
189
+ "noun.group",
190
+ "noun.location",
191
+ "noun.motive",
192
+ "noun.object",
193
+ "noun.person",
194
+ "noun.phenomenon",
195
+ "noun.plant",
196
+ "noun.possession",
197
+ "noun.process",
198
+ "noun.quantity",
199
+ "noun.relation",
200
+ "noun.shape",
201
+ "noun.state",
202
+ "noun.substance",
203
+ "noun.time",
204
+ "verb.body",
205
+ "verb.change",
206
+ "verb.cognition",
207
+ "verb.communication",
208
+ "verb.competition",
209
+ "verb.consumption",
210
+ "verb.contact",
211
+ "verb.creation",
212
+ "verb.emotion",
213
+ "verb.motion",
214
+ "verb.perception",
215
+ "verb.possession",
216
+ "verb.social",
217
+ "verb.stative",
218
+ "verb.weather",
219
+ "adj.ppl"
220
+ ]
221
+
222
+ # Verb sentences (?) -- used in building verb frames.
223
+ VERB_SENTS = [
224
+ "",
225
+ "Something ----s",
226
+ "Somebody ----s",
227
+ "It is ----ing",
228
+ "Something is ----ing PP",
229
+ "Something ----s something Adjective/Noun",
230
+ "Something ----s Adjective/Noun",
231
+ "Somebody ----s Adjective",
232
+ "Somebody ----s something",
233
+ "Somebody ----s somebody",
234
+ "Something ----s somebody",
235
+ "Something ----s something",
236
+ "Something ----s to somebody",
237
+ "Somebody ----s on something",
238
+ "Somebody ----s somebody something",
239
+ "Somebody ----s something to somebody",
240
+ "Somebody ----s something from somebody",
241
+ "Somebody ----s somebody with something",
242
+ "Somebody ----s somebody of something",
243
+ "Somebody ----s something on somebody",
244
+ "Somebody ----s somebody PP",
245
+ "Somebody ----s something PP",
246
+ "Somebody ----s PP",
247
+ "Somebody's (body part) ----s",
248
+ "Somebody ----s somebody to INFINITIVE",
249
+ "Somebody ----s somebody INFINITIVE",
250
+ "Somebody ----s that CLAUSE",
251
+ "Somebody ----s to somebody",
252
+ "Somebody ----s to INFINITIVE",
253
+ "Somebody ----s whether INFINITIVE",
254
+ "Somebody ----s somebody into V-ing something",
255
+ "Somebody ----s something with something",
256
+ "Somebody ----s INFINITIVE",
257
+ "Somebody ----s VERB-ing",
258
+ "It ----s that CLAUSE",
259
+ "Something ----s INFINITIVE"
260
+ ]
261
+
262
+
263
+ end # module Wordnet::Constants
264
+
@@ -0,0 +1,34 @@
1
+ #!/usr/bin/ruby
2
+
3
+ require 'wordnet' unless defined?( WordNet )
4
+ require 'wordnet/synset' unless defined?( WordNet::Synset )
5
+ require 'wordnet/model'
6
+
7
+ # WordNet lexical link (pointer) model class
8
+ class WordNet::LexicalLink < WordNet::Model( :lexlinks )
9
+ include WordNet::Constants
10
+
11
+ set_primary_key [:word1id, :synset1id, :word2id, :synset2id, :linkid]
12
+
13
+ many_to_one :origin,
14
+ :class => :"WordNet::Sense",
15
+ :key => :synset1id,
16
+ :primary_key => :synsetid
17
+
18
+ one_to_many :target,
19
+ :class => :"WordNet::Synset",
20
+ :key => :synsetid,
21
+ :primary_key => :synset2id
22
+
23
+
24
+ ######
25
+ public
26
+ ######
27
+
28
+ ### Return the type of link this is as a Symbol.
29
+ def type
30
+ return WordNet::Synset.linktype_table[ self.linkid ][ :type ]
31
+ end
32
+
33
+ end # class WordNet::SemanticLink
34
+