WordNet lexicon class - abstracts access to the WordNet lexical databases, and provides factory methods for looking up and creating new WordNet::Synset objects.
Create a new WordNet::Lexicon object that will read its data from the given dbenv (a BerkeleyDB env directory). The database will be opened with the specified mode, which can either be a numeric octal mode (e.g., 0444) or one of (:readonly, :readwrite).
# File lib/wordnet/lexicon.rb, line 91
91: def initialize( dbenv=DEFAULT_DB_ENV, mode=:readonly )
92: @mode = normalize_mode( mode )
93: debug_msg "Mode is: %04o" % [ mode ]
94:
95: envflags = 0
96: dbflags = 0
97:
98: unless self.readonly?
99: debug_msg "Using read/write flags"
100: envflags = ENV_FLAGS_RW
101: dbflags = BDB::CREATE
102: else
103: debug_msg "Using readonly flags"
104: envflags = ENV_FLAGS_RO
105: dbflags = 0
106: end
107:
108: debug_msg "Env flags are: %0s, dbflags are %0s" %
109: [ envflags.to_s(2), dbflags.to_s(2) ]
110:
111: begin
112: @env = BDB::Env.new( dbenv, envflags, ENV_OPTIONS )
113: @index_db = @env.open_db( BDB::BTREE, "index", nil, dbflags, @mode )
114: @data_db = @env.open_db( BDB::BTREE, "data", nil, dbflags, @mode )
115: @morph_db = @env.open_db( BDB::BTREE, "morph", nil, dbflags, @mode )
116: rescue StandardError => err
117: msg = "Error while opening Ruby-WordNet data files: #{dbenv}: %s" %
118: [ err.message ]
119: raise err, msg, err.backtrace
120: end
121: end
Checkpoint the database. (BerkeleyDB-specific)
# File lib/wordnet/lexicon.rb, line 161
161: def checkpoint( bytes=0, minutes=0 )
162: @env.checkpoint
163: end
Remove any archival logfiles for the lexicon‘s database environment. (BerkeleyDB-specific).
# File lib/wordnet/lexicon.rb, line 168
168: def clean_logs
169: return unless self.readwrite?
170: self.archlogs.each do |logfile|
171: File::chmod( 0777, logfile )
172: File::delete( logfile )
173: end
174: end
Close the lexicon‘s database environment
# File lib/wordnet/lexicon.rb, line 155
155: def close
156: @env.close if @env
157: end
Factory method: Creates and returns a new WordNet::Synset object in this lexicon for the specified word and part_of_speech.
# File lib/wordnet/lexicon.rb, line 279
279: def create_synset( word, part_of_speech )
280: return WordNet::Synset::new( self, '', part_of_speech, word )
281: end
Returns an integer of the familiarity/polysemy count for word as a part_of_speech. Note that polysemy can be identified for a given word by counting the synsets returned by #lookup_synsets.
# File lib/wordnet/lexicon.rb, line 180
180: def familiarity( word, part_of_speech, polyCount=nil )
181: wordkey = self.make_word_key( word, part_of_speech )
182: return nil unless @index_db.key?( wordkey )
183: @index_db[ wordkey ].split( WordNet::SUB_DELIM_RE ).length
184: end
Returns an array of compound words matching text.
# File lib/wordnet/lexicon.rb, line 258
258: def grep( text )
259: return [] if text.empty?
260:
261: words = []
262:
263: # Grab a cursor into the database and fetch while the key matches
264: # the target text
265: cursor = @index_db.cursor
266: rec = cursor.set_range( text )
267: while /^#{text}/ =~ rec[0]
268: words.push rec[0]
269: rec = cursor.next
270: end
271: cursor.close
272:
273: return *words
274: end
Look up sysets (Wordnet::Synset objects) matching text as a part_of_speech, where part_of_speech is one of +WordNet::Noun+, +WordNet::Verb+, +WordNet::Adjective+, or +WordNet::Adverb+. Without sense, #lookup_synsets will return all matches that are a part_of_speech. If sense is specified, only the synset object that matches that particular part_of_speech and sense is returned.
# File lib/wordnet/lexicon.rb, line 193
193: def lookup_synsets( word, part_of_speech, sense=nil )
194: wordkey = self.make_word_key( word, part_of_speech )
195: pos = self.make_pos( part_of_speech )
196: synsets = []
197:
198: # Look up the index entry, trying first the word as given, and if
199: # that fails, trying morphological conversion.
200: entry = @index_db[ wordkey ]
201:
202: if entry.nil? && (word = self.morph( word, part_of_speech ))
203: wordkey = self.make_word_key( word, part_of_speech )
204: entry = @index_db[ wordkey ]
205: end
206:
207: # If the lookup failed both ways, just abort
208: return nil unless entry
209:
210: # Make synset keys from the entry, narrowing it to just the sense
211: # requested if one was specified.
212: synkeys = entry.split( SUB_DELIM_RE ).collect {|off| "#{off}%#{pos}" }
213: if sense
214: return lookup_synsets_by_key( synkeys[sense - 1] )
215: else
216: return [ lookup_synsets_by_key(*synkeys) ].flatten
217: end
218: end
Returns the WordNet::Synset objects corresponding to the keys specified. The keys are made up of the target synset‘s "offset" and syntactic category catenated together with a ’%’ character.
# File lib/wordnet/lexicon.rb, line 224
224: def lookup_synsets_by_key( *keys )
225: synsets = []
226:
227: keys.each {|key|
228: raise WordNet::LookupError, "Failed lookup of synset '#{key}':"\
229: "No such synset" unless @data_db.key?( key )
230:
231: data = @data_db[ key ]
232: offset, part_of_speech = key.split( /%/, 2 )
233: synsets << WordNet::Synset::new( self, offset, part_of_speech, nil, data )
234: }
235:
236: return *synsets
237: end
Returns a form of word as a part of speech part_of_speech, as found in the WordNet morph files. The #lookup_synsets method perfoms morphological conversion automatically, so a call to #morph is not required.
# File lib/wordnet/lexicon.rb, line 245
245: def morph( word, part_of_speech )
246: return @morph_db[ self.make_word_key(word, part_of_speech) ]
247: end
Returns true if the lexicon was opened in read-only mode.
# File lib/wordnet/lexicon.rb, line 143
143: def readonly?
144: ( @mode & 0200 ).nonzero? ? false : true
145: end
Returns true if the lexicon was opened in read-write mode.
# File lib/wordnet/lexicon.rb, line 149
149: def readwrite?
150: ! self.readonly?
151: end
Remove the specified synset (a WordNet::Synset object) in the lexicon. Returns the offset of the stored synset.
# File lib/wordnet/lexicon.rb, line 327
327: def remove_synset( synset )
328: # If it's not in the database (ie., doesn't have a real offset),
329: # just return.
330: return nil if synset.offset == 1
331:
332: # Start a transaction on the data table
333: @env.begin( BDB::TXN_COMMIT, @data_db ) do |txn,datadb|
334:
335: # First remove the index entries for this synset by iterating
336: # over each of its words
337: txn.begin( BDB::TXN_COMMIT, @index_db ) do |txn,indexdb|
338: synset.words.collect {|word| word + "%" + pos }.each {|word|
339:
340: # If the index contains an entry for this word, either
341: # splice out the offset for the synset being deleted if
342: # there are more than one, or just delete the whole
343: # entry if it's the only one.
344: if indexdb.key?( word )
345: offsets = indexdb[ word ].
346: split( SUB_DELIM_RE ).
347: reject {|offset| offset == synset.offset}
348:
349: unless offsets.empty?
350: index_db[ word ] = newoffsets.join( SUB_DELIM )
351: else
352: index_db.delete( word )
353: end
354: end
355: }
356: end
357:
358: # :TODO: Delete synset from pointers of related synsets
359:
360: # Delete the synset from the main db
361: datadb.delete( synset.offset )
362: end
363:
364: return true
365: end
Returns the result of looking up word in the inverse of the WordNet morph files. _(This is undocumented in Lingua::Wordnet)_
# File lib/wordnet/lexicon.rb, line 252
252: def reverse_morph( word )
253: @morph_db.invert[ word ]
254: end
Store the specified synset (a WordNet::Synset object) in the lexicon. Returns the key of the stored synset.
# File lib/wordnet/lexicon.rb, line 287
287: def store_synset( synset )
288: strippedOffset = nil
289: pos = nil
290:
291: # Start a transaction
292: @env.begin( BDB::TXN_COMMIT, @data_db ) do |txn,datadb|
293:
294: # If this is a new synset, generate an offset for it
295: if synset.offset == 1
296: synset.offset =
297: (datadb['offsetcount'] = datadb['offsetcount'].to_i + 1)
298: end
299:
300: # Write the data entry
301: datadb[ synset.key ] = synset.serialize
302:
303: # Write the index entries
304: txn.begin( BDB::TXN_COMMIT, @index_db ) do |txn,indexdb|
305:
306: # Make word/part-of-speech pairs from the words in the synset
307: synset.words.collect {|word| word + "%" + pos }.each {|word|
308:
309: # If the index already has this word, but not this
310: # synset, add it
311: if indexdb.key?( word )
312: indexdb[ word ] << SUB_DELIM << synset.offset unless
313: indexdb[ word ].include?( synset.offset )
314: else
315: indexdb[ word ] = synset.offset
316: end
317: }
318: end # transaction on @index_db
319: end # transaction on @dataDB
320:
321: return synset.offset
322: end
Return a list of archival logfiles that can be removed safely. (BerkeleyDB-specific).
# File lib/wordnet/lexicon.rb, line 398
398: def archlogs
399: return @env.log_archive( BDB::ARCH_ABS )
400: end
Normalize various ways of specifying a part of speech into the WordNet part of speech indicator from the original representation, which may be the name (e.g., "noun"); nil, in which case it defaults to the indicator for a noun; or the indicator character itself, in which case it is returned unmodified.
# File lib/wordnet/lexicon.rb, line 377
377: def make_pos( original )
378: return WordNet::Noun if original.nil?
379: osym = original.to_s.intern
380: return WordNet::SYNTACTIC_CATEGORIES[ osym ] if
381: WordNet::SYNTACTIC_CATEGORIES.key?( osym )
382: return original if SYNTACTIC_SYMBOLS.key?( original )
383: return nil
384: end
--- SEC00008
--- ""
---
- name: data_db
rw: R
a_desc: |+
The handle to the synset data table
- name: env
rw: R
a_desc: |+
The BDB::Env object which contains the wordnet lexicon‘s databases.
- name: index_db
rw: R
a_desc: |+
The handle to the index table
- name: morph_db
rw: R
a_desc: |+
The handle to the morph table
---
- methods:
- visibility: public
aref: M000001
name: new
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 91</span>\n 91: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">initialize</span>( <span class=\"ruby-identifier\">dbenv</span>=<span class=\"ruby-constant\">DEFAULT_DB_ENV</span>, <span class=\"ruby-identifier\">mode</span>=<span class=\"ruby-identifier\">:readonly</span> )\n 92: <span class=\"ruby-ivar\">@mode</span> = <span class=\"ruby-identifier\">normalize_mode</span>( <span class=\"ruby-identifier\">mode</span> )\n 93: <span class=\"ruby-identifier\">debug_msg</span> <span class=\"ruby-value str\">"Mode is: %04o"</span> <span class=\"ruby-operator\">%</span> [ <span class=\"ruby-identifier\">mode</span> ]\n 94: \n 95: <span class=\"ruby-identifier\">envflags</span> = <span class=\"ruby-value\">0</span>\n 96: <span class=\"ruby-identifier\">dbflags</span> = <span class=\"ruby-value\">0</span>\n 97: \n 98: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">readonly?</span>\n 99: <span class=\"ruby-identifier\">debug_msg</span> <span class=\"ruby-value str\">"Using read/write flags"</span>\n\
100: <span class=\"ruby-identifier\">envflags</span> = <span class=\"ruby-constant\">ENV_FLAGS_RW</span>\n\
101: <span class=\"ruby-identifier\">dbflags</span> = <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">CREATE</span>\n\
102: <span class=\"ruby-keyword kw\">else</span>\n\
103: <span class=\"ruby-identifier\">debug_msg</span> <span class=\"ruby-value str\">"Using readonly flags"</span>\n\
104: <span class=\"ruby-identifier\">envflags</span> = <span class=\"ruby-constant\">ENV_FLAGS_RO</span>\n\
105: <span class=\"ruby-identifier\">dbflags</span> = <span class=\"ruby-value\">0</span>\n\
106: <span class=\"ruby-keyword kw\">end</span>\n\
107: \n\
108: <span class=\"ruby-identifier\">debug_msg</span> <span class=\"ruby-value str\">"Env flags are: %0s, dbflags are %0s"</span> <span class=\"ruby-operator\">%</span>\n\
109: [ <span class=\"ruby-identifier\">envflags</span>.<span class=\"ruby-identifier\">to_s</span>(<span class=\"ruby-value\">2</span>), <span class=\"ruby-identifier\">dbflags</span>.<span class=\"ruby-identifier\">to_s</span>(<span class=\"ruby-value\">2</span>) ]\n\
110: \n\
111: <span class=\"ruby-keyword kw\">begin</span>\n\
112: <span class=\"ruby-ivar\">@env</span> = <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Env</span>.<span class=\"ruby-identifier\">new</span>( <span class=\"ruby-identifier\">dbenv</span>, <span class=\"ruby-identifier\">envflags</span>, <span class=\"ruby-constant\">ENV_OPTIONS</span> )\n\
113: <span class=\"ruby-ivar\">@index_db</span> = <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">open_db</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">BTREE</span>, <span class=\"ruby-value str\">"index"</span>, <span class=\"ruby-keyword kw\">nil</span>, <span class=\"ruby-identifier\">dbflags</span>, <span class=\"ruby-ivar\">@mode</span> )\n\
114: <span class=\"ruby-ivar\">@data_db</span> = <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">open_db</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">BTREE</span>, <span class=\"ruby-value str\">"data"</span>, <span class=\"ruby-keyword kw\">nil</span>, <span class=\"ruby-identifier\">dbflags</span>, <span class=\"ruby-ivar\">@mode</span> )\n\
115: <span class=\"ruby-ivar\">@morph_db</span> = <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">open_db</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">BTREE</span>, <span class=\"ruby-value str\">"morph"</span>, <span class=\"ruby-keyword kw\">nil</span>, <span class=\"ruby-identifier\">dbflags</span>, <span class=\"ruby-ivar\">@mode</span> )\n\
116: <span class=\"ruby-keyword kw\">rescue</span> <span class=\"ruby-constant\">StandardError</span> =<span class=\"ruby-operator\">></span> <span class=\"ruby-identifier\">err</span>\n\
117: <span class=\"ruby-identifier\">msg</span> = <span class=\"ruby-node\">"Error while opening Ruby-WordNet data files: #{dbenv}: %s"</span> <span class=\"ruby-operator\">%</span> \n\
118: [ <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">message</span> ]\n\
119: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-identifier\">err</span>, <span class=\"ruby-identifier\">msg</span>, <span class=\"ruby-identifier\">err</span>.<span class=\"ruby-identifier\">backtrace</span>\n\
120: <span class=\"ruby-keyword kw\">end</span>\n\
121: <span class=\"ruby-keyword kw\">end</span>"
m_desc: "<p>\n\
Create a new <a href=\"Lexicon.html\">WordNet::Lexicon</a> object that will\n\
read its data from the given <tt>dbenv</tt> (a BerkeleyDB env directory).\n\
The database will be opened with the specified <tt>mode</tt>, which can\n\
either be a numeric octal mode (e.g., 0444) or one of (:readonly,\n\
:readwrite).\n\
</p>"
params: ( dbenv=DEFAULT_DB_ENV, mode=:readonly )
category: Class
type: Public
- methods:
- visibility: public
aref: M000005
name: checkpoint
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 161</span>\n\
161: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">checkpoint</span>( <span class=\"ruby-identifier\">bytes</span>=<span class=\"ruby-value\">0</span>, <span class=\"ruby-identifier\">minutes</span>=<span class=\"ruby-value\">0</span> )\n\
162: <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">checkpoint</span>\n\
163: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Checkpoint the database. (BerkeleyDB-specific)
</p>
params: ( bytes=0, minutes=0 )
- visibility: public
aref: M000006
name: clean_logs
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 168</span>\n\
168: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">clean_logs</span>\n\
169: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">readwrite?</span>\n\
170: <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">archlogs</span>.<span class=\"ruby-identifier\">each</span> <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">logfile</span><span class=\"ruby-operator\">|</span>\n\
171: <span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">chmod</span>( <span class=\"ruby-value\">0777</span>, <span class=\"ruby-identifier\">logfile</span> )\n\
172: <span class=\"ruby-constant\">File</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">delete</span>( <span class=\"ruby-identifier\">logfile</span> )\n\
173: <span class=\"ruby-keyword kw\">end</span>\n\
174: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Remove any archival logfiles for the lexicon‘s database environment.
(BerkeleyDB-specific).
</p>
params: ()
- visibility: public
aref: M000004
name: close
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 155</span>\n\
155: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">close</span>\n\
156: <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">close</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-ivar\">@env</span>\n\
157: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Close the lexicon‘s database environment
</p>
params: ()
- visibility: public
aref: M000014
name: create_synset
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 279</span>\n\
279: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">create_synset</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span> )\n\
280: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">WordNet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Synset</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">new</span>( <span class=\"ruby-keyword kw\">self</span>, <span class=\"ruby-value str\">''</span>, <span class=\"ruby-identifier\">part_of_speech</span>, <span class=\"ruby-identifier\">word</span> )\n\
281: <span class=\"ruby-keyword kw\">end</span>"
aka:
- aref: Lexicon.html#M000015
name: new_synset
m_desc: |-
<p>
Factory method: Creates and returns a new <a
href="Synset.html">WordNet::Synset</a> object in this lexicon for the
specified <tt>word</tt> and <tt>part_of_speech</tt>.
</p>
params: ( word, part_of_speech )
- visibility: public
aref: M000007
name: familiarity
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 180</span>\n\
180: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">familiarity</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span>, <span class=\"ruby-identifier\">polyCount</span>=<span class=\"ruby-keyword kw\">nil</span> )\n\
181: <span class=\"ruby-identifier\">wordkey</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">make_word_key</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span> )\n\
182: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@index_db</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">wordkey</span> )\n\
183: <span class=\"ruby-ivar\">@index_db</span>[ <span class=\"ruby-identifier\">wordkey</span> ].<span class=\"ruby-identifier\">split</span>( <span class=\"ruby-constant\">WordNet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">SUB_DELIM_RE</span> ).<span class=\"ruby-identifier\">length</span>\n\
184: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns an integer of the familiarity/polysemy count for <tt>word</tt> as a
<tt>part_of_speech</tt>. Note that polysemy can be identified for a given
word by counting the synsets returned by <a
href="Lexicon.html#M000008">#lookup_synsets</a>.
</p>
params: ( word, part_of_speech, polyCount=nil )
- visibility: public
aref: M000013
name: grep
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 258</span>\n\
258: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">grep</span>( <span class=\"ruby-identifier\">text</span> )\n\
259: <span class=\"ruby-keyword kw\">return</span> [] <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">text</span>.<span class=\"ruby-identifier\">empty?</span>\n\
260: \n\
261: <span class=\"ruby-identifier\">words</span> = []\n\
262: \n\
263: <span class=\"ruby-comment cmt\"># Grab a cursor into the database and fetch while the key matches</span>\n\
264: <span class=\"ruby-comment cmt\"># the target text</span>\n\
265: <span class=\"ruby-identifier\">cursor</span> = <span class=\"ruby-ivar\">@index_db</span>.<span class=\"ruby-identifier\">cursor</span>\n\
266: <span class=\"ruby-identifier\">rec</span> = <span class=\"ruby-identifier\">cursor</span>.<span class=\"ruby-identifier\">set_range</span>( <span class=\"ruby-identifier\">text</span> )\n\
267: <span class=\"ruby-keyword kw\">while</span> <span class=\"ruby-node\">/^#{text}/</span> <span class=\"ruby-operator\">=~</span> <span class=\"ruby-identifier\">rec</span>[<span class=\"ruby-value\">0</span>]\n\
268: <span class=\"ruby-identifier\">words</span>.<span class=\"ruby-identifier\">push</span> <span class=\"ruby-identifier\">rec</span>[<span class=\"ruby-value\">0</span>]\n\
269: <span class=\"ruby-identifier\">rec</span> = <span class=\"ruby-identifier\">cursor</span>.<span class=\"ruby-identifier\">next</span>\n\
270: <span class=\"ruby-keyword kw\">end</span>\n\
271: <span class=\"ruby-identifier\">cursor</span>.<span class=\"ruby-identifier\">close</span>\n\
272: \n\
273: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">words</span>\n\
274: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns an array of compound words matching <tt>text</tt>.
</p>
params: ( text )
- visibility: public
aref: M000008
name: lookup_synsets
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 193</span>\n\
193: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">lookup_synsets</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span>, <span class=\"ruby-identifier\">sense</span>=<span class=\"ruby-keyword kw\">nil</span> )\n\
194: <span class=\"ruby-identifier\">wordkey</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">make_word_key</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span> )\n\
195: <span class=\"ruby-identifier\">pos</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">make_pos</span>( <span class=\"ruby-identifier\">part_of_speech</span> )\n\
196: <span class=\"ruby-identifier\">synsets</span> = []\n\
197: \n\
198: <span class=\"ruby-comment cmt\"># Look up the index entry, trying first the word as given, and if</span>\n\
199: <span class=\"ruby-comment cmt\"># that fails, trying morphological conversion.</span>\n\
200: <span class=\"ruby-identifier\">entry</span> = <span class=\"ruby-ivar\">@index_db</span>[ <span class=\"ruby-identifier\">wordkey</span> ]\n\
201: \n\
202: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">entry</span>.<span class=\"ruby-identifier\">nil?</span> <span class=\"ruby-operator\">&&</span> (<span class=\"ruby-identifier\">word</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">morph</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span> ))\n\
203: <span class=\"ruby-identifier\">wordkey</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">make_word_key</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span> )\n\
204: <span class=\"ruby-identifier\">entry</span> = <span class=\"ruby-ivar\">@index_db</span>[ <span class=\"ruby-identifier\">wordkey</span> ]\n\
205: <span class=\"ruby-keyword kw\">end</span>\n\
206: \n\
207: <span class=\"ruby-comment cmt\"># If the lookup failed both ways, just abort</span>\n\
208: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">entry</span>\n\
209: \n\
210: <span class=\"ruby-comment cmt\"># Make synset keys from the entry, narrowing it to just the sense</span>\n\
211: <span class=\"ruby-comment cmt\"># requested if one was specified.</span>\n\
212: <span class=\"ruby-identifier\">synkeys</span> = <span class=\"ruby-identifier\">entry</span>.<span class=\"ruby-identifier\">split</span>( <span class=\"ruby-constant\">SUB_DELIM_RE</span> ).<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">off</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-node\">"#{off}%#{pos}"</span> }\n\
213: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">sense</span>\n\
214: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">lookup_synsets_by_key</span>( <span class=\"ruby-identifier\">synkeys</span>[<span class=\"ruby-identifier\">sense</span> <span class=\"ruby-operator\">-</span> <span class=\"ruby-value\">1</span>] )\n\
215: <span class=\"ruby-keyword kw\">else</span>\n\
216: <span class=\"ruby-keyword kw\">return</span> [ <span class=\"ruby-identifier\">lookup_synsets_by_key</span>(<span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">synkeys</span>) ].<span class=\"ruby-identifier\">flatten</span>\n\
217: <span class=\"ruby-keyword kw\">end</span>\n\
218: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Look up sysets (Wordnet::Synset objects) matching <tt>text</tt> as a
<tt>part_of_speech</tt>, where <tt>part_of_speech</tt> is one of
+WordNet::Noun+, +WordNet::Verb+, +WordNet::Adjective+, or
+WordNet::Adverb+. Without <tt>sense</tt>, <a
href="Lexicon.html#M000008">#lookup_synsets</a> will return all matches
that are a <tt>part_of_speech</tt>. If <tt>sense</tt> is specified, only
the synset object that matches that particular <tt>part_of_speech</tt> and
<tt>sense</tt> is returned.
</p>
params: ( word, part_of_speech, sense=nil )
- visibility: public
aref: M000010
name: lookup_synsetsByOffset
m_desc: |-
<p>
Alias for <a href="Lexicon.html#M000009">#lookup_synsets_by_key</a>
</p>
params: ( *keys )
- visibility: public
aref: M000009
name: lookup_synsets_by_key
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 224</span>\n\
224: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">lookup_synsets_by_key</span>( <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">keys</span> )\n\
225: <span class=\"ruby-identifier\">synsets</span> = []\n\
226: \n\
227: <span class=\"ruby-identifier\">keys</span>.<span class=\"ruby-identifier\">each</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">key</span><span class=\"ruby-operator\">|</span>\n\
228: <span class=\"ruby-identifier\">raise</span> <span class=\"ruby-constant\">WordNet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">LookupError</span>, <span class=\"ruby-node\">"Failed lookup of synset '#{key}':"</span>\\\n\
229: <span class=\"ruby-value str\">"No such synset"</span> <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-ivar\">@data_db</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">key</span> )\n\
230: \n\
231: <span class=\"ruby-identifier\">data</span> = <span class=\"ruby-ivar\">@data_db</span>[ <span class=\"ruby-identifier\">key</span> ]\n\
232: <span class=\"ruby-identifier\">offset</span>, <span class=\"ruby-identifier\">part_of_speech</span> = <span class=\"ruby-identifier\">key</span>.<span class=\"ruby-identifier\">split</span>( <span class=\"ruby-regexp re\">/%/</span>, <span class=\"ruby-value\">2</span> )\n\
233: <span class=\"ruby-identifier\">synsets</span> <span class=\"ruby-operator\"><<</span> <span class=\"ruby-constant\">WordNet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Synset</span><span class=\"ruby-operator\">::</span><span class=\"ruby-identifier\">new</span>( <span class=\"ruby-keyword kw\">self</span>, <span class=\"ruby-identifier\">offset</span>, <span class=\"ruby-identifier\">part_of_speech</span>, <span class=\"ruby-keyword kw\">nil</span>, <span class=\"ruby-identifier\">data</span> )\n\
234: }\n\
235: \n\
236: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-operator\">*</span><span class=\"ruby-identifier\">synsets</span>\n\
237: <span class=\"ruby-keyword kw\">end</span>"
aka:
- aref: Lexicon.html#M000010
name: lookup_synsetsByOffset
m_desc: |-
<p>
Returns the <a href="Synset.html">WordNet::Synset</a> objects corresponding
to the <tt>keys</tt> specified. The <tt>keys</tt> are made up of the target
synset‘s "offset" and syntactic category catenated together with a
’%’ character.
</p>
params: ( *keys )
- visibility: public
aref: M000011
name: morph
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 245</span>\n\
245: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">morph</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span> )\n\
246: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@morph_db</span>[ <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">make_word_key</span>(<span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">part_of_speech</span>) ]\n\
247: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns a form of <tt>word</tt> as a part of speech
<tt>part_of_speech</tt>, as found in the <a
href="../WordNet.html">WordNet</a> morph files. The <a
href="Lexicon.html#M000008">#lookup_synsets</a> method perfoms
morphological conversion automatically, so a call to <a
href="Lexicon.html#M000011">#morph</a> is not required.
</p>
params: ( word, part_of_speech )
- visibility: public
aref: M000015
name: new_synset
m_desc: |-
<p>
Alias for <a href="Lexicon.html#M000014">#create_synset</a>
</p>
params: ( word, part_of_speech )
- visibility: public
aref: M000002
name: readonly?
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 143</span>\n\
143: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">readonly?</span>\n\
144: ( <span class=\"ruby-ivar\">@mode</span> <span class=\"ruby-operator\">&</span> <span class=\"ruby-value\">0200</span> ).<span class=\"ruby-identifier\">nonzero?</span> <span class=\"ruby-value\">? </span><span class=\"ruby-keyword kw\">false</span> <span class=\"ruby-operator\">:</span> <span class=\"ruby-keyword kw\">true</span>\n\
145: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns <tt>true</tt> if the lexicon was opened in read-only mode.
</p>
params: ()
- visibility: public
aref: M000003
name: readwrite?
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 149</span>\n\
149: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">readwrite?</span>\n\
150: <span class=\"ruby-operator\">!</span> <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">readonly?</span>\n\
151: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns <tt>true</tt> if the lexicon was opened in read-write mode.
</p>
params: ()
- visibility: public
aref: M000017
name: remove_synset
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 327</span>\n\
327: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">remove_synset</span>( <span class=\"ruby-identifier\">synset</span> )\n\
328: <span class=\"ruby-comment cmt\"># If it's not in the database (ie., doesn't have a real offset),</span>\n\
329: <span class=\"ruby-comment cmt\"># just return.</span>\n\
330: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">1</span>\n\
331: \n\
332: <span class=\"ruby-comment cmt\"># Start a transaction on the data table</span>\n\
333: <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">begin</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">TXN_COMMIT</span>, <span class=\"ruby-ivar\">@data_db</span> ) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">txn</span>,<span class=\"ruby-identifier\">datadb</span><span class=\"ruby-operator\">|</span>\n\
334: \n\
335: <span class=\"ruby-comment cmt\"># First remove the index entries for this synset by iterating</span>\n\
336: <span class=\"ruby-comment cmt\"># over each of its words</span>\n\
337: <span class=\"ruby-identifier\">txn</span>.<span class=\"ruby-identifier\">begin</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">TXN_COMMIT</span>, <span class=\"ruby-ivar\">@index_db</span> ) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">txn</span>,<span class=\"ruby-identifier\">indexdb</span><span class=\"ruby-operator\">|</span>\n\
338: <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">words</span>.<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">word</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">word</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">"%"</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">pos</span> }.<span class=\"ruby-identifier\">each</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">word</span><span class=\"ruby-operator\">|</span>\n\
339: \n\
340: <span class=\"ruby-comment cmt\"># If the index contains an entry for this word, either</span>\n\
341: <span class=\"ruby-comment cmt\"># splice out the offset for the synset being deleted if</span>\n\
342: <span class=\"ruby-comment cmt\"># there are more than one, or just delete the whole</span>\n\
343: <span class=\"ruby-comment cmt\"># entry if it's the only one.</span>\n\
344: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">indexdb</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">word</span> )\n\
345: <span class=\"ruby-identifier\">offsets</span> = <span class=\"ruby-identifier\">indexdb</span>[ <span class=\"ruby-identifier\">word</span> ].\n\
346: <span class=\"ruby-identifier\">split</span>( <span class=\"ruby-constant\">SUB_DELIM_RE</span> ).\n\
347: <span class=\"ruby-identifier\">reject</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">offset</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">offset</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span>}\n\
348: \n\
349: <span class=\"ruby-keyword kw\">unless</span> <span class=\"ruby-identifier\">offsets</span>.<span class=\"ruby-identifier\">empty?</span>\n\
350: <span class=\"ruby-identifier\">index_db</span>[ <span class=\"ruby-identifier\">word</span> ] = <span class=\"ruby-identifier\">newoffsets</span>.<span class=\"ruby-identifier\">join</span>( <span class=\"ruby-constant\">SUB_DELIM</span> )\n\
351: <span class=\"ruby-keyword kw\">else</span>\n\
352: <span class=\"ruby-identifier\">index_db</span>.<span class=\"ruby-identifier\">delete</span>( <span class=\"ruby-identifier\">word</span> )\n\
353: <span class=\"ruby-keyword kw\">end</span>\n\
354: <span class=\"ruby-keyword kw\">end</span>\n\
355: }\n\
356: <span class=\"ruby-keyword kw\">end</span>\n\
357: \n\
358: <span class=\"ruby-comment cmt\"># :TODO: Delete synset from pointers of related synsets</span>\n\
359: \n\
360: <span class=\"ruby-comment cmt\"># Delete the synset from the main db</span>\n\
361: <span class=\"ruby-identifier\">datadb</span>.<span class=\"ruby-identifier\">delete</span>( <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span> )\n\
362: <span class=\"ruby-keyword kw\">end</span>\n\
363: \n\
364: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">true</span>\n\
365: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Remove the specified <tt>synset</tt> (a <a
href="Synset.html">WordNet::Synset</a> object) in the lexicon. Returns the
offset of the stored synset.
</p>
params: ( synset )
- visibility: public
aref: M000012
name: reverse_morph
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 252</span>\n\
252: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">reverse_morph</span>( <span class=\"ruby-identifier\">word</span> )\n\
253: <span class=\"ruby-ivar\">@morph_db</span>.<span class=\"ruby-identifier\">invert</span>[ <span class=\"ruby-identifier\">word</span> ]\n\
254: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Returns the result of looking up <tt>word</tt> in the inverse of the <a
href="../WordNet.html">WordNet</a> morph files. _(This is undocumented in
Lingua::Wordnet)_
</p>
params: ( word )
- visibility: public
aref: M000016
name: store_synset
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 287</span>\n\
287: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">store_synset</span>( <span class=\"ruby-identifier\">synset</span> )\n\
288: <span class=\"ruby-identifier\">strippedOffset</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
289: <span class=\"ruby-identifier\">pos</span> = <span class=\"ruby-keyword kw\">nil</span>\n\
290: \n\
291: <span class=\"ruby-comment cmt\"># Start a transaction</span>\n\
292: <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">begin</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">TXN_COMMIT</span>, <span class=\"ruby-ivar\">@data_db</span> ) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">txn</span>,<span class=\"ruby-identifier\">datadb</span><span class=\"ruby-operator\">|</span>\n\
293: \n\
294: <span class=\"ruby-comment cmt\"># If this is a new synset, generate an offset for it</span>\n\
295: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span> <span class=\"ruby-operator\">==</span> <span class=\"ruby-value\">1</span>\n\
296: <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span> =\n\
297: (<span class=\"ruby-identifier\">datadb</span>[<span class=\"ruby-value str\">'offsetcount'</span>] = <span class=\"ruby-identifier\">datadb</span>[<span class=\"ruby-value str\">'offsetcount'</span>].<span class=\"ruby-identifier\">to_i</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value\">1</span>)\n\
298: <span class=\"ruby-keyword kw\">end</span>\n\
299: \n\
300: <span class=\"ruby-comment cmt\"># Write the data entry</span>\n\
301: <span class=\"ruby-identifier\">datadb</span>[ <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">key</span> ] = <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">serialize</span>\n\
302: \n\
303: <span class=\"ruby-comment cmt\"># Write the index entries</span>\n\
304: <span class=\"ruby-identifier\">txn</span>.<span class=\"ruby-identifier\">begin</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">TXN_COMMIT</span>, <span class=\"ruby-ivar\">@index_db</span> ) <span class=\"ruby-keyword kw\">do</span> <span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">txn</span>,<span class=\"ruby-identifier\">indexdb</span><span class=\"ruby-operator\">|</span>\n\
305: \n\
306: <span class=\"ruby-comment cmt\"># Make word/part-of-speech pairs from the words in the synset</span>\n\
307: <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">words</span>.<span class=\"ruby-identifier\">collect</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">word</span><span class=\"ruby-operator\">|</span> <span class=\"ruby-identifier\">word</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-value str\">"%"</span> <span class=\"ruby-operator\">+</span> <span class=\"ruby-identifier\">pos</span> }.<span class=\"ruby-identifier\">each</span> {<span class=\"ruby-operator\">|</span><span class=\"ruby-identifier\">word</span><span class=\"ruby-operator\">|</span>\n\
308: \n\
309: <span class=\"ruby-comment cmt\"># If the index already has this word, but not this</span>\n\
310: <span class=\"ruby-comment cmt\"># synset, add it</span>\n\
311: <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">indexdb</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">word</span> )\n\
312: <span class=\"ruby-identifier\">indexdb</span>[ <span class=\"ruby-identifier\">word</span> ] <span class=\"ruby-operator\"><<</span> <span class=\"ruby-constant\">SUB_DELIM</span> <span class=\"ruby-operator\"><<</span> <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span> <span class=\"ruby-keyword kw\">unless</span>\n\
313: <span class=\"ruby-identifier\">indexdb</span>[ <span class=\"ruby-identifier\">word</span> ].<span class=\"ruby-identifier\">include?</span>( <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span> )\n\
314: <span class=\"ruby-keyword kw\">else</span>\n\
315: <span class=\"ruby-identifier\">indexdb</span>[ <span class=\"ruby-identifier\">word</span> ] = <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span>\n\
316: <span class=\"ruby-keyword kw\">end</span>\n\
317: }\n\
318: <span class=\"ruby-keyword kw\">end</span> <span class=\"ruby-comment cmt\"># transaction on @index_db</span>\n\
319: <span class=\"ruby-keyword kw\">end</span> <span class=\"ruby-comment cmt\"># transaction on @dataDB</span>\n\
320: \n\
321: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">synset</span>.<span class=\"ruby-identifier\">offset</span>\n\
322: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Store the specified <tt>synset</tt> (a <a
href="Synset.html">WordNet::Synset</a> object) in the lexicon. Returns the
key of the stored synset.
</p>
params: ( synset )
category: Instance
type: Public
- methods:
- visibility: protected
aref: M000020
name: archlogs
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 398</span>\n\
398: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">archlogs</span>\n\
399: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-ivar\">@env</span>.<span class=\"ruby-identifier\">log_archive</span>( <span class=\"ruby-constant\">BDB</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">ARCH_ABS</span> )\n\
400: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Return a list of archival logfiles that can be removed safely.
(BerkeleyDB-specific).
</p>
params: ()
- visibility: protected
aref: M000018
name: make_pos
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 377</span>\n\
377: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">make_pos</span>( <span class=\"ruby-identifier\">original</span> )\n\
378: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">WordNet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">Noun</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-identifier\">original</span>.<span class=\"ruby-identifier\">nil?</span>\n\
379: <span class=\"ruby-identifier\">osym</span> = <span class=\"ruby-identifier\">original</span>.<span class=\"ruby-identifier\">to_s</span>.<span class=\"ruby-identifier\">intern</span>\n\
380: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-constant\">WordNet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">SYNTACTIC_CATEGORIES</span>[ <span class=\"ruby-identifier\">osym</span> ] <span class=\"ruby-keyword kw\">if</span>\n\
381: <span class=\"ruby-constant\">WordNet</span><span class=\"ruby-operator\">::</span><span class=\"ruby-constant\">SYNTACTIC_CATEGORIES</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">osym</span> )\n\
382: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-identifier\">original</span> <span class=\"ruby-keyword kw\">if</span> <span class=\"ruby-constant\">SYNTACTIC_SYMBOLS</span>.<span class=\"ruby-identifier\">key?</span>( <span class=\"ruby-identifier\">original</span> )\n\
383: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-keyword kw\">nil</span>\n\
384: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Normalize various ways of specifying a part of speech into the <a
href="../WordNet.html">WordNet</a> part of speech indicator from the
<tt>original</tt> representation, which may be the name (e.g., "noun");
<tt>nil</tt>, in which case it defaults to the indicator for a noun; or the
indicator character itself, in which case it is returned unmodified.
</p>
params: ( original )
- visibility: protected
aref: M000019
name: make_word_key
sourcecode: " <span class=\"ruby-comment cmt\"># File lib/wordnet/lexicon.rb, line 389</span>\n\
389: <span class=\"ruby-keyword kw\">def</span> <span class=\"ruby-identifier\">make_word_key</span>( <span class=\"ruby-identifier\">word</span>, <span class=\"ruby-identifier\">pos</span> )\n\
390: <span class=\"ruby-identifier\">pos</span> = <span class=\"ruby-keyword kw\">self</span>.<span class=\"ruby-identifier\">make_pos</span>( <span class=\"ruby-identifier\">pos</span> )\n\
391: <span class=\"ruby-identifier\">word</span> = <span class=\"ruby-identifier\">word</span>.<span class=\"ruby-identifier\">gsub</span>( <span class=\"ruby-regexp re\">/\\s+/</span>, <span class=\"ruby-value str\">'_'</span> )\n\
392: <span class=\"ruby-keyword kw\">return</span> <span class=\"ruby-node\">"#{word}%#{pos}"</span>\n\
393: <span class=\"ruby-keyword kw\">end</span>"
m_desc: |-
<p>
Make a lexicon key out of the given <tt>word</tt> and part of speech
(<tt>pos</tt>).
</p>
params: ( word, pos )
category: Instance
type: Protected
---
---
- name: SvnId
desc: |+
Subversion Id
value: "%q$Id: lexicon.rb 93 2008-07-12 00:56:49Z deveiant $"
- name: SvnRev
desc: |+
Subversion revision
value: "%q$Rev: 93 $"
- name: DEFAULT_DB_ENV
desc: |+
The path to the <a href="../WordNet.html">WordNet</a> BerkeleyDB Env. It
lives in the directory that this module is in.
value: File::join( Config::CONFIG['datadir'], "ruby-wordnet" )
- name: ENV_OPTIONS
desc: |+
Options for the creation of the Env object
value: "{ :set_timeout => 50, :set_lk_detect => 1, :set_verbose => false, :set_lk_max => 3000, }"
- name: ENV_FLAGS_RW
desc: |+
Flags for the creation of the Env object (read-write and read-only)
value: BDB::CREATE|BDB::INIT_TRANSACTION|BDB::RECOVER|BDB::INIT_MPOOL
- name: ENV_FLAGS_RO
value: BDB::INIT_MPOOL
Generated with the Darkfish Rdoc Generator.