wordnet 1.0.0.pre.136 → 1.0.0.pre.139
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.tar.gz.sig +0 -0
- data/History.rdoc +1 -1
- data/README.rdoc +50 -11
- data/Rakefile +7 -0
- data/lib/wordnet.rb +2 -2
- data/lib/wordnet/lexicallink.rb +4 -0
- data/lib/wordnet/lexicon.rb +154 -35
- data/lib/wordnet/model.rb +1 -1
- data/lib/wordnet/morph.rb +28 -3
- data/lib/wordnet/sumoterm.rb +58 -3
- data/lib/wordnet/synset.rb +48 -26
- data/lib/wordnet/word.rb +17 -0
- data/spec/lib/helpers.rb +12 -0
- data/spec/wordnet/lexicon_spec.rb +65 -15
- data/spec/wordnet/semanticlink_spec.rb +21 -7
- data/spec/wordnet/synset_spec.rb +36 -17
- data/spec/wordnet/word_spec.rb +91 -16
- metadata +29 -25
- metadata.gz.sig +0 -0
data.tar.gz.sig
CHANGED
Binary file
|
data/History.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -4,25 +4,64 @@
|
|
4
4
|
|
5
5
|
== Description
|
6
6
|
|
7
|
-
This library is a Ruby interface to WordNet
|
8
|
-
lexical reference system whose design is inspired
|
9
|
-
psycholinguistic theories of human lexical memory. English
|
10
|
-
adjectives and adverbs are organized into synonym sets, each
|
7
|
+
This library is a Ruby interface to WordNet®[http://wordnet.princeton.edu/].
|
8
|
+
WordNet® is an online lexical reference system whose design is inspired
|
9
|
+
by current psycholinguistic theories of human lexical memory. English
|
10
|
+
nouns, verbs, adjectives and adverbs are organized into synonym sets, each
|
11
11
|
representing one underlying lexical concept. Different relations link
|
12
12
|
the synonym sets.
|
13
13
|
|
14
|
-
|
15
|
-
a relational database format. You
|
16
|
-
defaultdb' gem, which packages up the
|
17
|
-
install your own and point the lexicon
|
18
|
-
|
14
|
+
This library uses WordNet-SQL[http://wnsql.sourceforge.net/], which is a
|
15
|
+
conversion of the lexicon flatfiles into a relational database format. You
|
16
|
+
can either install the 'wordnet-defaultdb' gem, which packages up the
|
17
|
+
SQLite3 version of WordNet-SQL, or install your own and point the lexicon
|
18
|
+
at it by passing
|
19
|
+
{Sequel connection parameters}[http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html]
|
20
|
+
to the constructor.
|
19
21
|
|
22
|
+
=== Usage
|
23
|
+
|
24
|
+
There are three major parts to this library:
|
25
|
+
|
26
|
+
[WordNet::Lexicon] the interface to the dictionary, used to connect to the
|
27
|
+
database and look up Words and Synsets.
|
28
|
+
[WordNet::Word] the English word entries in the Lexicon that are mapped
|
29
|
+
to Synsets via one or more Senses.
|
30
|
+
[WordNet::Synset] the main artifact of WordNet: a "synonym set". These
|
31
|
+
are connected to one or more Words through a Sense,
|
32
|
+
and are connected to each other via SemanticLinks.
|
33
|
+
|
34
|
+
The other object classes exist mostly as a way of representing relationships
|
35
|
+
between the main three:
|
36
|
+
|
37
|
+
[WordNet::Sense] represents a link between one or more Words and
|
38
|
+
one or more Synsets for one meaning of the word.
|
39
|
+
[WordNet::SemanticLink] represents a link between Synsets
|
40
|
+
[WordNet::LexicalLink] represents a link between Words in Synsets
|
41
|
+
[WordNet::Morph] an interface to a lookup table of irregular word
|
42
|
+
forms mapped to their base form (lemma)
|
43
|
+
|
44
|
+
The last class (WordNet::Model) is the abstract superclass for all the others,
|
45
|
+
and inherits most of its functionality from Sequel::Model, the ORM layer
|
46
|
+
of the Sequel toolkit. It's mostly just a container for the database
|
47
|
+
connection, with some convenience methods to allow the database connection
|
48
|
+
to be deferred until runtime instead of when the library loads.
|
49
|
+
|
50
|
+
The library also comes with the beginnings of support for the SUMO-WordNet
|
51
|
+
mapping:
|
52
|
+
|
53
|
+
[WordNet::SumoTerm] {Suggested Upper Merged Ontology}[http://www.ontologyportal.org/]
|
54
|
+
terms, with associations back to related Synsets.
|
55
|
+
|
56
|
+
This is only supported by a subset of the WordNetSQL databases, and there
|
57
|
+
is a fair amount of work left to be done before it's really functional. Drop
|
58
|
+
me a note if you're interested in working on this.
|
20
59
|
|
21
60
|
|
22
61
|
== Requirements
|
23
62
|
|
24
|
-
* Ruby >= 1.9.
|
25
|
-
* Sequel >= 3.
|
63
|
+
* Ruby >= 1.9.3
|
64
|
+
* Sequel >= 3.38.0
|
26
65
|
|
27
66
|
|
28
67
|
== Authors
|
data/Rakefile
CHANGED
@@ -32,6 +32,7 @@ hoespec = Hoe.spec( 'wordnet' ) do
|
|
32
32
|
self.dependency 'loggability', '~> 0.5'
|
33
33
|
self.dependency 'sqlite3', '~> 1.3', :developer
|
34
34
|
self.dependency 'rspec', '~> 2.7', :developer
|
35
|
+
self.dependency 'simplecov', '~> 0.6', :developer
|
35
36
|
|
36
37
|
self.spec_extras[:licenses] = ["BSD"]
|
37
38
|
self.spec_extras[:post_install_message] = %{
|
@@ -74,3 +75,9 @@ end
|
|
74
75
|
# Rebuild the ChangeLog immediately before release
|
75
76
|
task :prerelease => 'ChangeLog'
|
76
77
|
|
78
|
+
# Simplecov
|
79
|
+
desc "Build a coverage report"
|
80
|
+
task :coverage do
|
81
|
+
ENV["COVERAGE"] = 'yes'
|
82
|
+
Rake::Task[:spec].invoke
|
83
|
+
end
|
data/lib/wordnet.rb
CHANGED
@@ -21,8 +21,8 @@ module WordNet
|
|
21
21
|
REVISION = %q$Revision: $
|
22
22
|
|
23
23
|
# Abort if not >=1.9.2
|
24
|
-
abort "This version of WordNet requires Ruby 1.9.
|
25
|
-
RUBY_VERSION >= '1.9.
|
24
|
+
abort "This version of WordNet requires Ruby 1.9.3 or greater." unless
|
25
|
+
RUBY_VERSION >= '1.9.3'
|
26
26
|
|
27
27
|
|
28
28
|
### Lexicon exception - something has gone wrong in the internals of the
|
data/lib/wordnet/lexicallink.rb
CHANGED
@@ -10,11 +10,15 @@ class WordNet::LexicalLink < WordNet::Model( :lexlinks )
|
|
10
10
|
|
11
11
|
set_primary_key [:word1id, :synset1id, :word2id, :synset2id, :linkid]
|
12
12
|
|
13
|
+
##
|
14
|
+
# The WordNet::Sense the link is pointing *from*.
|
13
15
|
many_to_one :origin,
|
14
16
|
:class => :"WordNet::Sense",
|
15
17
|
:key => :synset1id,
|
16
18
|
:primary_key => :synsetid
|
17
19
|
|
20
|
+
##
|
21
|
+
# The WordNet::Synset the link is pointing *to*.
|
18
22
|
one_to_many :target,
|
19
23
|
:class => :"WordNet::Synset",
|
20
24
|
:key => :synsetid,
|
data/lib/wordnet/lexicon.rb
CHANGED
@@ -10,8 +10,115 @@ require 'wordnet/synset'
|
|
10
10
|
require 'wordnet/word'
|
11
11
|
|
12
12
|
|
13
|
-
# WordNet lexicon class -
|
14
|
-
# database, and provides factory methods for looking up words
|
13
|
+
# WordNet lexicon class - provides access to the WordNet lexical
|
14
|
+
# database, and provides factory methods for looking up words[rdoc-ref:WordNet::Word]
|
15
|
+
# and synsets[rdoc-ref:WordNet::Synset].
|
16
|
+
#
|
17
|
+
# == Creating a Lexicon
|
18
|
+
#
|
19
|
+
# To create a Lexicon, either point it at a database using [Sequel database connection
|
20
|
+
# criteria]{http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html}:
|
21
|
+
#
|
22
|
+
# lex = WordNet::Lexicon.new( 'postgres://localhost/wordnet30' )
|
23
|
+
# # => #<WordNet::Lexicon:0x7fd192a76668 postgres://localhost/wordnet30>
|
24
|
+
#
|
25
|
+
# # Another way of doing the same thing:
|
26
|
+
# lex = WordNet::Lexicon.new( adapter: 'postgres', database: 'wordnet30', host: 'localhost' )
|
27
|
+
# # => #<WordNet::Lexicon:0x7fd192d374b0 postgres>
|
28
|
+
#
|
29
|
+
# Alternatively, if you have the 'wordnet-defaultdb' gem (which includes an
|
30
|
+
# embedded copy of the SQLite WordNET-SQL database) installed, just call ::new
|
31
|
+
# without any arguments:
|
32
|
+
#
|
33
|
+
# lex = WordNet::Lexicon.new
|
34
|
+
# # => #<WordNet::Lexicon:0x7fdbfac1a358 sqlite:[...]/gems/wordnet-defaultdb-1.0.1
|
35
|
+
# # /data/wordnet-defaultdb/wordnet30.sqlite>
|
36
|
+
#
|
37
|
+
# == Looking Up Synsets
|
38
|
+
#
|
39
|
+
# Once you have a Lexicon created, the main lookup method for Synsets is
|
40
|
+
# #[], which will return the first of any Synsets that are found:
|
41
|
+
#
|
42
|
+
# synset = lex[ :language ]
|
43
|
+
# # => #<WordNet::Synset:0x7fdbfaa987a0 {105650820} 'language, speech' (noun):
|
44
|
+
# # [noun.cognition] the mental faculty or power of vocal communication>
|
45
|
+
#
|
46
|
+
# If you want to look up *all* matching Synsets, use the #lookup_synsets
|
47
|
+
# method:
|
48
|
+
#
|
49
|
+
# synsets = lex.lookup_synsets( :language )
|
50
|
+
# # => [#<WordNet::Synset:0x7fdbfaac46c0 {105650820} 'language, speech' (noun):
|
51
|
+
# # [noun.cognition] the mental faculty or power of vocal
|
52
|
+
# # communication>,
|
53
|
+
# # #<WordNet::Synset:0x7fdbfaac45a8 {105808557} 'language, linguistic process'
|
54
|
+
# # (noun): [noun.cognition] the cognitive processes involved
|
55
|
+
# # in producing and understanding linguistic communication>,
|
56
|
+
# # #<WordNet::Synset:0x7fdbfaac4490 {106282651} 'language, linguistic
|
57
|
+
# # communication' (noun): [noun.communication] a systematic means of
|
58
|
+
# # communicating by the use of sounds or conventional symbols>,
|
59
|
+
# # #<WordNet::Synset:0x7fdbfaac4378 {106304059} 'language, nomenclature,
|
60
|
+
# # terminology' (noun): [noun.communication] a system of words used to
|
61
|
+
# # name things in a particular discipline>,
|
62
|
+
# # #<WordNet::Synset:0x7fdbfaac4260 {107051975} 'language, lyric, words'
|
63
|
+
# # (noun): [noun.communication] the text of a popular song or musical-comedy
|
64
|
+
# # number>,
|
65
|
+
# # #<WordNet::Synset:0x7fdbfaac4120 {107109196} 'language, oral communication,
|
66
|
+
# # speech, speech communication, spoken communication, spoken language,
|
67
|
+
# # voice communication' (noun): [noun.communication] (language)
|
68
|
+
# # communication by word of mouth>]
|
69
|
+
#
|
70
|
+
# Sometime, the first Synset isn't necessarily what you want; you want to look up
|
71
|
+
# a particular one. Both #[] and #lookup_synsets also provide several
|
72
|
+
# ways of filtering or selecting synsets.
|
73
|
+
#
|
74
|
+
# The first is the ability to select one based on its offset:
|
75
|
+
#
|
76
|
+
# lex[ :language, 2 ]
|
77
|
+
# # => #<WordNet::Synset:0x7ffa78e74d78 {105808557} 'language, linguistic
|
78
|
+
# # process' (noun): [noun.cognition] the cognitive processes involved in
|
79
|
+
# # producing and understanding linguistic communication>
|
80
|
+
#
|
81
|
+
# You can also select one with a particular word in its definition:
|
82
|
+
#
|
83
|
+
# lex[ :language, 'sounds' ]
|
84
|
+
# # => #<WordNet::Synset:0x7ffa78ee01b8 {106282651} 'linguistic communication,
|
85
|
+
# # language' (noun): [noun.communication] a systematic means of
|
86
|
+
# # communicating by the use of sounds or conventional symbols>
|
87
|
+
#
|
88
|
+
# If you're using a database that supports using regular expressions (e.g.,
|
89
|
+
# PostgreSQL), you can use that to select one with a matching definition:
|
90
|
+
#
|
91
|
+
# lex[ :language, %r:name.*discipline: ]
|
92
|
+
# # => #<WordNet::Synset:0x7ffa78f235a8 {106304059} 'language, nomenclature,
|
93
|
+
# # terminology' (noun): [noun.communication] a system of words used
|
94
|
+
# # to name things in a particular discipline>
|
95
|
+
#
|
96
|
+
# You can also select certain parts of speech:
|
97
|
+
#
|
98
|
+
# lex[ :right, :noun ]
|
99
|
+
# # => #<WordNet::Synset:0x7ffa78f30b68 {100351000} 'right' (noun):
|
100
|
+
# # [noun.act] a turn toward the side of the body that is on the south
|
101
|
+
# # when the person is facing east>
|
102
|
+
# lex[ :right, :verb ]
|
103
|
+
# # => #<WordNet::Synset:0x7ffa78f09590 {200199659} 'correct, right, rectify'
|
104
|
+
# # (verb): [verb.change] make right or correct>
|
105
|
+
# lex[ :right, :adjective ]
|
106
|
+
# # => #<WordNet::Synset:0x7ffa78ea8060 {300631391} 'correct, right'
|
107
|
+
# # (adjective): [adj.all] free from error; especially conforming to
|
108
|
+
# # fact or truth>
|
109
|
+
# lex[ :right, :adverb ]
|
110
|
+
# # => #<WordNet::Synset:0x7ffa78e5b2d8 {400032299} 'powerful, mightily,
|
111
|
+
# # mighty, right' (adverb): [adv.all] (Southern regional intensive)
|
112
|
+
# # very; to a great degree>
|
113
|
+
#
|
114
|
+
# or by lexical domain, which is a more-specific part of speech (see
|
115
|
+
# <tt>WordNet::Synset.lexdomains.keys</tt> for the list of valid ones):
|
116
|
+
#
|
117
|
+
# lex.lookup_synsets( :right, 'verb.social' )
|
118
|
+
# # => [#<WordNet::Synset:0x7ffa78d817e0 {202519991} 'redress, compensate,
|
119
|
+
# # correct, right' (verb): [verb.social] make reparations or amends
|
120
|
+
# # for>]
|
121
|
+
#
|
15
122
|
class WordNet::Lexicon
|
16
123
|
extend Loggability
|
17
124
|
include WordNet::Constants
|
@@ -19,19 +126,9 @@ class WordNet::Lexicon
|
|
19
126
|
# Loggability API -- log to the WordNet module's logger
|
20
127
|
log_to :wordnet
|
21
128
|
|
22
|
-
# class LogTracer
|
23
|
-
# def method_missing( sym, msg, &block )
|
24
|
-
# if msg =~ /does not exist/
|
25
|
-
# $stderr.puts ">>> DOES NOT EXIST TRACE"
|
26
|
-
# $stderr.puts( caller(1).grep(/wordnet/i) )
|
27
|
-
# end
|
28
|
-
# end
|
29
|
-
# end
|
30
|
-
|
31
129
|
|
32
130
|
# Add the logger device to the default options after it's been loaded
|
33
131
|
WordNet::DEFAULT_DB_OPTIONS.merge!( :logger => [Loggability[WordNet]] )
|
34
|
-
# WordNet::DEFAULT_DB_OPTIONS.merge!( :logger => [LogTracer.new] )
|
35
132
|
|
36
133
|
|
37
134
|
### Get the Sequel URI of the default database, if it's installed.
|
@@ -73,35 +170,53 @@ class WordNet::Lexicon
|
|
73
170
|
### Create a new WordNet::Lexicon object that will use the database connection specified by
|
74
171
|
### the given +dbconfig+.
|
75
172
|
def initialize( *args )
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
173
|
+
if args.empty?
|
174
|
+
self.initialize_with_defaultdb( args.shift )
|
175
|
+
elsif args.first.is_a?( String )
|
176
|
+
self.initialize_with_uri( *args )
|
177
|
+
else
|
178
|
+
self.initialize_with_opthash( args.shift )
|
179
|
+
end
|
180
|
+
|
181
|
+
@db.sql_log_level = :debug
|
182
|
+
WordNet::Model.db = @db
|
183
|
+
end
|
184
|
+
|
185
|
+
|
186
|
+
### Connect to the WordNet DB using an optional options hash.
|
187
|
+
def initialize_with_defaultdb( options )
|
188
|
+
uri = WordNet::Lexicon.default_db_uri or raise WordNet::LexiconError,
|
189
|
+
"No default WordNetSQL database! You can install it via the " +
|
190
|
+
"wordnet-defaultdb gem, or download a version yourself from " +
|
191
|
+
"http://sourceforge.net/projects/wnsql/"
|
192
|
+
@db = self.connect( uri, options )
|
193
|
+
end
|
88
194
|
|
89
|
-
|
195
|
+
|
196
|
+
### Connect to the WordNet DB using a URI and an optional options hash.
|
197
|
+
def initialize_with_uri( uri, options )
|
198
|
+
@db = self.connect( uri, options )
|
199
|
+
end
|
200
|
+
|
201
|
+
|
202
|
+
### Connect to the WordNet DB using a connection options hash.
|
203
|
+
def initialize_with_opthash( options )
|
204
|
+
@db = self.connect( nil, options )
|
205
|
+
end
|
206
|
+
|
207
|
+
|
208
|
+
### Connect to the WordNet DB and return a Sequel::Database object.
|
209
|
+
def connect( uri, options )
|
210
|
+
options = WordNet::DEFAULT_DB_OPTIONS.merge( options || {} )
|
90
211
|
|
91
212
|
if uri
|
92
213
|
self.log.debug "Connecting using uri + options style: uri = %s, options = %p" %
|
93
214
|
[ uri, options ]
|
94
|
-
|
215
|
+
return Sequel.connect( uri, options )
|
95
216
|
else
|
96
217
|
self.log.debug "Connecting using hash style connect: options = %p" % [ options ]
|
97
|
-
|
218
|
+
return Sequel.connect( options )
|
98
219
|
end
|
99
|
-
|
100
|
-
@uri = @db.uri
|
101
|
-
self.log.debug " setting model db to: %s" % [ @uri ]
|
102
|
-
|
103
|
-
@db.sql_log_level = :debug
|
104
|
-
WordNet::Model.db = @db
|
105
220
|
end
|
106
221
|
|
107
222
|
|
@@ -175,7 +290,7 @@ class WordNet::Lexicon
|
|
175
290
|
|
176
291
|
when Range
|
177
292
|
self.log.debug " limiting to range of senses: %p" % [ arg ]
|
178
|
-
dataset = dataset.limit( arg.
|
293
|
+
dataset = dataset.limit( arg.entries.length, arg.begin - 1 )
|
179
294
|
|
180
295
|
when Regexp
|
181
296
|
self.log.debug " filter: definition =~ %p" % [ arg ]
|
@@ -213,7 +328,11 @@ class WordNet::Lexicon
|
|
213
328
|
### Return a human-readable string representation of the Lexicon, suitable for
|
214
329
|
### debugging.
|
215
330
|
def inspect
|
216
|
-
return "#<%p:%0#x %s>" % [
|
331
|
+
return "#<%p:%0#x %s>" % [
|
332
|
+
self.class,
|
333
|
+
self.object_id * 2,
|
334
|
+
self.db.url || self.db.adapter_scheme
|
335
|
+
]
|
217
336
|
end
|
218
337
|
|
219
338
|
|
data/lib/wordnet/model.rb
CHANGED
@@ -46,7 +46,7 @@ module WordNet
|
|
46
46
|
end
|
47
47
|
|
48
48
|
self.descendents.each do |subclass|
|
49
|
-
self.log.
|
49
|
+
self.log.debug "Resetting database connection for: %p to: %p" % [ subclass, newdb ]
|
50
50
|
subclass.db = newdb
|
51
51
|
end
|
52
52
|
end
|
data/lib/wordnet/morph.rb
CHANGED
@@ -7,12 +7,37 @@ require 'wordnet/model'
|
|
7
7
|
class WordNet::Morph < WordNet::Model( :morphs )
|
8
8
|
include WordNet::Constants
|
9
9
|
|
10
|
+
# Table "public.morphs"
|
11
|
+
# Column | Type | Modifiers
|
12
|
+
# ---------+-----------------------+--------------------
|
13
|
+
# morphid | integer | not null default 0
|
14
|
+
# morph | character varying(70) | not null
|
15
|
+
# Indexes:
|
16
|
+
# "pk_morphs" PRIMARY KEY, btree (morphid)
|
17
|
+
# "unq_morphs_morph" UNIQUE, btree (morph)
|
18
|
+
# Referenced by:
|
19
|
+
# TABLE "morphmaps" CONSTRAINT "fk_morphmaps_morphid" FOREIGN KEY (morphid) REFERENCES morphs(morphid)
|
20
|
+
#
|
21
|
+
|
10
22
|
set_primary_key :morphid
|
11
23
|
|
12
|
-
|
24
|
+
# Table "public.morphmaps"
|
25
|
+
# Column | Type | Modifiers
|
26
|
+
# ---------+--------------+-------------------------------
|
27
|
+
# wordid | integer | not null default 0
|
28
|
+
# pos | character(1) | not null default NULL::bpchar
|
29
|
+
# morphid | integer | not null default 0
|
30
|
+
# Indexes:
|
31
|
+
# "pk_morphmaps" PRIMARY KEY, btree (morphid, pos, wordid)
|
32
|
+
# "k_morphmaps_morphid" btree (morphid)
|
33
|
+
# "k_morphmaps_wordid" btree (wordid)
|
34
|
+
# Foreign-key constraints:
|
35
|
+
# "fk_morphmaps_morphid" FOREIGN KEY (morphid) REFERENCES morphs(morphid)
|
36
|
+
# "fk_morphmaps_wordid" FOREIGN KEY (wordid) REFERENCES words(wordid)
|
37
|
+
many_to_many :words,
|
13
38
|
:join_table => :morphmaps,
|
14
|
-
:
|
15
|
-
:
|
39
|
+
:right_key => :wordid,
|
40
|
+
:left_key => :morphid
|
16
41
|
|
17
42
|
|
18
43
|
### Return the stringified word; alias for #lemma.
|
data/lib/wordnet/sumoterm.rb
CHANGED
@@ -5,17 +5,72 @@ require 'wordnet/model'
|
|
5
5
|
require 'wordnet/constants'
|
6
6
|
|
7
7
|
|
8
|
-
#
|
8
|
+
# Experimental support for the WordNet mapping for the {Suggested Upper Merged
|
9
|
+
# Ontology}[http://www.ontologyportal.org/] (SUMO).
|
10
|
+
# This is still a work in progress, and isn't supported by all of the WordNet-SQL
|
11
|
+
# databases.
|
9
12
|
class WordNet::SumoTerm < WordNet::Model( :sumoterms )
|
10
13
|
include WordNet::Constants
|
11
14
|
|
15
|
+
# Table "public.sumoterms"
|
16
|
+
# Column | Type | Modifiers
|
17
|
+
# -----------------------+------------------------+--------------------
|
18
|
+
# sumoid | integer | not null default 0
|
19
|
+
# sumoterm | character varying(128) | not null
|
20
|
+
# ischildofattribute | boolean |
|
21
|
+
# ischildoffunction | boolean |
|
22
|
+
# ischildofpredicate | boolean |
|
23
|
+
# ischildofrelation | boolean |
|
24
|
+
# iscomparisonop | boolean |
|
25
|
+
# isfunction | boolean |
|
26
|
+
# isinstance | boolean |
|
27
|
+
# islogical | boolean |
|
28
|
+
# ismath | boolean |
|
29
|
+
# isquantifier | boolean |
|
30
|
+
# isrelationop | boolean |
|
31
|
+
# issubclass | boolean |
|
32
|
+
# issubclassofattribute | boolean |
|
33
|
+
# issubclassoffunction | boolean |
|
34
|
+
# issubclassofpredicate | boolean |
|
35
|
+
# issubclassofrelation | boolean |
|
36
|
+
# issubrelation | boolean |
|
37
|
+
# issuperclass | boolean |
|
38
|
+
# issuperrelation | boolean |
|
39
|
+
# Indexes:
|
40
|
+
# "pk_sumoterms" PRIMARY KEY, btree (sumoid)
|
41
|
+
# "unq_sumoterms_sumoterm" UNIQUE, btree (sumoterm)
|
42
|
+
# Referenced by:
|
43
|
+
# TABLE "sumomaps" CONSTRAINT "fk_sumomaps_sumoid" FOREIGN KEY (sumoid) REFERENCES sumoterms(sumoid)
|
44
|
+
# TABLE "sumoparsemaps" CONSTRAINT "fk_sumoparsemaps_sumoid" FOREIGN KEY (sumoid) REFERENCES sumoterms(sumoid)
|
12
45
|
set_primary_key :sumoid
|
13
46
|
|
47
|
+
|
48
|
+
#
|
49
|
+
# Associations
|
50
|
+
#
|
51
|
+
|
14
52
|
# SUMO Term -> [ SUMO Map ] -> [ Synset ]
|
53
|
+
|
54
|
+
# Table "public.sumomaps"
|
55
|
+
# Column | Type | Modifiers
|
56
|
+
# -----------+--------------+--------------------
|
57
|
+
# synsetid | integer | not null default 0
|
58
|
+
# sumoid | integer | not null default 0
|
59
|
+
# sumownrel | character(1) | not null
|
60
|
+
# Indexes:
|
61
|
+
# "pk_sumomaps" PRIMARY KEY, btree (synsetid)
|
62
|
+
# "k_sumomaps_sumoid" btree (sumoid)
|
63
|
+
# "k_sumomaps_sumownrel" btree (sumownrel)
|
64
|
+
# Foreign-key constraints:
|
65
|
+
# "fk_sumomaps_sumoid" FOREIGN KEY (sumoid) REFERENCES sumoterms(sumoid)
|
66
|
+
# "fk_sumomaps_synsetid" FOREIGN KEY (synsetid) REFERENCES synsets(synsetid)
|
67
|
+
|
68
|
+
##
|
69
|
+
# WordNet::Synsets that are related to this term
|
15
70
|
many_to_many :synsets,
|
16
71
|
:join_table => :sumomaps,
|
17
|
-
:left_key
|
18
|
-
:right_key
|
72
|
+
:left_key => :sumoid,
|
73
|
+
:right_key => :synsetid
|
19
74
|
|
20
75
|
end # class WordNet::SumoTerm
|
21
76
|
|
data/lib/wordnet/synset.rb
CHANGED
@@ -11,31 +11,53 @@ require 'wordnet/model'
|
|
11
11
|
# WordNet lexical database. A synonym set is a set of words that are
|
12
12
|
# interchangeable in some context.
|
13
13
|
#
|
14
|
-
#
|
15
|
-
# # => #<WordNet::Synset @values={:synsetid=>106286395, :pos=>"n",
|
16
|
-
# :lexdomainid=>10,
|
17
|
-
# :definition=>"a unit of language that native speakers can identify"}>
|
14
|
+
# We can either fetch the synset from a connected Lexicon:
|
18
15
|
#
|
19
|
-
#
|
20
|
-
#
|
16
|
+
# lexicon = WordNet::Lexicon.new( 'postgres://localhost/wordnet30' )
|
17
|
+
# ss = lexicon[ :first, 'time' ]
|
18
|
+
# # => #<WordNet::Synset:0x7ffbf2643bb0 {115265518} 'commencement, first,
|
19
|
+
# # get-go, offset, outset, start, starting time, beginning, kickoff,
|
20
|
+
# # showtime' (noun): [noun.time] the time at which something is
|
21
|
+
# # supposed to begin>
|
21
22
|
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
# :lexdomainid=>10,
|
25
|
-
# :definition=>"one of the natural units into which [...]"}>]
|
23
|
+
# or if you've already created a Lexicon, use its connection indirectly to
|
24
|
+
# look up a Synset by its ID:
|
26
25
|
#
|
27
|
-
#
|
28
|
-
#
|
29
|
-
#
|
30
|
-
# :
|
31
|
-
#
|
32
|
-
#
|
33
|
-
#
|
34
|
-
#
|
35
|
-
#
|
36
|
-
#
|
37
|
-
#
|
38
|
-
# ]
|
26
|
+
# ss = WordNet::Synset[ 115265518 ]
|
27
|
+
# # => #<WordNet::Synset:0x7ffbf257e928 {115265518} 'commencement, first,
|
28
|
+
# # get-go, offset, outset, start, starting time, beginning, kickoff,
|
29
|
+
# # showtime' (noun): [noun.time] the time at which something is
|
30
|
+
# # supposed to begin>
|
31
|
+
#
|
32
|
+
# You can fetch a list of the lemmas (base forms) of the words included in the
|
33
|
+
# synset:
|
34
|
+
#
|
35
|
+
# ss.words.map( &:lemma )
|
36
|
+
# # => ["commencement", "first", "get-go", "offset", "outset", "start",
|
37
|
+
# # "starting time", "beginning", "kickoff", "showtime"]
|
38
|
+
#
|
39
|
+
# But the primary reason for a synset is its lexical and semantic links to
|
40
|
+
# other words and synsets. For instance, its *hypernym* is the equivalent
|
41
|
+
# of its superclass: it's the class of things of which the receiving
|
42
|
+
# synset is a member.
|
43
|
+
#
|
44
|
+
# ss.hypernyms
|
45
|
+
# # => [#<WordNet::Synset:0x7ffbf25c76c8 {115180528} 'point, point in
|
46
|
+
# # time' (noun): [noun.time] an instant of time>]
|
47
|
+
#
|
48
|
+
# The synset's *hypernyms*, on the other hand, are kind of like its
|
49
|
+
# subclasses:
|
50
|
+
#
|
51
|
+
# ss.hyponyms
|
52
|
+
# # => [#<WordNet::Synset:0x7ffbf25d83b0 {115142167} 'birth' (noun):
|
53
|
+
# # [noun.time] the time when something begins (especially life)>,
|
54
|
+
# # #<WordNet::Synset:0x7ffbf25d8298 {115268993} 'threshold' (noun):
|
55
|
+
# # [noun.time] the starting point for a new state or experience>,
|
56
|
+
# # #<WordNet::Synset:0x7ffbf25d8180 {115143012} 'incipiency,
|
57
|
+
# # incipience' (noun): [noun.time] beginning to exist or to be
|
58
|
+
# # apparent>,
|
59
|
+
# # #<WordNet::Synset:0x7ffbf25d8068 {115266164} 'starting point,
|
60
|
+
# # terminus a quo' (noun): [noun.time] earliest limiting point>]
|
39
61
|
#
|
40
62
|
class WordNet::Synset < WordNet::Model( :synsets )
|
41
63
|
include WordNet::Constants
|
@@ -313,12 +335,12 @@ class WordNet::Synset < WordNet::Model( :synsets )
|
|
313
335
|
|
314
336
|
|
315
337
|
### Return any sample sentences.
|
316
|
-
|
317
|
-
|
338
|
+
def samples
|
339
|
+
return self.db[:samples].
|
318
340
|
filter( synsetid: self.synsetid ).
|
319
341
|
order( :sampleid ).
|
320
|
-
map( :sample )
|
321
|
-
|
342
|
+
map( :sample )
|
343
|
+
end
|
322
344
|
|
323
345
|
|
324
346
|
#
|
data/lib/wordnet/word.rb
CHANGED
@@ -58,6 +58,10 @@ class WordNet::Word < WordNet::Model( :words )
|
|
58
58
|
|
59
59
|
set_primary_key :wordid
|
60
60
|
|
61
|
+
#
|
62
|
+
# Associations
|
63
|
+
#
|
64
|
+
|
61
65
|
##
|
62
66
|
# The WordNet::Sense objects that relate the word with its Synsets
|
63
67
|
one_to_many :senses,
|
@@ -79,6 +83,19 @@ class WordNet::Word < WordNet::Model( :words )
|
|
79
83
|
:right_key => :morphid
|
80
84
|
|
81
85
|
|
86
|
+
#
|
87
|
+
# Dataset methods
|
88
|
+
#
|
89
|
+
|
90
|
+
##
|
91
|
+
# Return a dataset for words matching the given +lemma+.
|
92
|
+
def_dataset_method( :by_lemma ) {|lemma| filter( lemma: lemma ) }
|
93
|
+
|
94
|
+
|
95
|
+
#
|
96
|
+
# Other methods
|
97
|
+
#
|
98
|
+
|
82
99
|
### Return the stringified word; alias for #lemma.
|
83
100
|
def to_s
|
84
101
|
return self.lemma
|
data/spec/lib/helpers.rb
CHANGED
@@ -11,6 +11,18 @@ BEGIN {
|
|
11
11
|
$LOAD_PATH.unshift( libdir.to_s ) unless $LOAD_PATH.include?( libdir.to_s )
|
12
12
|
}
|
13
13
|
|
14
|
+
# SimpleCov test coverage reporting; enable this using the :coverage rake task
|
15
|
+
if ENV['COVERAGE']
|
16
|
+
$stderr.puts "\n\n>>> Enabling coverage report.\n\n"
|
17
|
+
require 'simplecov'
|
18
|
+
SimpleCov.start do
|
19
|
+
add_filter 'spec'
|
20
|
+
add_group "Needing tests" do |file|
|
21
|
+
file.covered_percent < 90
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
14
26
|
require 'rspec'
|
15
27
|
require 'loggability/spechelpers'
|
16
28
|
require 'wordnet'
|
@@ -33,6 +33,7 @@ describe WordNet::Lexicon do
|
|
33
33
|
reset_logging()
|
34
34
|
end
|
35
35
|
|
36
|
+
|
36
37
|
context "the default_db_uri method" do
|
37
38
|
|
38
39
|
it "uses the wordnet-defaultdb database gem (if available)" do
|
@@ -80,77 +81,126 @@ describe WordNet::Lexicon do
|
|
80
81
|
|
81
82
|
context "with the default database", :requires_database => true do
|
82
83
|
|
83
|
-
|
84
|
-
@lexicon = WordNet::Lexicon.new
|
85
|
-
end
|
84
|
+
let( :lexicon ) { WordNet::Lexicon.new }
|
86
85
|
|
87
86
|
context "via its index operator" do
|
88
87
|
|
89
88
|
it "can look up a Synset by ID" do
|
90
|
-
rval =
|
89
|
+
rval = lexicon[ 101219722 ]
|
91
90
|
rval.should be_a( WordNet::Synset )
|
92
91
|
rval.words.map( &:to_s ).should include( 'carrot' )
|
93
92
|
end
|
94
93
|
|
95
94
|
it "can look up a Word by ID" do
|
96
|
-
rval =
|
95
|
+
rval = lexicon[ 21338 ]
|
97
96
|
rval.should be_a( WordNet::Word )
|
98
97
|
rval.lemma.should == 'carrot'
|
99
98
|
end
|
100
99
|
|
101
100
|
it "can look up the synset for a word and a sense" do
|
102
|
-
ss =
|
101
|
+
ss = lexicon[ :boot, 3 ]
|
103
102
|
ss.should be_a( WordNet::Synset )
|
104
103
|
ss.definition.should == 'footwear that covers the whole foot and lower leg'
|
105
104
|
end
|
106
105
|
|
106
|
+
it "can look up all synsets for a particular word" do
|
107
|
+
sss = lexicon.lookup_synsets( :tree )
|
108
|
+
sss.should have( 7 ).members
|
109
|
+
sss.all? {|ss| ss.should be_a(WordNet::Synset) }
|
110
|
+
end
|
111
|
+
|
112
|
+
it "can constrain fetched synsets to a certain range of results" do
|
113
|
+
sss = lexicon.lookup_synsets( :tree, 1..4 )
|
114
|
+
sss.should have( 4 ).members
|
115
|
+
end
|
116
|
+
|
117
|
+
it "can constrain fetched synsets to a certain (exclusive) range of results" do
|
118
|
+
sss = lexicon.lookup_synsets( :tree, 1...4 )
|
119
|
+
sss.should have( 3 ).members
|
120
|
+
end
|
121
|
+
|
107
122
|
end
|
108
123
|
|
109
124
|
end
|
110
125
|
|
111
126
|
context "with a PostgreSQL database", :requires_pg do
|
112
127
|
|
113
|
-
|
114
|
-
@lexicon = WordNet::Lexicon.new( 'postgres://localhost/wordnet30' )
|
115
|
-
end
|
128
|
+
let( :lexicon ) { WordNet::Lexicon.new(adapter: 'postgres', host: 'localhost', database: 'wordnet30') }
|
116
129
|
|
117
130
|
context "via its index operator" do
|
118
131
|
|
119
132
|
it "can look up a Synset by ID" do
|
120
|
-
rval =
|
133
|
+
rval = lexicon[ 101219722 ]
|
121
134
|
rval.should be_a( WordNet::Synset )
|
122
135
|
rval.words.map( &:to_s ).should include( 'carrot' )
|
123
136
|
end
|
124
137
|
|
125
138
|
it "can look up a Word by ID" do
|
126
|
-
rval =
|
139
|
+
rval = lexicon[ 21338 ]
|
127
140
|
rval.should be_a( WordNet::Word )
|
128
141
|
rval.lemma.should == 'carrot'
|
129
142
|
end
|
130
143
|
|
131
144
|
it "can look up the synset for a word and a sense" do
|
132
|
-
ss =
|
145
|
+
ss = lexicon[ :boot, 3 ]
|
133
146
|
ss.should be_a( WordNet::Synset )
|
134
147
|
ss.definition.should == 'footwear that covers the whole foot and lower leg'
|
135
148
|
end
|
136
149
|
|
137
150
|
it "can look up a synset for a word and a substring of its definition" do
|
138
|
-
ss =
|
151
|
+
ss = lexicon[ :boot, 'kick' ]
|
139
152
|
ss.should be_a( WordNet::Synset )
|
140
153
|
ss.definition.should =~ /kick/i
|
141
154
|
end
|
142
155
|
|
143
156
|
it "can look up a synset for a word and a part of speech" do
|
144
|
-
ss =
|
157
|
+
ss = lexicon[ :boot, :verb ]
|
145
158
|
ss.should be_a( WordNet::Synset )
|
146
159
|
ss.definition.should =~ /cause to load/i
|
147
160
|
end
|
148
161
|
|
149
162
|
it "can look up a synset for a word and an abbreviated part of speech" do
|
150
|
-
ss =
|
163
|
+
ss = lexicon[ :boot, :n ]
|
151
164
|
ss.should be_a( WordNet::Synset )
|
152
165
|
ss.definition.should =~ /act of delivering/i
|
153
166
|
end
|
167
|
+
|
168
|
+
it "can constrain fetched synsets with a Regexp match against its definition" do
|
169
|
+
sss = lexicon.lookup_synsets( :tree, /plant/ )
|
170
|
+
sss.should have( 2 ).members
|
171
|
+
end
|
172
|
+
|
173
|
+
it "can constrain fetched synsets via lexical domain" do
|
174
|
+
sss = lexicon.lookup_synsets( :tree, 'noun.shape' )
|
175
|
+
sss.should have( 1 ).member
|
176
|
+
sss.first.should == WordNet::Synset[ 113912260 ]
|
177
|
+
end
|
178
|
+
|
179
|
+
it "can constrain fetched synsets via part of speech as a single-letter Symbol" do
|
180
|
+
sss = lexicon.lookup_synsets( :tree, :n )
|
181
|
+
sss.should have( 3 ).members
|
182
|
+
sss.should include(
|
183
|
+
WordNet::Synset[ 113912260 ],
|
184
|
+
WordNet::Synset[ 111348160 ],
|
185
|
+
WordNet::Synset[ 113104059 ]
|
186
|
+
)
|
187
|
+
end
|
188
|
+
|
189
|
+
it "can constrain fetched synsets via part of speech as a Symbol word" do
|
190
|
+
sss = lexicon.lookup_synsets( :tree, :verb )
|
191
|
+
sss.should have( 4 ).members
|
192
|
+
sss.should include(
|
193
|
+
WordNet::Synset[ 200319111 ],
|
194
|
+
WordNet::Synset[ 201145163 ],
|
195
|
+
WordNet::Synset[ 201616293 ],
|
196
|
+
WordNet::Synset[ 201934205 ]
|
197
|
+
)
|
198
|
+
end
|
199
|
+
|
200
|
+
it "includes the database adapter name in its inspect output" do
|
201
|
+
lexicon.inspect.should include( "postgres" )
|
202
|
+
end
|
203
|
+
|
154
204
|
end
|
155
205
|
end
|
156
206
|
|
@@ -3,7 +3,7 @@
|
|
3
3
|
BEGIN {
|
4
4
|
require 'pathname'
|
5
5
|
|
6
|
-
basedir = Pathname.new( __FILE__ ).dirname.parent
|
6
|
+
basedir = Pathname.new( __FILE__ ).dirname.parent.parent
|
7
7
|
libdir = basedir + 'lib'
|
8
8
|
|
9
9
|
$LOAD_PATH.unshift( basedir.to_s ) unless $LOAD_PATH.include?( basedir.to_s )
|
@@ -24,12 +24,6 @@ describe WordNet::SemanticLink, :requires_database => true do
|
|
24
24
|
|
25
25
|
before( :all ) do
|
26
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
27
|
end
|
34
28
|
|
35
29
|
after( :all ) do
|
@@ -37,6 +31,26 @@ describe WordNet::SemanticLink, :requires_database => true do
|
|
37
31
|
end
|
38
32
|
|
39
33
|
|
34
|
+
let( :lexicon ) { WordNet::Lexicon.new }
|
35
|
+
let( :word ) { lexicon[96814] } # 'parody'
|
36
|
+
let( :synset ) { word.synsets.first }
|
37
|
+
let( :semlink ) { synset.semlinks.first }
|
38
|
+
|
39
|
+
|
40
|
+
it "links two synsets together" do
|
41
|
+
semlink.origin.should be_a( WordNet::Synset )
|
42
|
+
semlink.target.should be_a( WordNet::Synset )
|
43
|
+
end
|
44
|
+
|
45
|
+
it "has a Symbolic type" do
|
46
|
+
semlink.type.should == :hypernym
|
47
|
+
end
|
48
|
+
|
49
|
+
it "has a human-readable type name" do
|
50
|
+
semlink.typename.should == 'hypernym'
|
51
|
+
end
|
52
|
+
|
53
|
+
|
40
54
|
end
|
41
55
|
|
42
56
|
|
data/spec/wordnet/synset_spec.rb
CHANGED
@@ -55,31 +55,29 @@ describe WordNet::Synset, :requires_database => true do
|
|
55
55
|
|
56
56
|
context "for 'floor, level, storey, story (noun)' [103365991]" do
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
@synset = WordNet::Synset[ 103365991 ]
|
63
|
-
end
|
58
|
+
# floor, level, storey, story (noun): [noun.artifact] a structure
|
59
|
+
# consisting of a room or set of rooms at a single position along a
|
60
|
+
# vertical scale (hypernym: 1, hyponym: 5, part meronym: 1)
|
61
|
+
let( :synset ) { WordNet::Synset[103365991] }
|
64
62
|
|
65
63
|
|
66
64
|
it "knows what lexical domain it's from" do
|
67
|
-
|
65
|
+
synset.lexical_domain.should == 'noun.artifact'
|
68
66
|
end
|
69
67
|
|
70
68
|
it "can make a Sequel dataset for any of its semantic link relationships" do
|
71
|
-
ds =
|
69
|
+
ds = synset.semanticlink_dataset( :member_meronyms )
|
72
70
|
ds.should be_a( Sequel::Dataset )
|
73
71
|
ds.first_source_table.should == :synsets
|
74
72
|
end
|
75
73
|
|
76
74
|
it "can make an Enumerator for any of its semantic link relationships" do
|
77
|
-
enum =
|
75
|
+
enum = synset.semanticlink_enum( :member_meronyms )
|
78
76
|
enum.should be_a( Enumerator )
|
79
77
|
end
|
80
78
|
|
81
79
|
it "can recursively traverse its semantic links" do
|
82
|
-
res =
|
80
|
+
res = synset.traverse( :hypernyms ).to_a
|
83
81
|
res.should have( 6 ).members
|
84
82
|
res.should == [
|
85
83
|
WordNet::Synset[ 104341686 ],
|
@@ -92,7 +90,7 @@ describe WordNet::Synset, :requires_database => true do
|
|
92
90
|
end
|
93
91
|
|
94
92
|
it "can return an Enumerator for recursively traversing its semantic links" do
|
95
|
-
enum =
|
93
|
+
enum = synset.traverse( :hypernyms )
|
96
94
|
|
97
95
|
enum.next.should == WordNet::Synset[ 104341686 ]
|
98
96
|
enum.next.should == WordNet::Synset[ 100021939 ]
|
@@ -104,24 +102,45 @@ describe WordNet::Synset, :requires_database => true do
|
|
104
102
|
enum.next
|
105
103
|
}.to raise_error( StopIteration )
|
106
104
|
end
|
105
|
+
end
|
107
106
|
|
108
107
|
|
109
|
-
end
|
110
|
-
|
111
108
|
context "for 'knight (noun)' [110238375]" do
|
112
109
|
|
113
|
-
|
114
|
-
@synset = @lexicon[ :knight, "noble" ]
|
115
|
-
end
|
110
|
+
let( :synset ) { @lexicon[:knight, "noble"] }
|
116
111
|
|
117
112
|
it "can find the hypernym that it and another synset share in common through the intersection operator" do
|
118
|
-
res =
|
113
|
+
res = synset | @lexicon[ :squire ]
|
119
114
|
res.should == @lexicon[:person]
|
120
115
|
end
|
121
116
|
|
117
|
+
it "knows what part of speech it's for" do
|
118
|
+
synset.part_of_speech.should == 'noun'
|
119
|
+
end
|
120
|
+
|
121
|
+
it "stringifies as a readable definition" do
|
122
|
+
synset.to_s.should == "knight (noun): [noun.person] originally a person of noble birth trained to " +
|
123
|
+
"arms and chivalry; today in Great Britain a person honored by the sovereign for personal " +
|
124
|
+
"merit (hypernym: 1, hyponym: 6, instance hyponym: 1)"
|
125
|
+
end
|
126
|
+
|
122
127
|
end
|
123
128
|
|
124
129
|
|
130
|
+
context "for 'congener (noun)' [100003993]" do
|
131
|
+
|
132
|
+
let( :synset ) { @lexicon[:congener] }
|
133
|
+
|
134
|
+
it "can look up its sample sentences" do
|
135
|
+
synset.samples.should have( 2 ).members
|
136
|
+
synset.samples.should include(
|
137
|
+
"lard was also used, though its congener, butter, was more frequently employed",
|
138
|
+
"the American shopkeeper differs from his European congener"
|
139
|
+
)
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
|
125
144
|
|
126
145
|
end
|
127
146
|
|
data/spec/wordnet/word_spec.rb
CHANGED
@@ -25,12 +25,6 @@ describe WordNet::Word, :requires_database => true do
|
|
25
25
|
|
26
26
|
before( :all ) do
|
27
27
|
setup_logging( :fatal )
|
28
|
-
@lexicon = WordNet::Lexicon.new
|
29
|
-
end
|
30
|
-
|
31
|
-
before( :each ) do
|
32
|
-
# 'run'
|
33
|
-
@word = @lexicon[ 113377 ]
|
34
28
|
end
|
35
29
|
|
36
30
|
after( :all ) do
|
@@ -38,19 +32,100 @@ describe WordNet::Word, :requires_database => true do
|
|
38
32
|
end
|
39
33
|
|
40
34
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
35
|
+
let( :lexicon ) { WordNet::Lexicon.new }
|
36
|
+
|
37
|
+
|
38
|
+
context "the Word for 'run'" do
|
39
|
+
|
40
|
+
let( :word ) { lexicon[113377] }
|
41
|
+
|
42
|
+
it "knows what senses it has" do
|
43
|
+
senses = word.senses
|
44
|
+
senses.should be_an( Array )
|
45
|
+
senses.should have( 57 ).members
|
46
|
+
senses.first.should be_a( WordNet::Sense )
|
47
|
+
end
|
48
|
+
|
49
|
+
it "knows what synsets it has" do
|
50
|
+
synsets = word.synsets
|
51
|
+
|
52
|
+
# Should have one synset per sense
|
53
|
+
synsets.should have( word.senses.length ).members
|
54
|
+
synsets.first.senses.should include( word.senses.first )
|
55
|
+
end
|
56
|
+
|
57
|
+
it "has a dataset for selecting noun synsets" do
|
58
|
+
word.nouns.should be_a( Sequel::Dataset )
|
59
|
+
word.nouns.should have( 16 ).members
|
60
|
+
ss = word.nouns.all
|
61
|
+
ss.should include(
|
62
|
+
lexicon[ :run, 'sequence' ],
|
63
|
+
lexicon[ :run, 'baseball' ],
|
64
|
+
lexicon[ :run, 'act of running' ],
|
65
|
+
lexicon[ :run, 'testing' ]
|
66
|
+
)
|
67
|
+
end
|
68
|
+
|
69
|
+
it "has a dataset for selecting verb synsets" do
|
70
|
+
word.verbs.should be_a( Sequel::Dataset )
|
71
|
+
word.verbs.should have( 41 ).members
|
72
|
+
ss = word.verbs.all
|
73
|
+
ss.should include(
|
74
|
+
lexicon[ :run, 'compete' ],
|
75
|
+
lexicon[ :run, 'be diffused' ],
|
76
|
+
lexicon[ :run, 'liquid' ],
|
77
|
+
lexicon[ :run, 'move fast' ]
|
78
|
+
)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
|
84
|
+
context "the Word for 'light'" do
|
85
|
+
|
86
|
+
let( :word ) { lexicon[77458] }
|
87
|
+
|
88
|
+
it "has a dataset for selecting adjective synsets" do
|
89
|
+
word.adjectives.should be_a( Sequel::Dataset )
|
90
|
+
word.adjectives.should have( 8 ).members
|
91
|
+
ss = word.adjectives.all
|
92
|
+
ss.should include(
|
93
|
+
lexicon[ :light, 'weight' ],
|
94
|
+
lexicon[ :light, 'emit', :adjective ],
|
95
|
+
lexicon[ :light, 'color' ]
|
96
|
+
)
|
97
|
+
end
|
98
|
+
|
99
|
+
it "has a dataset for selecting adjective-satellite synsets" do
|
100
|
+
word.adjective_satellites.should be_a( Sequel::Dataset )
|
101
|
+
word.adjective_satellites.should have( 17 ).members
|
102
|
+
ss = word.adjective_satellites.all
|
103
|
+
ss.should include(
|
104
|
+
lexicon[ :light, 'soil' ],
|
105
|
+
lexicon[ :light, 'calories' ],
|
106
|
+
lexicon[ :light, 'entertainment' ]
|
107
|
+
)
|
108
|
+
end
|
109
|
+
|
46
110
|
end
|
47
111
|
|
48
|
-
it "knows what synsets it has" do
|
49
|
-
senses = @word.senses
|
50
|
-
synsets = @word.synsets
|
51
112
|
|
52
|
-
|
53
|
-
|
113
|
+
context "the Word for 'lightly'" do
|
114
|
+
|
115
|
+
let( :word ) { lexicon[77549] }
|
116
|
+
|
117
|
+
it "has a dataset for selecting adverb synsets" do
|
118
|
+
word.adverbs.should be_a( Sequel::Dataset )
|
119
|
+
word.adverbs.should have( 7 ).members
|
120
|
+
ss = word.adverbs.all
|
121
|
+
ss.should include(
|
122
|
+
lexicon[ :lightly, 'indifference' ],
|
123
|
+
lexicon[ :lightly, 'indulging' ],
|
124
|
+
lexicon[ :lightly, 'little weight' ],
|
125
|
+
lexicon[ :lightly, 'quantity' ]
|
126
|
+
)
|
127
|
+
end
|
128
|
+
|
54
129
|
end
|
55
130
|
|
56
131
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wordnet
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.
|
4
|
+
version: 1.0.0.pre.139
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -36,7 +36,7 @@ cert_chain:
|
|
36
36
|
YUhDS0xaZFNLai9SSHVUT3QrZ2JsUmV4OEZBaDhOZUEKY21saFhlNDZwWk5K
|
37
37
|
Z1dLYnhaYWg4NWpJang5NWhSOHZPSStOQU01aUg5a09xSzEzRHJ4YWNUS1Bo
|
38
38
|
cWo1UGp3RgotLS0tLUVORCBDRVJUSUZJQ0FURS0tLS0tCg==
|
39
|
-
date: 2012-
|
39
|
+
date: 2012-09-05 00:00:00.000000000 Z
|
40
40
|
dependencies:
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: sequel
|
@@ -150,6 +150,22 @@ dependencies:
|
|
150
150
|
- - ~>
|
151
151
|
- !ruby/object:Gem::Version
|
152
152
|
version: '2.7'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: simplecov
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
none: false
|
157
|
+
requirements:
|
158
|
+
- - ~>
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
version: '0.6'
|
161
|
+
type: :development
|
162
|
+
prerelease: false
|
163
|
+
version_requirements: !ruby/object:Gem::Requirement
|
164
|
+
none: false
|
165
|
+
requirements:
|
166
|
+
- - ~>
|
167
|
+
- !ruby/object:Gem::Version
|
168
|
+
version: '0.6'
|
153
169
|
- !ruby/object:Gem::Dependency
|
154
170
|
name: hoe
|
155
171
|
requirement: !ruby/object:Gem::Requirement
|
@@ -166,28 +182,16 @@ dependencies:
|
|
166
182
|
- - ~>
|
167
183
|
- !ruby/object:Gem::Version
|
168
184
|
version: '3.0'
|
169
|
-
description: !
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
the synonym sets.
|
180
|
-
|
181
|
-
|
182
|
-
It uses WordNet-SQL, which is a conversion of the lexicon flatfiles into
|
183
|
-
|
184
|
-
a relational database format. You can either install the ''wordnet-
|
185
|
-
|
186
|
-
defaultdb'' gem, which packages up the SQLite3 version of WordNet-SQL, or
|
187
|
-
|
188
|
-
install your own and point the lexicon at it by passing a Sequel URL to
|
189
|
-
|
190
|
-
the constructor.'
|
185
|
+
description: ! "This library is a Ruby interface to WordNet®[http://wordnet.princeton.edu/].\nWordNet®
|
186
|
+
is an online lexical reference system whose design is inspired\nby current psycholinguistic
|
187
|
+
theories of human lexical memory. English\nnouns, verbs, adjectives and adverbs
|
188
|
+
are organized into synonym sets, each\nrepresenting one underlying lexical concept.
|
189
|
+
Different relations link\nthe synonym sets.\n\nThis library uses WordNet-SQL[http://wnsql.sourceforge.net/],
|
190
|
+
which is a\nconversion of the lexicon flatfiles into a relational database format.
|
191
|
+
You\ncan either install the 'wordnet-defaultdb' gem, which packages up the\nSQLite3
|
192
|
+
version of WordNet-SQL, or install your own and point the lexicon\nat it by passing
|
193
|
+
\n{Sequel connection parameters}[http://sequel.rubyforge.org/rdoc/files/doc/opening_databases_rdoc.html]\nto
|
194
|
+
the constructor."
|
191
195
|
email:
|
192
196
|
- ged@FaerieMUD.org
|
193
197
|
executables: []
|
@@ -268,5 +272,5 @@ rubyforge_project: wordnet
|
|
268
272
|
rubygems_version: 1.8.24
|
269
273
|
signing_key:
|
270
274
|
specification_version: 3
|
271
|
-
summary: This library is a Ruby interface to WordNet®
|
275
|
+
summary: This library is a Ruby interface to WordNet®[http://wordnet.princeton.edu/]
|
272
276
|
test_files: []
|
metadata.gz.sig
CHANGED
Binary file
|